Skip to content

Instantly share code, notes, and snippets.

@holmeshe
Created September 20, 2018 08:53
Show Gist options
  • Save holmeshe/56ba62cf1732833fdba1c0de8fb1b50c to your computer and use it in GitHub Desktop.
Save holmeshe/56ba62cf1732833fdba1c0de8fb1b50c to your computer and use it in GitHub Desktop.
static int do_slabs_newslab(const unsigned int id) {
slabclass_t *p = &slabclass[id]; // scr: ----------------------------> 1)
slabclass_t *g = &slabclass[SLAB_GLOBAL_PAGE_POOL]; // scr: ---------> *)
int len = settings.slab_reassign ? settings.item_size_max // scr: ---> 2)
: p->size * p->perslab;
char *ptr;
if ((mem_limit && mem_malloced + len > mem_limit && p->slabs > 0 // -> 3)
&& g->slabs == 0)) {
mem_limit_reached = true;
MEMCACHED_SLABS_SLABCLASS_ALLOCATE_FAILED(id);
return 0;
}
if ((grow_slab_list(id) == 0) || // scr: ----------------------------> 4)
(((ptr = get_page_from_global_pool()) == NULL) && // scr: -------> *)
((ptr = memory_allocate((size_t)len)) == 0))) { // scr: ---------> 5)
MEMCACHED_SLABS_SLABCLASS_ALLOCATE_FAILED(id);
return 0;
}
memset(ptr, 0, (size_t)len);
split_slab_page_into_freelist(ptr, id); // scr: ---------------------> 6)
p->slab_list[p->slabs++] = ptr; // scr: -----------------------------> 7)
MEMCACHED_SLABS_SLABCLASS_ALLOCATE(id);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment