Why isn’t memcached using its available memory

configurationmemcachedmemory

Our memcached.conf has the following directive:

-m 7168

And the server has 8GB of RAM. However, despite heavy use, memory usage never goes above 2GB:

# free
             total       used       free     shared    buffers     cached
Mem:       8178532    2067308    6111224          0     109092     434916
-/+ buffers/cache:    1523300    6655232
Swap:            0          0          0

What are we missing?

Best Answer

Normally, memcached uses only as much memory as it needs, even if you give a maximum limit. It's not like the Linux system buffers that by design can expand to fill all the available memory in order to improve system performance.

You can telnet to your memcache and issue the commands

stats
stats slabs
stats malloc

which should give you an idea about how many objects of which sizes are in your memcache and how much memory they occupy.

If memcached does not have enough memory to store all your objects, it will evict older objects, which will increment the "evictions" counter returned by slabs. If "evictions" is at 0, then your memcache has enough memory.

You can find many other useful commands and solutions at "the memcached cheat sheet" at http://lzone.de/cheat-sheet/memcached