Hey all, We use memcached in a big way here, so I started digging into the memcached codebase to poke around and see how things work. One question I had, is why free items are stored in an array of pointers instead of using the linked list items inherent in the items themselves.
When items are alloc'd, the next and prev pointers are cleared. When they are free'd, only the ->slabs_clsid is cleared as an "indicator" before passing it to slabs_free. slabs_free then stores it in p- >slots, an array of pointers to free items. Why aren't these instead using the ->next pointers of the items to create a singly linked list. This would save on the need for dynamic memory allocation in the p- >slots array. The only downside I can see is that computing slab stats (used_chunks and free_chunks) suddenly becomes an expensive operation. Is the stats computation efficiency the sole reason for this use of a p-slots array, or am I missing something? I understand the value of these useful memcache stats, and can appreciate making this tradeoff, I'm more curious if these stats were the *sole* reason for using an array, or if there's something more subtle (or obvious) that I'm missing. Thanks! Mike
