[pypy-commit] stmgc c8-private-pages: Trying to fix what was basically just exceeding max_map_count. Now checking return values and showing an error message

Raemi noreply at buildbot.pypy.org
Tue Jan 13 17:04:26 CET 2015


Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch: c8-private-pages
Changeset: r1523:f15bc3c633a0
Date: 2015-01-13 15:50 +0100
http://bitbucket.org/pypy/stmgc/changeset/f15bc3c633a0/

Log:	Trying to fix what was basically just exceeding max_map_count. Now
	checking return values and showing an error message

diff --git a/c8/demo/demo_random2.c b/c8/demo/demo_random2.c
--- a/c8/demo/demo_random2.c
+++ b/c8/demo/demo_random2.c
@@ -10,10 +10,10 @@
 #include "stmgc.h"
 
 #define NUMTHREADS 3
-#define STEPS_PER_THREAD 500
-#define THREAD_STARTS 1000 // how many restarts of threads
+#define STEPS_PER_THREAD 50000
+#define THREAD_STARTS 100 // how many restarts of threads
 #define PREBUILT_ROOTS 3
-#define FORKS 3
+#define FORKS 0
 
 #define ACTIVE_ROOTS_SET_SIZE 100 // max num of roots created/alive in one transaction
 #define MAX_ROOTS_ON_SS 1000 // max on shadow stack
@@ -232,11 +232,13 @@
         break;
     case 3: // allocate fresh 'p'
         pushed = push_roots();
-        size_t sizes[4] = {sizeof(struct node_s),
-                           sizeof(struct node_s) + (get_rand(100000) & ~15),
-                           sizeof(struct node_s) + 4096,
-                           sizeof(struct node_s) + 4096*70};
-        size_t size = sizes[get_rand(4)];
+        size_t sizes[] = {
+            sizeof(struct node_s), sizeof(struct node_s)+16,
+            sizeof(struct node_s), sizeof(struct node_s)+16,
+            sizeof(struct node_s)+32, sizeof(struct node_s)+48,
+            sizeof(struct node_s)+32, sizeof(struct node_s)+48,
+            sizeof(struct node_s) + (get_rand(100000) & ~15)};
+        size_t size = sizes[get_rand(sizeof(sizes) / sizeof(size_t))];
         p = stm_allocate(size);
         ((nodeptr_t)p)->sig = SIGNATURE;
         ((nodeptr_t)p)->my_size = size;
@@ -352,7 +354,7 @@
     /* "interpreter main loop": this is one "application-frame" */
     while (td.steps_left-->0 && get_rand(10) != 0) {
         if (td.steps_left % 8 == 0)
-            fprintf(stdout, "#");
+            fprintf(stderr, "#");
 
         assert(p == NULL || ((nodeptr_t)p)->sig == SIGNATURE);
 
diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -299,6 +299,8 @@
         }
         last_cl = cl;
         /* HERE */
+
+        acquire_privatization_lock(STM_SEGMENT->segment_num);
         acquire_modification_lock_set(segments_to_lock);
 
 
@@ -330,6 +332,7 @@
                     struct stm_undo_s *end = cl->written + cl->written_count;
 
                     segment_really_copied_from |= (1UL << cl->segment_num);
+
                     import_objects(cl->segment_num, -1, undo, end);
 
                     /* here we can actually have our own modified version, so
@@ -364,6 +367,7 @@
 
         /* done with modifications */
         release_modification_lock_set(segments_to_lock);
+        release_privatization_lock(STM_SEGMENT->segment_num);
     }
 
     if (needs_abort) {
diff --git a/c8/stm/gcpage.c b/c8/stm/gcpage.c
--- a/c8/stm/gcpage.c
+++ b/c8/stm/gcpage.c
@@ -13,7 +13,7 @@
 {
 }
 
-static void setup_N_pages(char *pages_addr, uint64_t num)
+static void setup_N_pages(char *pages_addr, long num)
 {
     /* initialize to |N|P|N|N| */
     acquire_all_privatization_locks();
@@ -21,6 +21,7 @@
     uintptr_t p = (pages_addr - stm_object_pages) / 4096UL;
     dprintf(("setup_N_pages(%p, %lu): pagenum %lu\n", pages_addr, num, p));
     while (num-->0) {
+        /* XXX: page_range_mark_accessible() */
         page_mark_accessible(STM_SEGMENT->segment_num, p + num);
     }
 
@@ -52,8 +53,8 @@
     }
 
     dprintf(("allocate_outside_nursery_large(%lu): %p, page=%lu\n",
-             size, addr,
-             (uintptr_t)addr / 4096UL + END_NURSERY_PAGE));
+             size, (char*)(addr - stm_object_pages),
+             (uintptr_t)(addr - stm_object_pages) / 4096UL));
 
     spinlock_release(lock_growth_large);
     return (stm_char*)(addr - stm_object_pages);
diff --git a/c8/stm/gcpage.h b/c8/stm/gcpage.h
--- a/c8/stm/gcpage.h
+++ b/c8/stm/gcpage.h
@@ -7,5 +7,5 @@
 
 static void setup_gcpage(void);
 static void teardown_gcpage(void);
-static void setup_N_pages(char *pages_addr, uint64_t num);
+static void setup_N_pages(char *pages_addr, long num);
 static stm_char *allocate_outside_nursery_large(uint64_t size);
diff --git a/c8/stm/pages.c b/c8/stm/pages.c
--- a/c8/stm/pages.c
+++ b/c8/stm/pages.c
@@ -22,7 +22,11 @@
     assert(get_page_status_in(segnum, pagenum) == PAGE_NO_ACCESS);
     dprintf(("page_mark_accessible(%lu) in seg:%ld\n", pagenum, segnum));
 
-    mprotect(get_virtual_page(segnum, pagenum), 4096, PROT_READ | PROT_WRITE);
+    dprintf(("RW(seg%ld, page%lu)\n", segnum, pagenum));
+    if (mprotect(get_virtual_page(segnum, pagenum), 4096, PROT_READ | PROT_WRITE)) {
+        perror("mprotect");
+        stm_fatalerror("mprotect failed! Consider running 'sysctl vm.max_map_count=16777216'");
+    }
 
     /* set this flag *after* we un-protected it, because XXX later */
     set_page_status_in(segnum, pagenum, PAGE_ACCESSIBLE);
@@ -36,7 +40,11 @@
 
     set_page_status_in(segnum, pagenum, PAGE_NO_ACCESS);
 
+    dprintf(("NONE(seg%ld, page%lu)\n", segnum, pagenum));
     char *addr = get_virtual_page(segnum, pagenum);
-    madvise(get_virtual_page(segnum, pagenum), 4096, MADV_DONTNEED);
-    mprotect(addr, 4096, PROT_NONE);
+    madvise(addr, 4096, MADV_DONTNEED);
+    if (mprotect(addr, 4096, PROT_NONE)) {
+        perror("mprotect");
+        stm_fatalerror("mprotect failed! Consider running 'sysctl vm.max_map_count=16777216'");
+    }
 }
diff --git a/c8/stm/pages.h b/c8/stm/pages.h
--- a/c8/stm/pages.h
+++ b/c8/stm/pages.h
@@ -57,6 +57,9 @@
 
 static inline bool get_page_status_in(long segnum, uintptr_t pagenum)
 {
+    /* reading page status requires "read"-lock: */
+    assert(STM_PSEGMENT->privatization_lock);
+
     OPT_ASSERT(segnum < 8 * sizeof(struct page_shared_s));
     volatile struct page_shared_s *ps = (volatile struct page_shared_s *)
         &pages_status[pagenum - PAGE_FLAG_START];
@@ -67,6 +70,9 @@
 static inline void set_page_status_in(long segnum, uintptr_t pagenum,
                                       bool status)
 {
+    /* writing page status requires "write"-lock: */
+    assert(all_privatization_locks_acquired());
+
     OPT_ASSERT(segnum < 8 * sizeof(struct page_shared_s));
     volatile struct page_shared_s *ps = (volatile struct page_shared_s *)
         &pages_status[pagenum - PAGE_FLAG_START];
diff --git a/c8/stm/smallmalloc.c b/c8/stm/smallmalloc.c
--- a/c8/stm/smallmalloc.c
+++ b/c8/stm/smallmalloc.c
@@ -67,6 +67,10 @@
         /* if (!_stm_largemalloc_resize_arena(uninitialized_page_stop - base)) */
         /*     goto out_of_memory; */
 
+        /* lock acquiring not necessary because the affected pages don't
+           need privatization protection. (but there is an assert right
+           now to enforce that XXXXXX) */
+        acquire_all_privatization_locks();
 
         char *p = uninitialized_page_stop;
         long i;
@@ -79,6 +83,7 @@
             free_uniform_pages = (struct small_free_loc_s *)p;
             p += 4096;
         }
+        release_all_privatization_locks();
     }
 
     spinlock_release(gmfp_lock);
@@ -123,9 +128,16 @@
                                                    smallpage->nextpage)))
             goto retry;
 
+
+
+        /* lock acquiring not necessary because the affected pages don't
+           need privatization protection. (but there is an assert right
+           now to enforce that XXXXXX) */
+        acquire_all_privatization_locks();
         /* make page accessible in our segment too: */
         page_mark_accessible(STM_SEGMENT->segment_num,
                              ((char*)smallpage - stm_object_pages) / 4096UL);
+        release_all_privatization_locks();
 
         /* Succeeded: we have a page in 'smallpage', which is not
            initialized so far, apart from the 'nextpage' field read


More information about the pypy-commit mailing list