Difference between revisions of "Copy-on-write memory"

From CRIU
Jump to: navigation, search
(lotsa formatting fixes)
(fixed wikipedia links)
Line 1: Line 1:
 
== How it works now ==
 
== How it works now ==
 
=== Restoring ===
 
=== Restoring ===
We have different ideas how to restore {{Abbr|COW|Copy-on-write}}<ref>[[mediawiki:Copy-on-write]]</ref> memory. In a moment we even thought to use {{Abbr|KSM|Kernel Shared Memory}}<ref>[[mediawiki:Kernel_SamePage_Merging_(KSM)]]</ref> for that. As result we found a good way for restoring COW memory (I guess). All {{Abbr|VMA|Virtual Memory Area}}s are restored in the same way as they were created. Here are two questions:
+
We have different ideas how to restore {{Abbr|COW|Copy-on-write}}<ref>[[wikipedia:Copy-on-write]]</ref> memory. In a moment we even thought to use {{Abbr|KSM|Kernel Shared Memory}}<ref>[[wikipedia:Kernel SamePage Merging (KSM)]]</ref> for that. As result we found a good way for restoring COW memory (I guess). All {{Abbr|VMA|Virtual Memory Area}}s are restored in the same way as they were created. Here are two questions:
  
 
# Which VMAs should be inherited?
 
# Which VMAs should be inherited?

Revision as of 06:24, 31 October 2012

How it works now

Restoring

We have different ideas how to restore COW[1] memory. In a moment we even thought to use KSM[2] for that. As result we found a good way for restoring COW memory (I guess). All VMAs are restored in the same way as they were created. Here are two questions:

  1. Which VMAs should be inherited?
  2. How to avoid intersections with crtools VMAs?

The first question is not resolved completely. Now a VMA is inherited if a parent has a VMA with the same start and end addresses. This covers 99% of cases, but it doesn't work if a VMA was moved.

The second question is more interesting. Currently crtools reserves continuous space for all private VMAs, then restores all VMAs one by one in this space. Inherited VMAs are moved from a parent space. All VMAs are sorted by start addresses.

Cow.png

In “restorer” all crtools’ VMAs are unmapped and private VMAs are space apart. The complexity of this algorithm is linear. Now it looks simple, but I spent a few hours to find it.

“Complexity is easy; simplicity is difficult. -Georgy Shpagin”

“Everything should be made as simple as possible, but not more simpler. - Albert Einstein”

All VMAs and their contents are restored before forking children, so here is one more item. A parent can change some pages after forking a child, so such pages should be dropped from the child's VMA. For solving this problem bitmaps are used to mark touched pages and madvise() is used to remove extra pages.

One more case is not handled now. COW memory are not restored if a process is reparented to init.

References