[pypy-commit] stmgc c5: Use MADV_DONTNEED to clear the read marker pages after 255 transactions.

arigo noreply at buildbot.pypy.org
Wed Dec 18 17:33:25 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: c5
Changeset: r558:d3ce94726f63
Date: 2013-12-18 17:32 +0100
http://bitbucket.org/pypy/stmgc/changeset/d3ce94726f63/

Log:	Use MADV_DONTNEED to clear the read marker pages after 255
	transactions.

diff --git a/c5/core.c b/c5/core.c
--- a/c5/core.c
+++ b/c5/core.c
@@ -36,6 +36,12 @@
    writes to it now happen to go to the new mm page instead of the old
    one.
 
+   This is basically what happens automatically with fork() for regular
+   memory; the difference is that at commit time, we try to publish the
+   modified pages back for everybody to see.  This involves possibly
+   merging changes done by other processes to other objects from the
+   same page.
+
    The local pages are usually referenced by pointers, but may also be
    expressed as an index, called the "local index" of the page.
 */
@@ -134,6 +140,11 @@
             (unsigned char)(uintptr_t)stm_local.current_read_markers);
 }
 
+static struct read_marker_s *get_current_read_marker(struct object_s *object)
+{
+    return stm_local.current_read_markers + (((uintptr_t)object) >> 4);
+}
+
 void _stm_write_slowpath(struct object_s *);
 
 void stm_write(struct object_s *object)
@@ -282,6 +293,26 @@
     stm_local.current_read_markers += num;
 }
 
+static void clear_all_read_markers(void)
+{
+    /* set the largest possible read marker number, to find the last
+       possible read_marker to clear */
+    stm_set_read_marker_number(0xff);
+
+    uint64_t page_index = stm_shared_descriptor->index_page_never_used;
+    char *o = ((char *)stm_shared_descriptor) + page_index * 4096;
+    char *m = (char *)get_current_read_marker((struct object_s *)o);
+    size_t length = m - (char *)stm_local.read_markers;
+    length = (length + 4095) & ~4095;
+
+    int r = madvise(stm_local.read_markers, length, MADV_DONTNEED);
+    if (r != 0) {
+        perror("madvise() failure");
+        abort();
+    }
+    stm_set_read_marker_number(1);
+}
+
 void stm_setup(void)
 {
     if (sizeof(char *) != 8) {
@@ -491,8 +522,12 @@
     }
     stm_local.writes_by_this_transaction = NULL;
 
-    assert(stm_get_read_marker_number() < 0xff);
-    stm_local.current_read_markers++;
+    if (stm_get_read_marker_number() < 0xff) {
+        stm_local.current_read_markers++;
+    }
+    else {
+        clear_all_read_markers();
+    }
     return !conflict;
 }
 


More information about the pypy-commit mailing list