summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2012-07-29 15:41:30 -0700
committerdormando <dormando@rydia.net>2012-07-29 15:59:40 -0700
commitc979d213251bc48459a7135f95cf2a5c710e4dae (patch)
tree9f3226ea96f2c24499c6df4fc191b764a83f5d2e
parent55ef5d374d1c6eaa1344cfd2576f9ab62306c1c2 (diff)
downloadmemcached-c979d213251bc48459a7135f95cf2a5c710e4dae.tar.gz
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.
-rw-r--r--memcached.c3
-rw-r--r--memcached.h1
-rw-r--r--slabs.c21
3 files changed, 10 insertions, 15 deletions
diff --git a/memcached.c b/memcached.c
index fb32a87..6c18254 100644
--- a/memcached.c
+++ b/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;
diff --git a/memcached.h b/memcached.h
index 17bfd71..7774e0e 100644
--- a/memcached.h
+++ b/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
diff --git a/slabs.c b/slabs.c
index 2de2153..d8b3eac 100644
--- a/slabs.c
+++ b/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];