memcached internals question

J Ravi Menon jravimenon at gmail.com
Wed Mar 26 18:05:10 UTC 2008


Hi.

I am new to this list, so let me know if this is not the right forum
to discuss memcached code.

We use memcached 1.2.2,  but I was also looking at the latest version
1.2.5 and I see the same logic.

During item_alloc(), I don't see the 'ntotal' being
normalized to the its appropriate 'chunk size':

[Note: I might be totally missing something or reading this wrong]


size_t ntotal = item_make_header(nkey + 1, flags, nbytes, suffix, &nsuffix);

    unsigned int id = slabs_clsid(ntotal);
    if (id == 0)
        return 0;

    it = slabs_alloc(ntotal, id);

In slabs_alloc(), adjust the ptr by 'ntotal' ( size=ntotal in this function):

 if (p->sl_curr != 0)
        return p->slots[--p->sl_curr];
.
.
 p->end_page_ptr += p->size;

Now say slab id 1 has chunk size 96, and slab id 2 has a
chunk_size=120, the id=2 is the bucket
for all item sizes from 97bytes to 120bytes.

Shouldn't it be adjusted to the maximum chunk size?

The reason I ask is that on slabs_free(), we return the item ptr back
to the slots list without any size info:

p->slots[p->sl_curr++] = ptr;


And in slabs_alloc(),  it consults the slots list first for a free ptr
which could now vary in size...

Am I missing something?

Thanks,
Ravi


More information about the memcached mailing list