On Mon, 3 Oct 2016, yuantao peng wrote:

> Hi,  --    I am reading memcached source code and got a question on this 
> function:  do_slabs_alloc_chunked,   it is called by do_slabs_alloc if the 
> request size is larger than
> the slabclass size.  I am curious why we don't just move to a slabclass with 
> larger size instead?  Also, I am not sure I understand the way it calculated 
> the number of chunks
> needed:

That's only used if it's already at the highest slab class. It chains
multiple chunks of the highest possible class together.

>     int csize = p->size - sizeof(item_chunk);
>     unsigned int chunks_req = size / csize;
>     if (size % csize != 0)
>         chunks_req++;
>
>
> later on, we store the first chunk in do_item_alloc as follows:
>
> if (it->it_flags & ITEM_CHUNKED) {
>         item_chunk *chunk = (item_chunk *) ITEM_data(it);
>
>         chunk->next = (item_chunk *) it->h_next;
>         chunk->prev = 0;
>         chunk->head = it;
>         /* Need to chain back into the head's chunk */
>         chunk->next->prev = chunk;
>         chunk->size = chunk->next->size - ((char *)chunk - (char *)it);
>         chunk->used = 0;
>         assert(chunk->size > 0);
>     }
>
> That means the first item has an item_chunk header next to item header,   
> then the csize calculation is wrong, isn't it?   Say if csize equals 2,  we 
> will actually need 3
> chunks, because the first chunk will have more meta data (item+item_chunk),   
> am I missing something here?

Wish I didn't have to do that, it is pretty confusing. I can double check
but the size of the header is added and removed in the appropriate places
and it's gotten quite a lot of testing.

That particular section you're looking at is settign the initial chunk
size to the potential size of the chunk minus the offset the current chunk
is into the overall item the header is stored into. So that should take
into account the entire rendered metadata.

> thanks
> yuantao
>
> --
>
> ---
> 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 memcached+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 

--- 
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 memcached+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to