malloc/mallopt question
Steve Ellcey
sellcey@marvell.com
Tue Jun 11 21:52:00 GMT 2019
I have a basic question about the glibc malloc and mallopt implementations.
I am looking at do_set_mmap_threshold in malloc/malloc.c and I see:
static __always_inline int
do_set_mmap_threshold (size_t value)
{
/* Forbid setting the threshold too high. */
if (value <= HEAP_MAX_SIZE / 2)
{
LIBC_PROBE (memory_mallopt_mmap_threshold, 3, value, mp_.mmap_threshold,
mp_.no_dyn_threshold);
mp_.mmap_threshold = value;
mp_.no_dyn_threshold = 1;
return 1;
}
return 0;
}
How does checking that 'value' is less than or equal to HEAP_MAX_SIZE/2
make sure it is not 'too high'? Also the mallopt man page says the
limits are 0 and 'DEFAULT_MMAP_THRESHOLD_MAX'. I don't see the upper
limit being enforced here (or anywhere else). What am I missing?
The hidden agenda here is to undestand if the mmap threshold can really
be set to something larger than DEFAULT_MMAP_THRESHOLD_MAX somehow to
get some large mallocs allocated with sbrk instead of mmap.
Steve Ellcey
sellcey@marvell.com
More information about the Libc-help
mailing list