This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct { | |
unsigned int size; /* sizes of items */ | |
unsigned int perslab; /* how many items per slab */ | |
void *slots; /* list of item ptrs */ | |
unsigned int sl_curr; /* total free items in list */ | |
unsigned int slabs; /* how many slabs were allocated for this class */ | |
void **slab_list; /* array of slab pointers */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void slabs_init(const size_t limit, const double factor, const bool prealloc, const uint32_t *slab_sizes) { | |
... | |
mem_limit = limit; // scr: here | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static size_t mem_limit = 0; | |
... | |
settings.maxbytes = 64 * 1024 * 1024; /* default is 64MB */ | |
... | |
case 'm': | |
settings.maxbytes = ((size_t)atoi(optarg)) * 1024 * 1024; | |
break; | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
bool preallocate = false; | |
... | |
case 'L' : | |
if (enable_large_pages() == 0) { | |
preallocate = true; | |
} else { | |
fprintf(stderr, "Cannot enable large pages on this system\n" | |
"(There is no Linux support as of this version)\n"); | |
return 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int grow_slab_list (const unsigned int id) { | |
slabclass_t *p = &slabclass[id]; | |
if (p->slabs == p->list_size) { | |
size_t new_size = (p->list_size != 0) ? p->list_size * 2 : 16; | |
void *new_list = realloc(p->slab_list, new_size * sizeof(void *)); | |
if (new_list == 0) return 0; | |
p->list_size = new_size; | |
p->slab_list = new_list; | |
} | |
return 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void split_slab_page_into_freelist(char *ptr, const unsigned int id) { | |
slabclass_t *p = &slabclass[id]; | |
int x; | |
for (x = 0; x < p->perslab; x++) { | |
do_slabs_free(ptr, 0, id); | |
ptr += p->size; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void do_slabs_free(void *ptr, const size_t size, unsigned int id) { | |
slabclass_t *p; | |
item *it; | |
... | |
p = &slabclass[id]; | |
it = (item *)ptr; | |
it->it_flags = ITEM_SLABBED; // scr: ---------------> 1) | |
it->slabs_clsid = 0; | |
it->prev = 0; // scr: ------------------------------> 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void slabs_init(const size_t limit, const double factor, const bool prealloc, const uint32_t *slab_sizes) { | |
... | |
if (prealloc) { | |
slabs_preallocate(power_largest); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void slabs_preallocate (const unsigned int maxslabs) { | |
int i; | |
unsigned int prealloc = 0; | |
/* pre-allocate a 1MB slab in every size class so people don't get | |
confused by non-intuitive "SERVER_ERROR out of memory" | |
messages. this is the most common question on the mailing | |
list. if you really don't want this, you can rebuild without | |
these three lines. */ |