MEDIUM: pool: Following up on previous pool trimming update.

Apple libmalloc has its own notion of memory arenas as malloc_zone with
rich API having various callbacks for various allocations strategies but
here we just use the defaults.
In trim_all_pools,  we advise to purge each zone as much as possible, called "greedy" mode.
diff --git a/include/haproxy/compat.h b/include/haproxy/compat.h
index 25b15a1..f8afe1b 100644
--- a/include/haproxy/compat.h
+++ b/include/haproxy/compat.h
@@ -274,9 +274,10 @@
 #endif
 
 /* macOS has a call similar to malloc_usable_size */
-#if defined(USE_MEMORY_PROFILING) && defined(__APPLE__)
+#if defined(__APPLE__)
 #include <malloc/malloc.h>
 #define malloc_usable_size malloc_size
+#define HA_HAVE_MALLOC_ZONE
 #endif
 
 /* Max number of file descriptors we send in one sendmsg(). Linux seems to be
diff --git a/src/pool.c b/src/pool.c
index 4d1d7d2..984c890 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -63,6 +63,21 @@
 #if defined(HA_HAVE_MALLOC_TRIM)
 		if (using_default_allocator)
 			malloc_trim(0);
+#elif defined(HA_HAVE_MALLOC_ZONE)
+		if (using_default_allocator) {
+			vm_address_t *zones;
+			unsigned int i, nzones;
+
+			if (malloc_get_all_zones(0, NULL, &zones, &nzones) == KERN_SUCCESS) {
+				for (i = 0; i < nzones; i ++) {
+					malloc_zone_t *zone = (malloc_zone_t *)zones[i];
+
+					/* we cannot purge anonymous zones */
+					if (zone->zone_name)
+						malloc_zone_pressure_relief(zone, 0);
+				}
+			}
+		}
 #endif
 	}
 }
@@ -111,6 +126,8 @@
 		free(DISGUISE(ptr));
 
 		using_default_allocator = !!memcmp(&mi1, &mi2, sizeof(mi1));
+#elif defined(HA_HAVE_MALLOC_ZONE)
+		using_default_allocator = (malloc_default_zone() != NULL);
 #endif
 	}
 }