[ccan] [PATCH] rszshm: New module
Rusty Russell
rusty at rustcorp.com.au
Wed Jan 20 10:50:35 AEDT 2016
Dan Good <dan at dancancode.com> writes:
> rszshm - resizable pointer-safe shared memory
>
> Signed-off-by: Dan Good <dan at dancancode.com>
Nice! This is very similar to what antithread does, but pulled out
into a module of its own.
> On Linux boxes it can be seen that the used addresses clump
> + * at either end of the address range. rszshm tries to mmap in the middle
> + * of the address range, and checks if the requested address matches the
> + * returned address. If not, additional addresses are tried. Once mapped,
> + * the address is recorded to a header in the file. Another process reads the
> + * header and requests the saved address from mmap. If the returned address
> + * matches, work proceeds. While the defaults provide a propitious search,
> + * all the search parameters may be specified.
In antithread, I used the following heuristic:
/* We add 16MB to size. This compensates for address randomization. */
#define PADDING (16 * 1024 * 1024)
p->pool = mmap(NULL, size+PADDING, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
0);
if (p->pool == MAP_FAILED)
goto fail_free;
/* Then we remap into the middle of it. */
munmap(p->pool, size+PADDING);
p->pool = mmap((char *)p->pool + PADDING/2, size, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);
if (p->pool == MAP_FAILED)
goto fail_free;
The 16MB probably needs to be much larger for 64-bit machines, though
(and I didn't support resize nor renegotiation, as that's an issue if
you want to be able to create new antithreads dynamically...)
Cheers,
Rusty.
More information about the ccan
mailing list