[152980] trunk/dports/devel/jemalloc

larryv at macports.org larryv at macports.org
Wed Sep 21 11:29:03 PDT 2016


Revision: 152980
          https://trac.macports.org/changeset/152980
Author:   larryv at macports.org
Date:     2016-09-21 11:29:02 -0700 (Wed, 21 Sep 2016)
Log Message:
-----------
jemalloc: Fix malloc zone registration on Sierra

Closes: #52238

Modified Paths:
--------------
    trunk/dports/devel/jemalloc/Portfile

Added Paths:
-----------
    trunk/dports/devel/jemalloc/files/
    trunk/dports/devel/jemalloc/files/0001-Avoid-getting-the-same-default-zone-twice-in-a-row.patch
    trunk/dports/devel/jemalloc/files/0002-Change-how-the-default-zone-is-found.patch

Modified: trunk/dports/devel/jemalloc/Portfile
===================================================================
--- trunk/dports/devel/jemalloc/Portfile	2016-09-21 18:25:32 UTC (rev 152979)
+++ trunk/dports/devel/jemalloc/Portfile	2016-09-21 18:29:02 UTC (rev 152980)
@@ -6,6 +6,7 @@
 name                jemalloc
 categories          devel
 version             4.2.1
+revision            1
 license             BSD
 platforms           darwin
 maintainers         gmail.com:yoanlin93 openmaintainer
@@ -24,6 +25,13 @@
 
 depends_build       port:libxslt
 
+# https://trac.macports.org/ticket/52238
+# https://github.com/jemalloc/jemalloc/commit/4abaee5
+# https://github.com/jemalloc/jemalloc/commit/19c9a3e
+patch.pre_args      -p1
+patchfiles          0001-Avoid-getting-the-same-default-zone-twice-in-a-row.patch \
+                    0002-Change-how-the-default-zone-is-found.patch
+
 configure.args-append --disable-debug --with-jemalloc-prefix=
 
 # provide a compatibility symlink with the older name

Added: trunk/dports/devel/jemalloc/files/0001-Avoid-getting-the-same-default-zone-twice-in-a-row.patch
===================================================================
--- trunk/dports/devel/jemalloc/files/0001-Avoid-getting-the-same-default-zone-twice-in-a-row.patch	                        (rev 0)
+++ trunk/dports/devel/jemalloc/files/0001-Avoid-getting-the-same-default-zone-twice-in-a-row.patch	2016-09-21 18:29:02 UTC (rev 152980)
@@ -0,0 +1,41 @@
+From 4abaee5d13a54c677cd132c481dbf7621f785fec Mon Sep 17 00:00:00 2001
+From: Mike Hommey <mh at glandium.org>
+Date: Fri, 8 Jul 2016 13:28:16 +0900
+Subject: [PATCH 1/2] Avoid getting the same default zone twice in a row.
+
+847ff22 added a call to malloc_default_zone() before the main loop in
+register_zone, effectively making malloc_default_zone() called twice
+without any different outcome expected in the returned result.
+
+It is also called once at the beginning, and a second time at the end
+of the loop block.
+
+Instead, call it only once per iteration.
+---
+ src/zone.c | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/src/zone.c b/src/zone.c
+index ca235da..9432f45 100644
+--- a/src/zone.c
++++ b/src/zone.c
+@@ -246,7 +246,6 @@ register_zone(void)
+ 	malloc_zone_register(&zone);
+ 
+ 	do {
+-		default_zone = malloc_default_zone();
+ 		/*
+ 		 * Unregister and reregister the default zone.  On OSX >= 10.6,
+ 		 * unregistering takes the last registered zone and places it
+@@ -272,5 +271,7 @@ register_zone(void)
+ 			malloc_zone_unregister(purgeable_zone);
+ 			malloc_zone_register(purgeable_zone);
+ 		}
+-	} while (malloc_default_zone() != &zone);
++
++		default_zone = malloc_default_zone();
++	} while (default_zone != &zone);
+ }
+-- 
+2.9.3
+

Added: trunk/dports/devel/jemalloc/files/0002-Change-how-the-default-zone-is-found.patch
===================================================================
--- trunk/dports/devel/jemalloc/files/0002-Change-how-the-default-zone-is-found.patch	                        (rev 0)
+++ trunk/dports/devel/jemalloc/files/0002-Change-how-the-default-zone-is-found.patch	2016-09-21 18:29:02 UTC (rev 152980)
@@ -0,0 +1,76 @@
+From 19c9a3e828ed46f1576521c264640e60bd0cb01f Mon Sep 17 00:00:00 2001
+From: Mike Hommey <mh at glandium.org>
+Date: Fri, 8 Jul 2016 13:35:35 +0900
+Subject: [PATCH 2/2] Change how the default zone is found
+
+On OSX 10.12, malloc_default_zone returns a special zone that is not
+present in the list of registered zones. That zone uses a "lite zone"
+if one is present (apparently enabled when malloc stack logging is
+enabled), or the first registered zone otherwise. In practice this
+means unless malloc stack logging is enabled, the first registered
+zone is the default.
+
+So get the list of zones to get the first one, instead of relying on
+malloc_default_zone.
+---
+ src/zone.c | 31 +++++++++++++++++++++++++++++--
+ 1 file changed, 29 insertions(+), 2 deletions(-)
+
+diff --git a/src/zone.c b/src/zone.c
+index 9432f45..9238161 100644
+--- a/src/zone.c
++++ b/src/zone.c
+@@ -168,6 +168,33 @@ zone_force_unlock(malloc_zone_t *zone)
+ 		jemalloc_postfork_parent();
+ }
+ 
++static malloc_zone_t *get_default_zone()
++{
++	malloc_zone_t **zones = NULL;
++	unsigned int num_zones = 0;
++
++	/*
++	 * On OSX 10.12, malloc_default_zone returns a special zone that is not
++	 * present in the list of registered zones. That zone uses a "lite zone"
++	 * if one is present (apparently enabled when malloc stack logging is
++	 * enabled), or the first registered zone otherwise. In practice this
++	 * means unless malloc stack logging is enabled, the first registered
++	 * zone is the default.
++	 * So get the list of zones to get the first one, instead of relying on
++	 * malloc_default_zone.
++	 */
++        if (KERN_SUCCESS != malloc_get_all_zones(0, NULL, (vm_address_t**) &zones,
++	                                         &num_zones)) {
++		/* Reset the value in case the failure happened after it was set. */
++		num_zones = 0;
++	}
++
++	if (num_zones)
++		return zones[0];
++
++	return malloc_default_zone();
++}
++
+ JEMALLOC_ATTR(constructor)
+ void
+ register_zone(void)
+@@ -177,7 +204,7 @@ register_zone(void)
+ 	 * If something else replaced the system default zone allocator, don't
+ 	 * register jemalloc's.
+ 	 */
+-	malloc_zone_t *default_zone = malloc_default_zone();
++	malloc_zone_t *default_zone = get_default_zone();
+ 	malloc_zone_t *purgeable_zone = NULL;
+ 	if (!default_zone->zone_name ||
+ 	    strcmp(default_zone->zone_name, "DefaultMallocZone") != 0) {
+@@ -272,6 +299,6 @@ register_zone(void)
+ 			malloc_zone_register(purgeable_zone);
+ 		}
+ 
+-		default_zone = malloc_default_zone();
++		default_zone = get_default_zone();
+ 	} while (default_zone != &zone);
+ }
+-- 
+2.9.3
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20160921/d0bd6022/attachment.html>


More information about the macports-changes mailing list