Unexpected(?) high 'wasted' memory in memcached
Solution 1:
It has been a year since this question and I don't know if you found your answer but I'm going to say your perception of "wasted" is wrong.
Wasted memory is allocated in memory so it can not be used by another application, but it still is available for memcached.
To simplify the explanation, assume you have a memcache with 3MB of ram with 3 Slabs:
slab class 1: chunk size 10485 perslab 100
slab class 2: chunk size 104857 perslab 10
slab class 3: chunk size 1048576 perslab 1
Execute a single "set" with a 10k size. You'll see in your statistics(roughly) that you have:
0.03% used
66.6% free
33% wasted
This is because memcached allocated a single chunk from "slab class 1" and 99% of the memory for that slab is "wasted" and 1% is "used" This does not mean that slab and the memory allocated for that slab is gone.
Execute another single "set" with 10k size. This time you'll see:
0.06% used
66.6% free
32.7% wasted
so now you are using 2 out of 100 allocated chunks in slab 1, "wasted" statistics dropped, and used statistics increased.
There is nothing wrong for used% + wasted% being equal to 100%. That does not mean you have no more memory left, it simply means you allocated at least one chunk from each and every slab.
To see this issue a "set" with 100k size and another one with 1000k size
Now you'll see
36.6% used
0% free
63.3% wasted
Solution 2:
You probably have a very large number of very small objects. Typically, the smallest slab holds 104-byte entries. If you have a lot of entries that just map one integer to another, you can get waste as high as 85%.
You can find information on how to tune around this in the article Memcached for small objects.