summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assoc.c28
-rw-r--r--assoc.h1
-rw-r--r--memcached.c4
-rw-r--r--trace.h4
4 files changed, 15 insertions, 22 deletions
diff --git a/assoc.c b/assoc.c
index 8cdf581..8e7a810 100644
--- a/assoc.c
+++ b/assoc.c
@@ -27,7 +27,6 @@
static pthread_cond_t maintenance_cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t maintenance_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t hash_items_counter_lock = PTHREAD_MUTEX_INITIALIZER;
typedef unsigned long int ub4; /* unsigned 4-byte quantities */
typedef unsigned char ub1; /* unsigned 1-byte quantities */
@@ -47,9 +46,6 @@ static item** primary_hashtable = 0;
*/
static item** old_hashtable = 0;
-/* Number of items in the hash table. */
-static unsigned int hash_items = 0;
-
/* Flag: Are we in the middle of expanding now? */
static bool expanding = false;
static bool started_expanding = false;
@@ -144,12 +140,15 @@ static void assoc_expand(void) {
}
}
-static void assoc_start_expand(void) {
+void assoc_start_expand(uint64_t curr_items) {
if (started_expanding)
return;
- started_expanding = true;
- pthread_cond_signal(&maintenance_cond);
+ if (curr_items > (hashsize(hashpower) * 3) / 2 &&
+ hashpower < HASHPOWER_MAX) {
+ started_expanding = true;
+ pthread_cond_signal(&maintenance_cond);
+ }
}
/* Note: this isn't an assoc_update. The key must not already exist to call this */
@@ -168,15 +167,7 @@ int assoc_insert(item *it, const uint32_t hv) {
primary_hashtable[hv & hashmask(hashpower)] = it;
}
- pthread_mutex_lock(&hash_items_counter_lock);
- hash_items++;
- if (! expanding && hash_items > (hashsize(hashpower) * 3) / 2 &&
- hashpower < HASHPOWER_MAX) {
- assoc_start_expand();
- }
- pthread_mutex_unlock(&hash_items_counter_lock);
-
- MEMCACHED_ASSOC_INSERT(ITEM_key(it), it->nkey, hash_items);
+ MEMCACHED_ASSOC_INSERT(ITEM_key(it), it->nkey);
return 1;
}
@@ -185,13 +176,10 @@ void assoc_delete(const char *key, const size_t nkey, const uint32_t hv) {
if (*before) {
item *nxt;
- pthread_mutex_lock(&hash_items_counter_lock);
- hash_items--;
- pthread_mutex_unlock(&hash_items_counter_lock);
/* The DTrace probe cannot be triggered as the last instruction
* due to possible tail-optimization by the compiler
*/
- MEMCACHED_ASSOC_DELETE(key, nkey, hash_items);
+ MEMCACHED_ASSOC_DELETE(key, nkey);
nxt = (*before)->h_next;
(*before)->h_next = 0; /* probably pointless, but whatever. */
*before = nxt;
diff --git a/assoc.h b/assoc.h
index dda39a0..fb2c922 100644
--- a/assoc.h
+++ b/assoc.h
@@ -6,5 +6,6 @@ void assoc_delete(const char *key, const size_t nkey, const uint32_t hv);
void do_assoc_move_next_bucket(void);
int start_assoc_maintenance_thread(void);
void stop_assoc_maintenance_thread(void);
+void assoc_start_expand(uint64_t curr_items);
extern unsigned int hashpower;
extern unsigned int item_lock_hashpower;
diff --git a/memcached.c b/memcached.c
index 595814c..0e60c40 100644
--- a/memcached.c
+++ b/memcached.c
@@ -6127,6 +6127,10 @@ static void clock_handler(const int fd, const short which, void *arg) {
#endif
}
+ // While we're here, check for hash table expansion.
+ // This function should be quick to avoid delaying the timer.
+ assoc_start_expand(stats_state.curr_items);
+
evtimer_set(&clockevent, clock_handler, 0);
event_base_set(main_base, &clockevent);
evtimer_add(&clockevent, &t);
diff --git a/trace.h b/trace.h
index dc792a0..94e585d 100644
--- a/trace.h
+++ b/trace.h
@@ -4,11 +4,11 @@
#ifdef ENABLE_DTRACE
#include "memcached_dtrace.h"
#else
-#define MEMCACHED_ASSOC_DELETE(arg0, arg1, arg2)
+#define MEMCACHED_ASSOC_DELETE(arg0, arg1)
#define MEMCACHED_ASSOC_DELETE_ENABLED() (0)
#define MEMCACHED_ASSOC_FIND(arg0, arg1, arg2)
#define MEMCACHED_ASSOC_FIND_ENABLED() (0)
-#define MEMCACHED_ASSOC_INSERT(arg0, arg1, arg2)
+#define MEMCACHED_ASSOC_INSERT(arg0, arg1)
#define MEMCACHED_ASSOC_INSERT_ENABLED() (0)
#define MEMCACHED_COMMAND_ADD(arg0, arg1, arg2, arg3, arg4)
#define MEMCACHED_COMMAND_ADD_ENABLED() (0)