Why memcached takes much more memory than specified in its configuration

Muhammad Tahir asked:

I have set Item Size to 128M and Maximum Memory to 1024M in my memcached configuration.
But when I run this command:

ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5

I get

71.7  0.0 3072592 4537 /usr/bin/memcached -vv -m 1024 -p 11211 -u memcache -l -I 128M

Which states that memcached is taking 3GB of memory. Now I understand when we set Item Size larger than 1MB, memory consumption of memcached increases. But 3GB when you have set Maximum memory to 1GB seems to be quite much.

Is is always so or I am doing something wrong? Is there anyway to decrease this memory consumption?

Note: Although keys that I am currently storing in the memcached or a little over 1MB but size of these keys keeps increasing continuously, so to be safe in the future I have set the Item size to maximum possible!

My answer:

vsize does not mean how much memory the process is taking up. That number is given by rss.

Resident set size, or rss, indicates how much memory the process is actually using. While, total VM size, here vsize, indicates how much total address space is in use. The program could theoretically use that much RAM eventually, but most of the address space is used by things like memory allocated but not used, parts of libraries which haven’t been loaded from disk because they weren’t needed, etc.

In practice you can ignore vsize unless you’re on a 32-bit system, on which the maximum possible address space for any process is 4GiB (even if the process uses a far smaller amount of RAM).

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.