Re: [PATCH] rszshm: New module
Rusty Russell <[email protected]> Wed, 20 Jan 2016 10:20:35 +1030
| Newsgroups | org.ozlabs.lists.ccan |
|---|---|
| Message-ID | <[email protected]> |
Dan Good <[email protected]> writes: > rszshm - resizable pointer-safe shared memory > > Signed-off-by: Dan Good <[email protected]> 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. _______________________________________________ ccan mailing list [email protected] https://lists.ozlabs.org/listinfo/ccan