mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-14 17:37:46 +00:00
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:
parent
bb3e80e181
commit
b1e190a885
@ -274,9 +274,10 @@ typedef struct { } empty_t;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* macOS has a call similar to malloc_usable_size */
|
/* macOS has a call similar to malloc_usable_size */
|
||||||
#if defined(USE_MEMORY_PROFILING) && defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <malloc/malloc.h>
|
#include <malloc/malloc.h>
|
||||||
#define malloc_usable_size malloc_size
|
#define malloc_usable_size malloc_size
|
||||||
|
#define HA_HAVE_MALLOC_ZONE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Max number of file descriptors we send in one sendmsg(). Linux seems to be
|
/* Max number of file descriptors we send in one sendmsg(). Linux seems to be
|
||||||
|
17
src/pool.c
17
src/pool.c
@ -63,6 +63,21 @@ static void trim_all_pools(void)
|
|||||||
#if defined(HA_HAVE_MALLOC_TRIM)
|
#if defined(HA_HAVE_MALLOC_TRIM)
|
||||||
if (using_default_allocator)
|
if (using_default_allocator)
|
||||||
malloc_trim(0);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,6 +126,8 @@ static void detect_allocator(void)
|
|||||||
free(DISGUISE(ptr));
|
free(DISGUISE(ptr));
|
||||||
|
|
||||||
using_default_allocator = !!memcmp(&mi1, &mi2, sizeof(mi1));
|
using_default_allocator = !!memcmp(&mi1, &mi2, sizeof(mi1));
|
||||||
|
#elif defined(HA_HAVE_MALLOC_ZONE)
|
||||||
|
using_default_allocator = (malloc_default_zone() != NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user