Skip to content

Commit

Permalink
If we're preallocating memory, prealloc slab pages
Browse files Browse the repository at this point in the history
I'll probably get in trouble for removing DONT_PREALLOC_SLABS

... however tons of people like using the -L option, which does nothing under
linux. It should soon do *something* under linux, and when it does they'll
report the same errors of not being able to store things into certain slab
classes.

So just give them a useful error and bail instead.
  • Loading branch information
dormando committed Jul 29, 2012
1 parent 55ef5d3 commit c979d21
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
3 changes: 2 additions & 1 deletion memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -4892,7 +4892,8 @@ int main (int argc, char **argv) {
if (enable_large_pages() == 0) {
preallocate = true;
} else {
fprintf(stderr, "Cannot enable large pages on this system\n");
fprintf(stderr, "Cannot enable large pages on this system\n"
"(There is no Linux support as of this version)\n");
return 1;
}
break;
Expand Down
1 change: 0 additions & 1 deletion memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
#define POWER_SMALLEST 1
#define POWER_LARGEST 200
#define CHUNK_ALIGN_BYTES 8
#define DONT_PREALLOC_SLABS
#define MAX_NUMBER_OF_SLAB_CLASSES (POWER_LARGEST + 1)

/** How long an object can reasonably be assumed to be locked before
Expand Down
21 changes: 8 additions & 13 deletions slabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ static int do_slabs_newslab(const unsigned int id);
static void *memory_allocate(size_t size);
static void do_slabs_free(void *ptr, const size_t size, unsigned int id);

#ifndef DONT_PREALLOC_SLABS
/* Preallocate as many slab pages as possible (called from slabs_init)
on start-up, so users don't get confused out-of-memory errors when
they do have free (in-slab) space, but no space to make new slabs.
if maxslabs is 18 (POWER_LARGEST - POWER_SMALLEST + 1), then all
slab types can be made. if max memory is less than 18 MB, only the
smaller ones will be made. */
static void slabs_preallocate (const unsigned int maxslabs);
#endif

/*
* Figures out which slab class (chunk size) is required to store an item of
Expand Down Expand Up @@ -145,18 +143,11 @@ void slabs_init(const size_t limit, const double factor, const bool prealloc) {

}

#ifndef DONT_PREALLOC_SLABS
{
char *pre_alloc = getenv("T_MEMD_SLABS_ALLOC");

if (pre_alloc == NULL || atoi(pre_alloc) != 0) {
slabs_preallocate(power_largest);
}
if (prealloc) {
slabs_preallocate(power_largest);
}
#endif
}

#ifndef DONT_PREALLOC_SLABS
static void slabs_preallocate (const unsigned int maxslabs) {
int i;
unsigned int prealloc = 0;
Expand All @@ -170,11 +161,15 @@ static void slabs_preallocate (const unsigned int maxslabs) {
for (i = POWER_SMALLEST; i <= POWER_LARGEST; i++) {
if (++prealloc > maxslabs)
return;
do_slabs_newslab(i);
if (do_slabs_newslab(i) == 0) {
fprintf(stderr, "Error while preallocating slab memory!\n"
"If using -L or other prealloc options, max memory must be "
"at least %d megabytes.\n", power_largest);
exit(1);
}
}

}
#endif

static int grow_slab_list (const unsigned int id) {
slabclass_t *p = &slabclass[id];
Expand Down

0 comments on commit c979d21

Please sign in to comment.