Skip to content

Commit

Permalink
Don't re-calculate the slab class id for slabs_free() either.
Browse files Browse the repository at this point in the history
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 8d3ac82
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion items.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions slabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion slabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 8d3ac82

Please sign in to comment.