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.
This commit is contained in:
David CARLIER 2021-11-26 20:44:44 +00:00 committed by Willy Tarreau
parent bb3e80e181
commit b1e190a885
2 changed files with 19 additions and 1 deletions

View File

@ -274,9 +274,10 @@ typedef struct { } empty_t;
#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

View File

@ -63,6 +63,21 @@ static void trim_all_pools(void)
#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 @@ static void detect_allocator(void)
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
}
}