PATCH - Add command line flag to not push items out of the cache
Jason Titus
jtitus@postini.com
Tue, 24 Feb 2004 13:56:36 -0800
This is a multi-part message in MIME format.
--------------060504020100020708060107
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Adds a '-M' flag to turn off tossing items from the cache. This makes
it so that memcached will error on a set when memory is full rather than
tossing an old item.
This is useful if you depend on items staying in the cache.
Jason
--------------060504020100020708060107
Content-Type: text/plain;
name="memcached-no-evict.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="memcached-no-evict.patch"
Common subdirectories: memcached-1.1.10/doc and memcached-1.1.10-no-evict/doc
diff -u memcached-1.1.10/items.c memcached-1.1.10-no-evict/items.c
--- memcached-1.1.10/items.c 2003-08-11 09:14:07.000000000 -0700
+++ memcached-1.1.10-no-evict/items.c 2004-02-24 13:44:41.000000000 -0800
@@ -55,6 +55,13 @@
it = slabs_alloc(ntotal);
if (it == 0) {
+
+ /* If requested to not push old items out of cache when memory runs out,
+ * we're out of luck at this point...
+ */
+
+ if (!settings.evict_to_free) return 0;
+
/*
* try to get one off the right LRU
* don't necessariuly unlink the tail because it may be locked: refcount>0
diff -u memcached-1.1.10/memcached.c memcached-1.1.10-no-evict/memcached.c
--- memcached-1.1.10/memcached.c 2003-12-04 09:50:57.000000000 -0800
+++ memcached-1.1.10-no-evict/memcached.c 2004-02-24 13:47:23.000000000 -0800
@@ -92,6 +92,7 @@
settings.maxconns = 1024; /* to limit connections-related memory to about 5MB */
settings.verbose = 0;
settings.oldest_live = 0;
+ settings.evict_to_free = 1; /* push old items out of cache when memory runs out */
}
conn **freeconns;
@@ -1177,6 +1178,7 @@
printf("-d run as a daemon\n");
printf("-u <username> assume identity of <username> (only when run as root)\n");
printf("-m <num> max memory to use for items in megabytes, default is 64 MB\n");
+ printf("-M return error on memory exhausted (rather than removing items)\n");
printf("-c <num> max simultaneous connections, default is 1024\n");
printf("-k lock down all paged memory\n");
printf("-v verbose (print errors/warnings while in event loop)\n");
@@ -1273,7 +1275,7 @@
settings_init();
/* process arguments */
- while ((c = getopt(argc, argv, "p:m:c:khivdl:u:")) != -1) {
+ while ((c = getopt(argc, argv, "p:m:Mc:khivdl:u:")) != -1) {
switch (c) {
case 'p':
settings.port = atoi(optarg);
@@ -1281,6 +1283,9 @@
case 'm':
settings.maxbytes = atoi(optarg)*1024*1024;
break;
+ case 'M':
+ settings.evict_to_free = 0;
+ break;
case 'c':
settings.maxconns = atoi(optarg);
break;
diff -u memcached-1.1.10/memcached.h memcached-1.1.10-no-evict/memcached.h
--- memcached-1.1.10/memcached.h 2003-12-04 09:50:57.000000000 -0800
+++ memcached-1.1.10-no-evict/memcached.h 2004-02-24 13:46:27.000000000 -0800
@@ -30,6 +30,7 @@
struct in_addr interface;
int verbose;
time_t oldest_live; /* ignore existing items older than this */
+ int evict_to_free;
};
extern struct stats stats;
Common subdirectories: memcached-1.1.10/scripts and memcached-1.1.10-no-evict/scripts
--------------060504020100020708060107--