Hey,
expired items are lazily reclaimed. This means when they're fetched (found
expired, then memory moved to free pool), or if they are sitting at the
bottom of the LRU when a new item is being stored.
They can hold up space in some cases. For example:
- store a 0 exp time item.
- store 10 1s exp time items.
- now, say we are out of memory.
- wait a few seconds.
- store an item: the 0 exp time item is at the bottom of the LRU. the
system looks at the tail item, finds it can't reclaim it, is out of
memory, and thus evicts it. Despite there being 10 expired items in the
middle of the slab class.
This isn't too common though. Your issue is much more likely related to
slab calcification.
On the chance it wasn't, it's another thing I imrpoved ages ago, with
1.4.18:
https://code.google.com/p/memcached/wiki/ReleaseNotes1418
The LRU crawler will periodically sweep through the LRU classes, pulling
expired items back into the free pool. This feature was improved over a
couple releases, and then again with .23 (stabilized in .24):
https://code.google.com/p/memcached/wiki/ReleaseNotes1423
... wherein the slab class is now split to protect against "scanning".
The recommended start lines noted in the .25 release enable all the new
features, and for many users could vastly improve their memory
efficiency.
With all of these new features, it's important to tune your TTL's
relatively well. The LRU maintainer thread can still improve hit ratios if
none of your items ever expire but page rebalancing and LRU reclaiming
only work if they're tuned well.