> > > On Monday, October 3, 2016 at 9:17:00 PM UTC-4, Dormando wrote: > > > 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. > > > It is indeed quite confusing. :) Say if the highest slab class have size > 2000 bytes, and sizeof(item) and sizeof(item_chunk) are all 40 bytes, If I > call slab_alloc with > ntotal=3920 bytes, > since csize = p->size - sizeof(item_chunk) , csize would be 2000-40=1960, > and chunks_req=3920/1960=2. > > the following code in do_item_alloc will set the first chunk size to > (2000-40)=1960, > chunk->size = chunk->next->size - ((char *)chunk - (char *)it); > > but the first chunk is set to start at the location ITEM_data(it) as follows, > which is after the struct item meta data, shouldn't the chunk size here is > actually smaller than > 1960 because item_chunk meta data of the first chunk will also consume some > space? > > item_chunk *chunk = (item_chunk *) ITEM_data(it); >
Did you have a chance to play with the tests yourself? I didn't have enough time for the last bugfix release to look into it myself. -- --- 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.