Regarding mmap synchronization.

mindentropy mindentropy at
Sun Sep 18 15:12:10 EDT 2011

On Monday 19 Sep 2011 12:19:29 AM Dave Hylands wrote:

> The way I normally deal with this is to use 2 indicies, a get index
> and a put index. One of the indicies if only ever written by kernel
> space, and the other is only ever written by user space.
That is the setup I have now.

> You make the circular buffer be a power of 2 in size, and you
> determine the number of items in the queue by subtracting the get
> index from the put index. 
I am worried about the subtraction. Is it safe to subtract when the put index 
is in the process of incrementing by the kernel?
My queue size is always a power of two and avoid the modulus operation by '&' 
with (2^n)-1.

> If the items in the circular buffer are in cached memory, then I
> normally try to make each item be an exact multiple of the cache line
> size. I find using uncached memory is generally better for this type
> of thing (the accesses are slower, but may be faster after accounting
> for the cache management).
I am having a chunked buffer. So the queue items are memory chunks ranging from 
PAGE_SIZE*n to PAGE_SIZE*1. So I have a index to the chunk, index to item 
inside the chunk for read and write. For the user its invisible and sees it as 
one big chunk of memory with a read and a write index.

More information about the Kernelnewbies mailing list