Source code, lru_lock vs former cache_lock

Skip to first unread message

Slawomir Pryczek

Feb 27, 2023, 2:49:45 PM2/27/23
to memcached
Hi, I was reading about LRU lock a bit and have a question regarding item_cachedump

unsigned int id = slabs_clsid;
id |= COLD_LRU;

1. Why in this code we're binary adding COLD_LRU, while for example in lru_crawler's code we're just using slab class IDs. This way other threads are able to access locked resources, is that correct?

uint32_t hv = hash(ITEM_key(it), it->nkey);
void *hold_lock = NULL;
if ((hold_lock = item_trylock(hv)) == NULL) {
if (refcount_incr(it) == 2) {

Is it still correct way to lock an item so it can be safely read?

3. for the item_cachedump I found this comment

/* This is walking the line of violating lock order, but I think it's safe.
 * If the LRU lock is held, an item in the LRU cannot be wiped and freed.
 * The data could possibly be overwritten, but this is only accessing the
 * headers.
 * It may not be the best idea to leave it like this, but for now it's safe.

Why it may violate lock order when we have only single lock acquired in this function? IS there some doc about correct (updated) lock order, the one in sources seems outdated...



Feb 28, 2023, 12:11:22 AM2/28/23
to memcached

That old "item_cachedump" command is deprecated. The locking is fine; it's
actually only looking at the COLD_LRU instead of walking all of them like
the lru_crawler.

I'd rather remove the command entirely than do any further work on it; it
has a hard limit on how many keys it can dump, it locks up the whole
worker thread while it fills the buffer, etc. The lru_crawler is superior
in all ways.
> --
> ---
> You received this message because you are subscribed to the Google Groups "memcached" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> To view this discussion on the web visit
Reply all
Reply to author
0 new messages