? .deps ? Makefile ? Makefile.in ? aclocal.m4 ? autom4te.cache ? config.h ? config.h.in ? config.log ? config.status ? configure ? memcached ? memcached-prealloc-slabs.txt ? stamp-h ? stamp-h.in ? doc/Makefile ? doc/Makefile.in Index: ChangeLog =================================================================== RCS file: /home/cvspub/wcmtools/memcached/ChangeLog,v retrieving revision 1.38 diff -u -r1.38 ChangeLog --- ChangeLog 10 Aug 2005 06:01:24 -0000 1.38 +++ ChangeLog 2 Jan 2006 03:42:46 -0000 @@ -1,3 +1,10 @@ +2006-01-01 + * Brad Fitzpatrick : allocate 1 slab per class + on start-up, to avoid confusing users with out-of-memory errors + later. this is 18 MB of allocation on start, unless max memory + allowed with -m is lower, in which case only the smaller slab + classes are allocated. + 2005-08-09 * Elizabeth Mattijsen : needed a way to flush all memcached backend servers, but not at exactly the same time (to Index: memcached.h =================================================================== RCS file: /home/cvspub/wcmtools/memcached/memcached.h,v retrieving revision 1.21 diff -u -r1.21 memcached.h --- memcached.h 24 Feb 2004 23:42:02 -0000 1.21 +++ memcached.h 2 Jan 2006 03:42:46 -0000 @@ -150,6 +150,14 @@ /* Init the subsystem. The argument is the limit on no. of bytes to allocate, 0 if no limit */ void slabs_init(unsigned int limit); +/* 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. */ +void slabs_preallocate (unsigned int maxslabs); + /* Given object size, return id to use when allocating/freeing memory for object */ /* 0 means error: can't store such a large object */ unsigned int slabs_clsid(unsigned int size); Index: slabs.c =================================================================== RCS file: /home/cvspub/wcmtools/memcached/slabs.c,v retrieving revision 1.15 diff -u -r1.15 slabs.c --- slabs.c 5 Sep 2003 22:37:36 -0000 1.15 +++ slabs.c 2 Jan 2006 03:42:46 -0000 @@ -83,6 +83,26 @@ slabclass[i].list_size = 0; slabclass[i].killing = 0; } + + slabs_preallocate(limit / POWER_BLOCK); +} + +void slabs_preallocate (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. */ + + for(i=POWER_SMALLEST; i<=POWER_LARGEST; i++) { + if (++prealloc > maxslabs) + return; + slabs_newslab(i); + } + } static int grow_slab_list (unsigned int id) {