[pypy-commit] stmgc cl-collector-thread: move some more code, separate accounting for cl-entries, and adapt tests

Raemi noreply at buildbot.pypy.org
Mon Mar 9 15:56:28 CET 2015


Author: Remi Meier <remi.meier at gmail.com>
Branch: cl-collector-thread
Changeset: r1708:3387438f8cc4
Date: 2015-03-09 13:57 +0100
http://bitbucket.org/pypy/stmgc/changeset/3387438f8cc4/

Log:	move some more code, separate accounting for cl-entries, and adapt
	tests

diff --git a/c8/stm/commitlog.c b/c8/stm/commitlog.c
--- a/c8/stm/commitlog.c
+++ b/c8/stm/commitlog.c
@@ -2,12 +2,44 @@
 # error "must be compiled via stmgc.c"
 #endif
 
+uint64_t cle_allocated;
+
+static void setup_commitlog(void)
+{
+    cle_allocated = 0;
+    commit_log_root.next = NULL;
+    commit_log_root.segment_num = -1;
+    commit_log_root.rev_num = 0;
+    commit_log_root.written_count = 0;
+}
+
+static void teardown_commitlog(void)
+{
+    cle_allocated = 0;
+    commit_log_root.next = NULL; /* xxx:free them */
+    commit_log_root.segment_num = -1;
+}
+
+static void add_cle_allocated(ssize_t add_or_remove)
+{
+    __sync_add_and_fetch(&cle_allocated, add_or_remove);
+}
+
+uint64_t _stm_cle_allocated(void) {
+    return cle_allocated;
+}
+
+static char *malloc_bk(size_t bk_size)
+{
+    add_cle_allocated(bk_size);
+    return malloc(bk_size);
+}
 
 static void free_bk(struct stm_undo_s *undo)
 {
     free(undo->backup);
     assert(undo->backup = (char*)-88);
-    increment_total_allocated(-SLICE_SIZE(undo->slice));
+    add_cle_allocated(-SLICE_SIZE(undo->slice));
 }
 
 static struct stm_commit_log_entry_s *malloc_cle(long entries)
@@ -15,7 +47,7 @@
     size_t byte_len = sizeof(struct stm_commit_log_entry_s) +
         entries * sizeof(struct stm_undo_s);
     struct stm_commit_log_entry_s *result = malloc(byte_len);
-    increment_total_allocated(byte_len);
+    add_cle_allocated(byte_len);
     return result;
 }
 
@@ -23,7 +55,7 @@
 {
     size_t byte_len = sizeof(struct stm_commit_log_entry_s) +
         e->written_count * sizeof(struct stm_undo_s);
-    increment_total_allocated(-byte_len);
+    add_cle_allocated(-byte_len);
     free(e);
 }
 
diff --git a/c8/stm/commitlog.h b/c8/stm/commitlog.h
--- a/c8/stm/commitlog.h
+++ b/c8/stm/commitlog.h
@@ -1,3 +1,7 @@
+
+
+/* when to trigger a CLE collection */
+#define CLE_COLLECT_BOUND (1*1024*1024) /* 1 MiB */
 
 
 /* Commit Log things */
@@ -33,8 +37,13 @@
 static struct stm_commit_log_entry_s commit_log_root;
 
 
+static char *malloc_bk(size_t bk_size);
 static void free_bk(struct stm_undo_s *undo);
 static struct stm_commit_log_entry_s *malloc_cle(long entries);
 static void free_cle(struct stm_commit_log_entry_s *e);
 
 void _dbg_print_commit_log();
+
+#ifdef STM_TESTS
+uint64_t _stm_cle_allocated(void);
+#endif
diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -231,7 +231,6 @@
     /* now return and retry */
 }
 
-/* ############# commit log ############# */
 
 
 
@@ -573,8 +572,7 @@
         in_page_offset = (in_page_offset + slice_sz) % 4096UL; /* mostly 0 */
 
         /* make backup slice: */
-        char *bk_slice = malloc(slice_sz);
-        increment_total_allocated(slice_sz);
+        char *bk_slice = malloc_bk(slice_sz);
         memcpy(bk_slice, realobj + slice_off, slice_sz);
 
         acquire_modification_lock(STM_SEGMENT->segment_num);
diff --git a/c8/stm/setup.c b/c8/stm/setup.c
--- a/c8/stm/setup.c
+++ b/c8/stm/setup.c
@@ -78,10 +78,6 @@
     setup_protection_settings();
     setup_signal_handler();
 
-    commit_log_root.next = NULL;
-    commit_log_root.segment_num = -1;
-    commit_log_root.rev_num = 0;
-    commit_log_root.written_count = 0;
 
     long i;
     /* including seg0 */
@@ -133,6 +129,7 @@
     setup_pages();
     setup_forksupport();
     setup_finalizer();
+    setup_commitlog();
 
     set_gs_register(get_segment_base(0));
 }
@@ -166,14 +163,13 @@
 
     munmap(stm_object_pages, TOTAL_MEMORY);
     stm_object_pages = NULL;
-    commit_log_root.next = NULL; /* xxx:free them */
-    commit_log_root.segment_num = -1;
 
     teardown_finalizer();
     teardown_sync();
     teardown_gcpage();
     teardown_smallmalloc();
     teardown_pages();
+    teardown_commitlog();
 }
 
 static void _shadowstack_trap_page(char *start, int prot)
diff --git a/c8/stmgc.h b/c8/stmgc.h
--- a/c8/stmgc.h
+++ b/c8/stmgc.h
@@ -138,6 +138,7 @@
 long _stm_count_old_objects_with_cards_set(void);
 object_t *_stm_enum_old_objects_with_cards_set(long index);
 uint64_t _stm_total_allocated(void);
+uint64_t _stm_cle_allocated(void);
 #endif
 
 /* ==================== HELPERS ==================== */
diff --git a/c8/test/support.py b/c8/test/support.py
--- a/c8/test/support.py
+++ b/c8/test/support.py
@@ -104,6 +104,7 @@
 /* void stm_collect(long level); */
 long _check_stm_collect(long level);
 uint64_t _stm_total_allocated(void);
+uint64_t _stm_cle_allocated(void);
 
 void _stm_set_nursery_free_count(uint64_t free_count);
 void _stm_largemalloc_init_arena(char *data_start, size_t data_size);
diff --git a/c8/test/test_gcpage.py b/c8/test/test_gcpage.py
--- a/c8/test/test_gcpage.py
+++ b/c8/test/test_gcpage.py
@@ -140,7 +140,8 @@
     def test_account_for_everything(self):
         self.start_transaction()
         self.commit_transaction()
-        assert lib._stm_total_allocated() == CLEO
+        assert lib._stm_total_allocated() == 0
+        assert lib._stm_cle_allocated() == CLEO
 
         self.start_transaction()
         o = stm_allocate(5008)
@@ -148,7 +149,8 @@
         self.commit_transaction()
         assert last_commit_log_entry_objs() == []
         # 2 CLEs, 1 old object
-        assert lib._stm_total_allocated() == 2*CLEO + (5008 + LMO)
+        assert lib._stm_total_allocated() == 5008 + LMO
+        assert lib._stm_cle_allocated() == 2*CLEO
 
         self.start_transaction()
         o = self.pop_root()
@@ -158,13 +160,16 @@
         assert last_commit_log_entry_objs() == [o]*2
         # 3 CLEs, 1 old object
         # also, 2 slices of bk_copy and thus 2 CLE entries
-        assert lib._stm_total_allocated() == 3*CLEO + (5008+LMO) + (5008 + CLEEO*2)
+        assert lib._stm_total_allocated() == 5008+LMO
+        assert lib._stm_cle_allocated() == 3*CLEO + (5008 + CLEEO*2)
 
         self.start_transaction()
-        assert lib._stm_total_allocated() == 3*CLEO + (5008+LMO) + (5008 + CLEEO*2)
+        assert lib._stm_total_allocated() == 5008+LMO
+        assert lib._stm_cle_allocated() == 3*CLEO + (5008 + CLEEO*2)
         stm_major_collect()
         # all CLE and CLE entries freed:
         assert lib._stm_total_allocated() == (5008+LMO)
+        assert lib._stm_cle_allocated() == 0
         self.commit_transaction()
 
 
@@ -202,12 +207,14 @@
         stm_set_char(x, 'a', 4999)
         self.push_root(x)
         self.commit_transaction()
-        assert lib._stm_total_allocated() == 5008 + LMO + CLEO
+        assert lib._stm_total_allocated() == 5008 + LMO
+        assert lib._stm_cle_allocated() == CLEO
 
         self.start_transaction()
         x = self.pop_root()
         self.push_root(x)
-        assert lib._stm_total_allocated() == 5008 + LMO + CLEO
+        assert lib._stm_total_allocated() == 5008 + LMO
+        assert lib._stm_cle_allocated() == CLEO
         stm_set_char(x, 'B')
         stm_set_char(x, 'b', 4999)
 


More information about the pypy-commit mailing list