[PATCH 3/5] Don't re-calculate the slab class id.
dormando
dormando at rydia.net
Sun Mar 2 22:37:01 UTC 2008
slabs_alloc() internally calls slabs_clsid(), so an eviction case would crawl the list of slab classes three times.
---
server/items.c | 4 ++--
server/memcached.h | 6 +++---
server/slabs.c | 3 +--
server/slabs.h | 2 +-
server/thread.c | 4 ++--
5 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/server/items.c b/server/items.c
index c53a350..fa6d215 100644
--- a/server/items.c
+++ b/server/items.c
@@ -88,7 +88,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
if (id == 0)
return 0;
- it = slabs_alloc(ntotal);
+ it = slabs_alloc(ntotal, id);
if (it == 0) {
int tries = 50;
item *search;
@@ -119,7 +119,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
break;
}
}
- it = slabs_alloc(ntotal);
+ it = slabs_alloc(ntotal, id);
if (it == 0) return NULL;
}
diff --git a/server/memcached.h b/server/memcached.h
index 7fe473a..6c70276 100644
--- a/server/memcached.h
+++ b/server/memcached.h
@@ -291,7 +291,7 @@ char *mt_item_stats_sizes(int *bytes);
void mt_item_unlink(item *it);
void mt_item_update(item *it);
void mt_run_deferred_deletes(void);
-void *mt_slabs_alloc(size_t size);
+void *mt_slabs_alloc(size_t size, unsigned int id);
void mt_slabs_free(void *ptr, size_t size);
int mt_slabs_reassign(unsigned char srcid, unsigned char dstid);
char *mt_slabs_stats(int *buflen);
@@ -320,7 +320,7 @@ int mt_store_item(item *item, int comm);
# define item_update(x) mt_item_update(x)
# define item_unlink(x) mt_item_unlink(x)
# define run_deferred_deletes() mt_run_deferred_deletes()
-# define slabs_alloc(x) mt_slabs_alloc(x)
+# define slabs_alloc(x,y) mt_slabs_alloc(x,y)
# define slabs_free(x,y) mt_slabs_free(x,y)
# define slabs_reassign(x,y) mt_slabs_reassign(x,y)
# define slabs_stats(x) mt_slabs_stats(x)
@@ -353,7 +353,7 @@ int mt_store_item(item *item, int comm);
# define item_unlink(x) do_item_unlink(x)
# define item_update(x) do_item_update(x)
# define run_deferred_deletes() do_run_deferred_deletes()
-# define slabs_alloc(x) do_slabs_alloc(x)
+# define slabs_alloc(x,y) do_slabs_alloc(x,y)
# define slabs_free(x,y) do_slabs_free(x,y)
# define slabs_reassign(x,y) do_slabs_reassign(x,y)
# define slabs_stats(x) do_slabs_stats(x)
diff --git a/server/slabs.c b/server/slabs.c
index dcd3774..b61ef84 100644
--- a/server/slabs.c
+++ b/server/slabs.c
@@ -218,10 +218,9 @@ static int do_slabs_newslab(const unsigned int id) {
}
/*@null@*/
-void *do_slabs_alloc(const size_t size) {
+void *do_slabs_alloc(const size_t size, unsigned int id) {
slabclass_t *p;
- unsigned int id = slabs_clsid(size);
if (id < POWER_SMALLEST || id > power_largest)
return NULL;
diff --git a/server/slabs.h b/server/slabs.h
index 55ac62f..2d62234 100644
--- a/server/slabs.h
+++ b/server/slabs.h
@@ -17,7 +17,7 @@ void slabs_init(const size_t limit, const double factor, const bool prealloc);
unsigned int slabs_clsid(const size_t size);
/** Allocate object of given length. 0 on error */ /*@null@*/
-void *do_slabs_alloc(const size_t size);
+void *do_slabs_alloc(const size_t size, unsigned int id);
/** Free previously allocated object */
void do_slabs_free(void *ptr, size_t size);
diff --git a/server/thread.c b/server/thread.c
index ea06eeb..90fb266 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -571,11 +571,11 @@ void mt_assoc_move_next_bucket() {
/******************************* SLAB ALLOCATOR ******************************/
-void *mt_slabs_alloc(size_t size) {
+void *mt_slabs_alloc(size_t size, unsigned int id) {
void *ret;
pthread_mutex_lock(&slabs_lock);
- ret = do_slabs_alloc(size);
+ ret = do_slabs_alloc(size, id);
pthread_mutex_unlock(&slabs_lock);
return ret;
}
--
1.5.4.2
More information about the memcached
mailing list