Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

If we're preallocating memory, prealloc slab pages

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...
commit c979d213251bc48459a7135f95cf2a5c710e4dae 1 parent 55ef5d3
@dormando dormando authored
Showing with 10 additions and 15 deletions.
  1. +2 −1  memcached.c
  2. +0 −1  memcached.h
  3. +8 −13 slabs.c
View
3  memcached.c
@@ -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;
View
1  memcached.h
@@ -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
View
21 slabs.c
@@ -61,7 +61,6 @@ 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.
@@ -69,7 +68,6 @@ static void do_slabs_free(void *ptr, const size_t size, unsigned int id);
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
@@ -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;
@@ -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];
Please sign in to comment.
Something went wrong with that request. Please try again.