Permalink
Browse files

Don't re-calculate the slab class id for slabs_free() either.

This + previous patch slightly reduce user CPU time, especially during heavy evictions.


git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@739 b0b603af-a30f-0410-a34e-baf09ae79d0b
  • Loading branch information...
dormando committed Mar 3, 2008
1 parent 01fa48f commit 8d3ac82666d9a2bdc5beb158140d358c4b5d0ce8
Showing with 10 additions and 9 deletions.
  1. +3 −1 items.c
  2. +3 −3 memcached.h
  3. +1 −2 slabs.c
  4. +1 −1 slabs.h
  5. +2 −2 thread.c
View
@@ -144,16 +144,18 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
void item_free(item *it) {
size_t ntotal = ITEM_ntotal(it);
+ unsigned int clsid;
assert((it->it_flags & ITEM_LINKED) == 0);
assert(it != heads[it->slabs_clsid]);
assert(it != tails[it->slabs_clsid]);
assert(it->refcount == 0);
/* so slab size changer can tell later if item is already free or not */
+ clsid = it->slabs_clsid;
it->slabs_clsid = 0;
it->it_flags |= ITEM_SLABBED;
DEBUG_REFCNT(it, 'F');
- slabs_free(it, ntotal);
+ slabs_free(it, ntotal, clsid);
}
/**
View
@@ -292,7 +292,7 @@ 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, unsigned int id);
-void mt_slabs_free(void *ptr, size_t size);
+void mt_slabs_free(void *ptr, size_t size, unsigned int id);
int mt_slabs_reassign(unsigned char srcid, unsigned char dstid);
char *mt_slabs_stats(int *buflen);
void mt_stats_lock(void);
@@ -321,7 +321,7 @@ int mt_store_item(item *item, int comm);
# define item_unlink(x) mt_item_unlink(x)
# define run_deferred_deletes() mt_run_deferred_deletes()
# define slabs_alloc(x,y) mt_slabs_alloc(x,y)
-# define slabs_free(x,y) mt_slabs_free(x,y)
+# define slabs_free(x,y,z) mt_slabs_free(x,y,z)
# define slabs_reassign(x,y) mt_slabs_reassign(x,y)
# define slabs_stats(x) mt_slabs_stats(x)
# define store_item(x,y) mt_store_item(x,y)
@@ -354,7 +354,7 @@ int mt_store_item(item *item, int comm);
# define item_update(x) do_item_update(x)
# define run_deferred_deletes() do_run_deferred_deletes()
# define slabs_alloc(x,y) do_slabs_alloc(x,y)
-# define slabs_free(x,y) do_slabs_free(x,y)
+# define slabs_free(x,y,z) do_slabs_free(x,y,z)
# define slabs_reassign(x,y) do_slabs_reassign(x,y)
# define slabs_stats(x) do_slabs_stats(x)
# define store_item(x,y) do_store_item(x,y)
View
@@ -257,8 +257,7 @@ void *do_slabs_alloc(const size_t size, unsigned int id) {
return NULL; /* shouldn't ever get here */
}
-void do_slabs_free(void *ptr, const size_t size) {
- unsigned char id = slabs_clsid(size);
+void do_slabs_free(void *ptr, const size_t size, unsigned int id) {
slabclass_t *p;
assert(((item *)ptr)->slabs_clsid == 0);
View
@@ -20,7 +20,7 @@ unsigned int slabs_clsid(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);
+void do_slabs_free(void *ptr, size_t size, unsigned int id);
/** Fill buffer with stats */ /*@null@*/
char* do_slabs_stats(int *buflen);
View
@@ -580,9 +580,9 @@ void *mt_slabs_alloc(size_t size, unsigned int id) {
return ret;
}
-void mt_slabs_free(void *ptr, size_t size) {
+void mt_slabs_free(void *ptr, size_t size, unsigned int id) {
pthread_mutex_lock(&slabs_lock);
- do_slabs_free(ptr, size);
+ do_slabs_free(ptr, size, id);
pthread_mutex_unlock(&slabs_lock);
}

0 comments on commit 8d3ac82

Please sign in to comment.