* COW userspace memory mapping question
@ 2011-03-08 21:38 Mordae
2011-03-10 19:13 ` Christoph Lameter
0 siblings, 1 reply; 7+ messages in thread
From: Mordae @ 2011-03-08 21:38 UTC (permalink / raw)
To: linux-mm
Hi,
first let me apologize if I've picked a wrong address.
Question: Is it possible to create a copy-on-write copy
of a MAP_PRIVATE|MAP_ANONYMOUS memory mapping
in the user space? Effectively a snapshot of
memory region.
I understand that clone() optionally does this
on much larger scale, but that's not really it.
Best regards,
Jan Dvorak
--
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>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: COW userspace memory mapping question
2011-03-08 21:38 COW userspace memory mapping question Mordae
@ 2011-03-10 19:13 ` Christoph Lameter
2011-03-10 21:00 ` Mordae
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Lameter @ 2011-03-10 19:13 UTC (permalink / raw)
To: Mordae; +Cc: linux-mm
On Tue, 8 Mar 2011, Mordae wrote:
> first let me apologize if I've picked a wrong address.
Its probably more an issue of us understanding what you want.
> Question: Is it possible to create a copy-on-write copy
> of a MAP_PRIVATE|MAP_ANONYMOUS memory mapping
> in the user space? Effectively a snapshot of
> memory region.
fork() and clone() can do this.
> I understand that clone() optionally does this
> on much larger scale, but that's not really it.
Ok let say you have a memory range in the address space from which you
want to take a snapshot. How is that snapshot data visible? To another
process? Via a file?
--
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>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: COW userspace memory mapping question
2011-03-10 19:13 ` Christoph Lameter
@ 2011-03-10 21:00 ` Mordae
2011-03-10 21:33 ` Christoph Lameter
0 siblings, 1 reply; 7+ messages in thread
From: Mordae @ 2011-03-10 21:00 UTC (permalink / raw)
To: Christoph Lameter; +Cc: linux-mm
On Thu, 10 Mar 2011 13:13:02 -0600 (CST), Christoph Lameter <cl@linux.com>
wrote:
> Its probably more an issue of us understanding what you want.
Okay. I've posted the message from within the CET. It was
approximately 1 am and I am not a native speaker. So, once again
sorry and thanks a lot for your help. :-)
Now to the question.
> Ok let say you have a memory range in the address space from which you
> want to take a snapshot. How is that snapshot data visible? To another
> process? Via a file?
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.
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?
Best regards,
Jan Dvorak
--
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>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: COW userspace memory mapping question
2011-03-10 21:00 ` Mordae
@ 2011-03-10 21:33 ` Christoph Lameter
2011-03-10 22:11 ` Mordae
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Lameter @ 2011-03-10 21:33 UTC (permalink / raw)
To: Mordae; +Cc: linux-mm
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>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: COW userspace memory mapping question
2011-03-10 21:33 ` Christoph Lameter
@ 2011-03-10 22:11 ` Mordae
2011-03-11 15:15 ` Christoph Lameter
0 siblings, 1 reply; 7+ messages in thread
From: Mordae @ 2011-03-10 22:11 UTC (permalink / raw)
To: Christoph Lameter; +Cc: linux-mm
On Thu, 10 Mar 2011 15:33:31 -0600 (CST), Christoph Lameter <cl@linux.com>
wrote:
> 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.
I see, that seems reasonable. But what if I was picky and want to snapshot
that piece of memory continuously? Let's say once in several minutes, then
let some thread to do stuffs to the original using consistent information
from the snapshot.
--
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>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: COW userspace memory mapping question
2011-03-10 22:11 ` Mordae
@ 2011-03-11 15:15 ` Christoph Lameter
2011-03-11 16:33 ` Jan Dvorak
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Lameter @ 2011-03-11 15:15 UTC (permalink / raw)
To: Mordae; +Cc: linux-mm
On Thu, 10 Mar 2011, Mordae wrote:
> On Thu, 10 Mar 2011 15:33:31 -0600 (CST), Christoph Lameter <cl@linux.com>
> wrote:
> > 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.
>
> I see, that seems reasonable. But what if I was picky and want to snapshot
> that piece of memory continuously? Let's say once in several minutes, then
> let some thread to do stuffs to the original using consistent information
> from the snapshot.
Keep the RW mapping around and tear down and repeat the MAP_PRIVATE mmaps
areas as needed? Updates would have to be done to the RW mapping.
--
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>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-03-11 16:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-08 21:38 COW userspace memory mapping question Mordae
2011-03-10 19:13 ` Christoph Lameter
2011-03-10 21:00 ` Mordae
2011-03-10 21:33 ` Christoph Lameter
2011-03-10 22:11 ` Mordae
2011-03-11 15:15 ` Christoph Lameter
2011-03-11 16:33 ` Jan Dvorak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).