linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Lameter <cl@linux.com>
To: Mordae <mordae@anilinux.org>
Cc: linux-mm@kvack.org
Subject: Re: COW userspace memory mapping question
Date: Thu, 10 Mar 2011 15:33:31 -0600 (CST)	[thread overview]
Message-ID: <alpine.DEB.2.00.1103101532230.2161@router.home> (raw)
In-Reply-To: <faf1c53253ae791c39448de707b96c15@anilinux.org>

On Thu, 10 Mar 2011, Mordae wrote:

> As I understand that, before a process forks, all of it's private memory
> pages are somehow magically marked. When a process with access to such
> page attempts to modify it, the page is duplicated and the copy replaces
> the shared page for this process. Then the actual modification is
> carried on.

Its not magic. The kernel simply marks the pages as readonly and does a
copy operation when the page is modified.

> What I am interested in is a hypothetical system call
>
>   void *mcopy(void *dst, void *src, size_t len, int flags);
>
> which would make src pages marked in the same way and mapped *also* to
> the dst. Afterwards, any modification to either mapping would not
> influence the other.
>
> Now, is there something like that?

If you have a file backed mmap (could be tmpfs) then it is possible.

First establish an RW mapping of the file.

Then -- when you want to take the snapshot -- unmap it and do two mmaps to
the old and new location. Make both readonly and MAP_PRIVATE. That will
cause the kernel to create readonly pages that are subject to COW.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-03-10 21:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-08 21:38 Mordae
2011-03-10 19:13 ` Christoph Lameter
2011-03-10 21:00   ` Mordae
2011-03-10 21:33     ` Christoph Lameter [this message]
2011-03-10 22:11       ` Mordae
2011-03-11 15:15         ` Christoph Lameter
2011-03-11 16:33           ` Jan Dvorak

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=alpine.DEB.2.00.1103101532230.2161@router.home \
    --to=cl@linux.com \
    --cc=linux-mm@kvack.org \
    --cc=mordae@anilinux.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