Author: Armin Rigo <[email protected]>
Branch: c7-more-segments
Changeset: r1023:fa8bfb4eb410
Date: 2014-03-15 18:42 +0100
http://bitbucket.org/pypy/stmgc/changeset/fa8bfb4eb410/

Log:    Write a long comment about the new model I'm aiming for.

diff --git a/c7/stm/pages.h b/c7/stm/pages.h
--- a/c7/stm/pages.h
+++ b/c7/stm/pages.h
@@ -1,21 +1,32 @@
 
-enum /* flag_page_private */ {
-    /* The page is not in use.  Assume that each segment sees its own copy. */
-    FREE_PAGE=0,
+/* For every page, 'num_segments_sharing_page' stores a number that
+   counts the number of segments that share the page.  If 0, the page is
+   not used so far.
 
-    /* The page is shared by all segments.  Each segment sees the same
-       physical page (the one that is within the segment 0 mmap address). */
-    SHARED_PAGE,
+   When the page is first initialized, 'num_segments_sharing_page' is
+   set to NB_SEGMENTS.  When later a segment wants a private copy, it
+   looks first in its own 'private_page_mapping' tree, which maps shared
+   pages to private copies.  If not found, then it proceeds like this:
 
-    /* For only one range of pages at a time, around the call to
-       remap_file_pages() that un-shares the pages (SHARED -> PRIVATE). */
-    REMAPPING_PAGE,
+   If 'num_segments_sharing_page' is greater than 1, then it is
+   decremented and a private copy of the page is made.
 
-    /* Page is private for each segment. */
-    PRIVATE_PAGE,
-};
+   If 'num_segments_sharing_page' is equal to 1, then we know we are the
+   last segment that sees this "shared" copy, and so it is actually not
+   shared with anybody else --- i.e. it is private already.
 
-static uint8_t flag_page_private[NB_PAGES];
+   The shared copy of a page is stored in the mmap at the file offset
+   corresponding to the segment 0 offset (with all other segments
+   remapping to the segment 0 offset).  Private copies are made in the
+   offset from segment 1 (and if full, more segments afterwards),
+   picking file offsets that are simply the next free ones.  This is
+   probably good for long-term memory usage: a major collection looks
+   for pages that are no-longer-used private copies of some shared page,
+   and discard them, remapping the address to the shared page.  The
+   pages thus freed are recorded into a free list, and can be reused as
+   the private copies of the following (unrelated) pages.
+*/
+static uint8_t num_segments_sharing_page[NB_PAGES];
 
 static void _pages_privatize(uintptr_t pagenum, uintptr_t count);
 static void pages_initialize_shared(uintptr_t pagenum, uintptr_t count);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to