MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / sys_alloc

Function sys_alloc

dlmalloc/dlmalloc.c:3413–3713  ·  view source on GitHub ↗

Get memory from system using MORECORE or MMAP */

Source from the content-addressed store, hash-verified

3411
3412/* Get memory from system using MORECORE or MMAP */
3413static void* sys_alloc(mstate m, size_t nb, int zeroout) {
3414 char* tbase = CMFAIL;
3415 size_t tsize = 0;
3416 flag_t mmap_flag = 0;
3417
3418 init_mparams();
3419
3420 if (
3421 (zeroout && m->alloc0func) ||
3422 (!zeroout && m->allocfunc)
3423 ) { /* Obtain memory from user allocation routines first. */
3424 size_t rsize = granularity_align(nb + TOP_FOOT_SIZE + SIZE_T_ONE);
3425 if (rsize > nb) { /* Check for wrap around 0. */
3426 char *mp;
3427
3428 /*
3429 * CONSERVATIVE: Round up the requested size to the nearest multiple of
3430 * page size.
3431 * Example:
3432 * 8193B -> 12KB
3433 *
3434 * MODERATE: Round up the requested size to the nearest multiple of
3435 * page size, and then grow the value exponentially up to
3436 * 1MB. For requested size >= 1MB, fall back to
3437 * CONSERVATIVE. In addition, the exponential factor is
3438 * halved upon a successful sys_trim().
3439 * Example:
3440 * 8193B -> 12KB (1st time)
3441 * 8193B -> 12KB -> 24KB (2nd)
3442 * 8193B -> 12KB -> 48KB (3rd)
3443 * 8193B -> 12KB -> 96KB (4th)
3444 * ... successful sys_trim() ...
3445 * 8193B -> 12KB -> 48KB (5th)
3446 *
3447 * AGGRESSIVE: Round up the requested size to the nearest multiple
3448 * of page size, and then round it up to the nearest
3449 * power of 2, and furthermore grow the value exponentially
3450 * up to 1MB. For requested size >= 1MB, fall back to
3451 * CONSERVATIVE.
3452 * Example:
3453 * 8193B -> 12KB -> 16KB (1st time)
3454 * 8193B -> 12KB -> 32KB (2nd)
3455 * 8193B -> 12KB -> 64KB (3rd)
3456 * 8193B -> 12KB -> 128KB (4th)
3457 * ... successful sys_trim() ...
3458 * 8193B -> 12KB -> 128KB (5th)
3459 */
3460
3461 /* We may have more policies in the future so let's switch-case here. */
3462 switch (mparams.nice) {
3463 case NICE_AGGRESSIVE:
3464 if (rsize < (1ULL << (20 - m->nallocs))) {
3465 unsigned int power = 0;
3466 --rsize;
3467
3468 // unroll the following loop to reduce overhead
3469 // while (rsize >>= 1) ++power;
3470

Callers 3

dlmallocFunction · 0.85
mspace_mallocFunction · 0.85
mspace_callocFunction · 0.85

Calls 7

init_mparamsFunction · 0.85
mmap_allocFunction · 0.85
segment_holdingFunction · 0.85
init_binsFunction · 0.85
init_topFunction · 0.85
add_segmentFunction · 0.85
prepend_allocFunction · 0.85

Tested by

no test coverage detected