diff options
author | David Howells <dhowells@redhat.com> | 2019-11-15 16:30:32 +0300 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2019-10-31 18:12:34 +0300 |
commit | 8cefc107ca54c8b06438b7dc9cc08bc0a11d5b98 (patch) | |
tree | 3e01800bf202ddff7841a717ddc47d1e5771768a /mm/page_counter.c | |
parent | f94df9890e98f2090c6a8d70c795134863b70201 (diff) | |
download | linux-8cefc107ca54c8b06438b7dc9cc08bc0a11d5b98.tar.xz |
pipe: Use head and tail pointers for the ring, not cursor and length
Convert pipes to use head and tail pointers for the buffer ring rather than
pointer and length as the latter requires two atomic ops to update (or a
combined op) whereas the former only requires one.
(1) The head pointer is the point at which production occurs and points to
the slot in which the next buffer will be placed. This is equivalent
to pipe->curbuf + pipe->nrbufs.
The head pointer belongs to the write-side.
(2) The tail pointer is the point at which consumption occurs. It points
to the next slot to be consumed. This is equivalent to pipe->curbuf.
The tail pointer belongs to the read-side.
(3) head and tail are allowed to run to UINT_MAX and wrap naturally. They
are only masked off when the array is being accessed, e.g.:
pipe->bufs[head & mask]
This means that it is not necessary to have a dead slot in the ring as
head == tail isn't ambiguous.
(4) The ring is empty if "head == tail".
A helper, pipe_empty(), is provided for this.
(5) The occupancy of the ring is "head - tail".
A helper, pipe_occupancy(), is provided for this.
(6) The number of free slots in the ring is "pipe->ring_size - occupancy".
A helper, pipe_space_for_user() is provided to indicate how many slots
userspace may use.
(7) The ring is full if "head - tail >= pipe->ring_size".
A helper, pipe_full(), is provided for this.
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'mm/page_counter.c')
0 files changed, 0 insertions, 0 deletions