Re: COW userspace memory mapping question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx  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@xxxxxxxxx";> email@xxxxxxxxx </a>


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]