Skip to content

Commit

Permalink
Don't re-calculate the slab class id.
Browse files Browse the repository at this point in the history
slabs_alloc() internally calls slabs_clsid(), so an eviction case would crawl the list of slab classes three times.


git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@738 b0b603af-a30f-0410-a34e-baf09ae79d0b
  • Loading branch information
dormando committed Mar 3, 2008
1 parent e215d6c commit 01fa48f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions items.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions memcached.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions slabs.c
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion slabs.h
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions thread.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 01fa48f

Please sign in to comment.