Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r75309:f176f55e3cb7
Date: 2015-01-12 18:22 +0100
http://bitbucket.org/pypy/pypy/changeset/f176f55e3cb7/

Log:    Issue #1925: tentative fix for the degenerating complexity

diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -773,11 +773,17 @@
             raise MemoryError
         #
         # If somebody calls this function a lot, we must eventually
-        # force a full collection.  XXX make this more incremental!
-        if (float(self.get_total_memory_used()) + raw_malloc_usage(totalsize) >
-                self.next_major_collection_threshold):
-            self.gc_step_until(STATE_SWEEPING)
-            self.gc_step_until(STATE_FINALIZING, raw_malloc_usage(totalsize))
+        # force a collection.  XXX make this more incremental!  For now
+        # the logic is to first do a minor GC only, and check if that
+        # was enough to free a bunch of large young objects.  If not,
+        # we do a complete major GC.
+        if self.get_total_memory_free() < raw_malloc_usage(totalsize):
+            self.minor_collection()
+            if self.get_total_memory_free() < (raw_malloc_usage(totalsize) +
+                                               self.nursery_size // 2):
+                self.gc_step_until(STATE_SWEEPING)
+                self.gc_step_until(STATE_FINALIZING,
+                                   raw_malloc_usage(totalsize))
         #
         # Check if the object would fit in the ArenaCollection.
         if raw_malloc_usage(totalsize) <= self.small_request_threshold:
@@ -1054,6 +1060,10 @@
         """
         return self.ac.total_memory_used + self.rawmalloced_total_size
 
+    def get_total_memory_free(self):
+        return (self.next_major_collection_threshold -
+                float(self.get_total_memory_used()))
+
     def card_marking_words_for_length(self, length):
         # --- Unoptimized version:
         #num_bits = ((length-1) >> self.card_page_shift) + 1
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to