From: Alex Bligh <alex@alex.org.uk>
To: linux-kernel@vger.kernel.org
Cc: Alex Bligh <alex@alex.org.uk>
Subject: Creating CoW mmap pages from userspace
Date: Sat, 23 Jul 2011 12:08:50 +0100 [thread overview]
Message-ID: <33B049CA913F8768850EDBBD@Ximines.local> (raw)
I have a threaded application which has a large file mmap'd into a
single large area L. L contains lots of page-aligned data structures
each of an integer number of pages in length.
L is volatile (altered by lots of threads). What I'd like to do
is take memory "snapshots" of bits of L by
1. taking a lock (preventing other threads writing to L)
2. generating an mmap CoW copy of a subset of L (just a few pages)
which would generate a new mmap'd area S (much smaller).
3. releasing a lock.
I'm not going to write to S, but I will read from it, and I need
it to contain what that bit of L contained at the time, and not
be affected by subsequent changes to L.
At kernel level, I can see how this would work - it's pretty much
what happens with fork().
I can't, however, see any way to do it from userspace. The only
near seems to be MAP_PRIVATE (i.e. open the file backing L
with another fd, or perhaps use the same fd, then create
a new memory map with MAP_PRIVATE set), but as far as I can tell
a) this would require me to msync() the relevant portion of L, and
there is no need for anything to hit the disk - memcpy() would
be faster, and
b) MAP_PRIVATE seems to protect L against changes to S, but does
not protect S against changes to L (which is what I need). The
manpage says "It is unspecified whether changes made to the file
after the mmap() call are visible in the mapped region"
Any ideas? Currently I am taking the easy way out and memcpy()'ing
the region, but I'd really rather avoid continuously memcpy()'ing
8MB chunks given that 99.9% of the time the relevant bit of L does
not change.
--
Alex Bligh
reply other threads:[~2011-07-23 11:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=33B049CA913F8768850EDBBD@Ximines.local \
--to=alex@alex.org.uk \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®