[Gc] Addition of GC_UNMAP_THRESHOLD environment var

Ivan Maidanski ivmai at mail.ru
Sun Nov 23 09:10:09 PST 2008


Hi!

This patch adds "GC_UNMAP_THRESHOLD" env var recognition (only for USE_MUNMAP case) to control unmapping "threshold" or to disable unmapping (by setting to 0) at an application start-up.

Bye.
-------------- next part --------------
diff -ru bdwgc/allchblk.c updated/bdwgc/allchblk.c
--- bdwgc/allchblk.c	2008-11-01 19:32:50.000000000 +0300
+++ updated/bdwgc/allchblk.c	2008-11-23 19:08:54.000000000 +0300
@@ -381,29 +381,31 @@
 
 #ifdef USE_MUNMAP
 
+#   ifndef MUNMAP_THRESHOLD
+#     define MUNMAP_THRESHOLD 6
+#   endif
+
+int GC_unmap_threshold = MUNMAP_THRESHOLD;
+
 /* Unmap blocks that haven't been recently touched.  This is the only way */
 /* way blocks are ever unmapped.					  */
 void GC_unmap_old(void)
 {
     struct hblk * h;
     hdr * hhdr;
-    word sz;
-    unsigned short last_rec, threshold;
     int i;
-#   ifndef MUNMAP_THRESHOLD
-#     define MUNMAP_THRESHOLD 6
-#   endif
+
+    if (GC_unmap_threshold == 0)
+      return; /* unmapping disabled */
     
     for (i = 0; i <= N_HBLK_FLS; ++i) {
       for (h = GC_hblkfreelist[i]; 0 != h; h = hhdr -> hb_next) {
         hhdr = HDR(h);
 	if (!IS_MAPPED(hhdr)) continue;
-	threshold = (unsigned short)(GC_gc_no - MUNMAP_THRESHOLD);
-	last_rec = hhdr -> hb_last_reclaimed;
-	if ((last_rec > GC_gc_no || last_rec < threshold)
-	    && threshold < GC_gc_no /* not recently wrapped */) {
-          sz = hhdr -> hb_sz;
-	  GC_unmap((ptr_t)h, sz);
+
+	if ((unsigned short)GC_gc_no - hhdr -> hb_last_reclaimed >
+		(unsigned short)GC_unmap_threshold) {
+	  GC_unmap((ptr_t)h, hhdr -> hb_sz);
 	  hhdr -> hb_flags |= WAS_UNMAPPED;
     	}
       }
diff -ru bdwgc/misc.c updated/bdwgc/misc.c
--- bdwgc/misc.c	2008-11-21 14:52:36.000000000 +0300
+++ updated/bdwgc/misc.c	2008-11-23 19:21:18.000000000 +0300
@@ -482,6 +482,10 @@
   void GC_thr_init(void);
 #endif
 
+#ifdef USE_MUNMAP
+  extern int GC_unmap_threshold;
+#endif
+
 void GC_init_inner(void)
 {
 #   if !defined(THREADS) && defined(GC_ASSERTIONS)
@@ -632,6 +636,21 @@
 	    GC_free_space_divisor = (GC_word)space_divisor;
 	}
     }
+#   ifdef USE_MUNMAP
+      {
+	char * string = GETENV("GC_UNMAP_THRESHOLD");
+	if (string != NULL) {
+	  if (*string == '0' && *(string + 1) == '\0') {
+	    /* "0" is used to disable unmapping. */
+	    GC_unmap_threshold = 0;
+	  } else {
+	    int unmap_threshold = atoi(string);
+	    if (unmap_threshold > 0)
+	      GC_unmap_threshold = unmap_threshold;
+	  }
+	}
+      }
+#   endif
     maybe_install_looping_handler();
     /* Adjust normal object descriptor for extra allocation.	*/
     if (ALIGNMENT > GC_DS_TAGS && EXTRA_BYTES != 0) {


More information about the Gc mailing list