hi,about memcached

Tomash Brechko tomash.brechko at gmail.com
Sat Jan 19 12:32:47 UTC 2008


On Sat, Jan 19, 2008 at 19:43:46 +0800, haibao liu wrote:
> so i have a question, if the refcount is larger than zero?what will
> happen?

If I understand it correctly, this is how it works: when item is not
being accessed its reference count is zero.  When some client accesses
an item its refcount is incremented at the beginning of the access (or
the new item is created with refcount == 1), and at the end of the
access refcount is decremented back.  Thus refcount > 0 means the item
is being accessed by come client.  Remember, several clients may
access the item simultaneously, so you shouldn't free it if some other
client is working with it right now.

When item expires (or when 'delete' request is received), we check if
its refcount is zero.  If so, no one is accessing it this very moment,
and we may free it.  If refcount > 0, then we just clear ITEM_LINKED
flag and do nothing.  Instead, the client that is accessing the item
will eventually call do_item_remove() to decrement refcount, and there
there's a statement

    if (it->refcount == 0 && (it->it_flags & ITEM_LINKED) == 0) {
        item_free(it);
    }

I.e. the last client that accessed the item will free it if it's
marked to be freed.


-- 
   Tomash Brechko


More information about the memcached mailing list