From 058af0d85b2fb95319f9512fa4a99c2e8a412899 Mon Sep 17 00:00:00 2001 From: Keyur Date: Tue, 4 Sep 2012 21:54:14 +0000 Subject: Make tail leak expiry time configurable --- items.c | 2 +- memcached.c | 16 +++++++++++++++- memcached.h | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/items.c b/items.c index 85fd7e1..d70400c 100644 --- a/items.c +++ b/items.c @@ -125,7 +125,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, /* Old rare bug could cause a refcount leak. We haven't seen * it in years, but we leave this code in to prevent failures * just in case */ - if (search->time + TAIL_REPAIR_TIME < current_time) { + if (search->time + settings.tail_repair_time < current_time) { itemstats[id].tailrepairs++; search->refcount = 1; do_item_unlink_nolock(search, hv); diff --git a/memcached.c b/memcached.c index f3b9939..cc89a12 100644 --- a/memcached.c +++ b/memcached.c @@ -226,6 +226,7 @@ static void settings_init(void) { settings.slab_reassign = false; settings.slab_automove = 0; settings.shutdown_command = false; + settings.tail_repair_time = TAIL_REPAIR_TIME_DEFAULT; } /* @@ -2624,6 +2625,7 @@ static void process_stat_settings(ADD_STAT add_stats, void *c) { APPEND_STAT("hashpower_init", "%d", settings.hashpower_init); APPEND_STAT("slab_reassign", "%s", settings.slab_reassign ? "yes" : "no"); APPEND_STAT("slab_automove", "%d", settings.slab_automove); + APPEND_STAT("tail_repair_time", "%d", settings.tail_repair_time); } static void process_stat(conn *c, token_t *tokens, const size_t ntokens) { @@ -4523,6 +4525,9 @@ static void usage(void) { " table should be. Can be grown at runtime if not big enough.\n" " Set this based on \"STAT hash_power_level\" before a \n" " restart.\n" + " - tail_repair_time: Time in seconds that indicates how long to wait before\n" + " forcefully taking over the LRU tail item whose refcount has leaked.\n" + " The default is 3 hours.\n" ); return; } @@ -4757,13 +4762,15 @@ int main (int argc, char **argv) { MAXCONNS_FAST = 0, HASHPOWER_INIT, SLAB_REASSIGN, - SLAB_AUTOMOVE + SLAB_AUTOMOVE, + TAIL_REPAIR_TIME }; char *const subopts_tokens[] = { [MAXCONNS_FAST] = "maxconns_fast", [HASHPOWER_INIT] = "hashpower", [SLAB_REASSIGN] = "slab_reassign", [SLAB_AUTOMOVE] = "slab_automove", + [TAIL_REPAIR_TIME] = "tail_repair_time", NULL }; @@ -5033,6 +5040,13 @@ int main (int argc, char **argv) { return 1; } break; + case TAIL_REPAIR_TIME: + if (subopts_value == NULL) { + fprintf(stderr, "Missing numeric argument for tail_repair_time\n"); + return 1; + } + settings.tail_repair_time = atoi(subopts_value); + break; default: printf("Illegal suboption \"%s\"\n", subopts_value); return 1; diff --git a/memcached.h b/memcached.h index 91b6502..9308db9 100644 --- a/memcached.h +++ b/memcached.h @@ -76,7 +76,7 @@ /** How long an object can reasonably be assumed to be locked before harvesting it on a low memory condition. */ -#define TAIL_REPAIR_TIME (3 * 3600) +#define TAIL_REPAIR_TIME_DEFAULT (3 * 3600) /* warning: don't use these macros with a function, as it evals its arg twice */ #define ITEM_get_cas(i) (((i)->it_flags & ITEM_CAS) ? \ @@ -308,6 +308,7 @@ struct settings { int slab_automove; /* Whether or not to automatically move slabs */ int hashpower_init; /* Starting hash power level */ bool shutdown_command; /* allow shutdown command */ + int tail_repair_time; /* LRU tail refcount leak repair time */ }; extern struct stats stats; -- cgit v1.2.1