memcached not using allocated memory

Steven Grimm sgrimm at facebook.com
Fri Apr 20 07:28:54 UTC 2007


Marcus Bointon wrote:
> I'm not familiar with the internals, but I believe that memory chunks 
> are allocated in power-of-2 sized chunks. 16394 is 10 bytes over 
> 16384, which is 2^14, so your 16394 bytes will be stored in a 32768 
> size chunk (2^15), hence the wastage. It's just unfortunate that your 
> data is that size - it couldn't get much less efficient! That's my 
> theory anyway, could be completely wrong of course!

That's somewhat plausible, although modern versions use a power of 1.25 
to determine the chunk sizes.

It's easy to test that theory: there's a command-line option (-f) that 
lets you set the factor that's used. Try reducing it to 1.05 or some 
similarly small value and you should get a chunk size much closer to 
your data size.

Also, if that's what's going on, and all the objects in the cache are 
truly fixed-size, you can use another command line option to tune the 
smallest chunk size. It is perfectly fine to set that to the exact value 
needed to hold your fixed-size objects (remember that you need to leave 
room for the key as well, plus some space for the flags value; should be 
pretty easy to experimentally determine the optimal size.) Then there 
will be no wasted memory in your slabs at all.

-Steve



More information about the memcached mailing list