All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Dan Good <dan@dancancode.com>, ccan@lists.ozlabs.org
Subject: Re: [PATCH] rszshm: New module
Date: Wed, 20 Jan 2016 10:20:35 +1030	[thread overview]
Message-ID: <87ziw1xh6c.fsf@rustcorp.com.au> (raw)
In-Reply-To: <20160119060402.GA31418@ip-172-31-61-248.ec2.internal>

Dan Good <dan@dancancode.com> writes:
> rszshm - resizable pointer-safe shared memory
>
> Signed-off-by: Dan Good <dan@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.
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

  reply	other threads:[~2016-01-20  2:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-19  6:04 [PATCH] rszshm: New module Dan Good
2016-01-19 23:50 ` Rusty Russell [this message]
     [not found]   ` <CACNkOJM3ZLRAvQ5aO9bwfeAxAoWQNFqLh38EOzFF_qagq1bLvQ@mail.gmail.com>
2016-01-21  4:51     ` Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ziw1xh6c.fsf@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=ccan@lists.ozlabs.org \
    --cc=dan@dancancode.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.