Author: Armin Rigo <[email protected]>
Branch: c7-more-segments
Changeset: r1048:1edbabf86da8
Date: 2014-03-16 13:32 +0100
http://bitbucket.org/pypy/stmgc/changeset/1edbabf86da8/

Log:    Tweak: we need after all to have the mutex_pages_lock around
        remappings and around synchronize_object_now().

diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -112,8 +112,8 @@
     /* check that so far all copies of the object have the flag
        (a bit messy because it's possible that we read a page in
        the middle of privatization by another thread) */
+    long i;
 #ifndef NDEBUG
-    long i;
     long busy_loop = 1000000000;
     for (i = 0; i <= NB_SEGMENTS; i++) {
         while (!(((struct object_s *)REAL_ADDRESS(get_segment_base(i), obj))
@@ -263,7 +263,10 @@
     /* Copy around the version of 'obj' that lives in our own segment.
        It is first copied into the shared pages, and then into other
        segments' own private pages.
+
+       This must be called with the mutex_pages_lock!
     */
+    assert(_has_mutex_pages());
     assert(!_is_young(obj));
     assert(obj->stm_flags & GCFLAG_WRITE_BARRIER);
 
@@ -417,10 +420,12 @@
         major_collection_now_at_safe_point();
 
     /* synchronize overflow objects living in privatized pages */
+    mutex_pages_lock();
     push_overflow_objects_from_privatized_pages();
 
     /* synchronize modified old objects to other threads */
     push_modified_to_other_segments();
+    mutex_pages_unlock();
 
     /* update 'overflow_number' if needed */
     if (STM_PSEGMENT->overflow_number_has_been_used) {
diff --git a/c7/stm/misc.c b/c7/stm/misc.c
--- a/c7/stm/misc.c
+++ b/c7/stm/misc.c
@@ -81,4 +81,14 @@
     mutex_pages_unlock();
     return result;
 }
+
+void _stm_mutex_pages_lock(void)
+{
+    mutex_pages_lock();
+}
+
+void _stm_mutex_pages_unlock(void)
+{
+    mutex_pages_unlock();
+}
 #endif
diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c
--- a/c7/stm/nursery.c
+++ b/c7/stm/nursery.c
@@ -198,8 +198,11 @@
                WRITE_BARRIER flag and traced into it to fix its
                content); or add the object to 'large_overflow_objects'.
             */
-            if (STM_PSEGMENT->minor_collect_will_commit_now)
+            if (STM_PSEGMENT->minor_collect_will_commit_now) {
+                mutex_pages_lock();
                 synchronize_object_now(obj, false);
+                mutex_pages_unlock();
+            }
             else
                 LIST_APPEND(STM_PSEGMENT->large_overflow_objects, obj);
         }
diff --git a/c7/stm/pages.c b/c7/stm/pages.c
--- a/c7/stm/pages.c
+++ b/c7/stm/pages.c
@@ -39,7 +39,6 @@
     __sync_lock_release(&pages_ctl.mutex_pages);
 }
 
-__attribute__((unused))
 static bool _has_mutex_pages(void)
 {
     return pages_ctl.mutex_pages != 0;
@@ -47,6 +46,7 @@
 
 static uint64_t increment_total_allocated(ssize_t add_or_remove)
 {
+    assert(_has_mutex_pages());
     pages_ctl.total_allocated += add_or_remove;
 
     if (pages_ctl.total_allocated >= pages_ctl.total_allocated_bound)
@@ -119,6 +119,10 @@
     return;
 
  not_found:;
+    /* lock, to prevent concurrent threads from looking up my own
+       'private_page_mapping' in parallel */
+    mutex_pages_lock();
+
     /* look up the next free page */
     uintptr_t free_page_num = STM_PSEGMENT->private_free_page_num;
 
@@ -142,6 +146,8 @@
 
     /* update private_page_mapping */
     tree_insert(STM_PSEGMENT->private_page_mapping, pagenum, free_page_num);
+
+    mutex_pages_unlock();
 }
 
 #if 0
diff --git a/c7/stm/pages.h b/c7/stm/pages.h
--- a/c7/stm/pages.h
+++ b/c7/stm/pages.h
@@ -27,6 +27,7 @@
 
 static void mutex_pages_lock(void);
 static void mutex_pages_unlock(void);
+static bool _has_mutex_pages(void) __attribute__((unused));
 static uint64_t increment_total_allocated(ssize_t add_or_remove);
 static bool is_major_collection_requested(void);
 static void force_major_collection_request(void);
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -107,6 +107,8 @@
 object_t *_stm_enum_modified_old_objects(long index);
 object_t *_stm_enum_objects_pointing_to_nursery(long index);
 uint64_t _stm_total_allocated(void);
+void _stm_mutex_pages_lock(void);
+void _stm_mutex_pages_unlock(void);
 #endif
 
 #define _STM_GCFLAG_WRITE_BARRIER      0x01
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -88,6 +88,8 @@
 
 void stm_collect(long level);
 uint64_t _stm_total_allocated(void);
+void _stm_mutex_pages_lock(void);
+void _stm_mutex_pages_unlock(void);
 
 long stm_identityhash(object_t *obj);
 long stm_id(object_t *obj);
diff --git a/c7/test/test_largemalloc.py b/c7/test/test_largemalloc.py
--- a/c7/test/test_largemalloc.py
+++ b/c7/test/test_largemalloc.py
@@ -14,6 +14,7 @@
 
         lib.memset(self.rawmem, 0xcd, self.size)
         lib._stm_largemalloc_init_arena(self.rawmem, self.size)
+        lib._stm_mutex_pages_lock()   # for this file
 
     def test_simple(self):
         d1 = lib._stm_large_malloc(7000)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to