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

Function mmap_resize

dlmalloc/dlmalloc.c:3232–3264  ·  view source on GitHub ↗

Realloc using mmap */

Source from the content-addressed store, hash-verified

3230
3231/* Realloc using mmap */
3232static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb) {
3233 size_t oldsize = chunksize(oldp);
3234 if (is_small(nb)) /* Can't shrink mmap regions below small size */
3235 return 0;
3236 /* Keep old chunk if big enough but not too big */
3237 if (oldsize >= nb + SIZE_T_SIZE &&
3238 (oldsize - nb) <= (mparams.granularity << 1))
3239 return oldp;
3240 else {
3241 size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT;
3242 size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD;
3243 size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES +
3244 CHUNK_ALIGN_MASK);
3245 char* cp = (char*)CALL_MREMAP((char*)oldp - offset,
3246 oldmmsize, newmmsize, 1);
3247 if (cp != CMFAIL) {
3248 mchunkptr newp = (mchunkptr)(cp + offset);
3249 size_t psize = newmmsize - offset - MMAP_FOOT_PAD;
3250 newp->head = (psize|CINUSE_BIT);
3251 mark_inuse_foot(m, newp, psize);
3252 chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;
3253 chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0;
3254
3255 if (cp < m->least_addr)
3256 m->least_addr = cp;
3257 if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint)
3258 m->max_footprint = m->footprint;
3259 check_mmapped_chunk(m, newp);
3260 return newp;
3261 }
3262 }
3263 return 0;
3264}
3265
3266/* -------------------------- mspace management -------------------------- */
3267

Callers 1

internal_reallocFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected