lkml.org 
[lkml]   [2011]   [Nov]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: Slub Allocator: Why get_order(size * MAX_OBJS_PER_PAGE) - 1 in function slab_order()?
From
2011/11/24 zhihua che <zhihua.che@gmail.com>:
> 2011/11/24 David Rientjes <rientjes@google.com>:
>> On Wed, 23 Nov 2011, zhihua che wrote:
>>
>>> I know what you mean, that is, a slab can only store no more than
>>> MAX_OBJS_PER_PAGE, actually 0x7FFF, objects.
>>>
>>> But  get_order(size * MAX_OBJS_PER_PAGE) already returns the order
>>> which reserves no_more_than size * MAX_OBJS_PER_PAGE memory.  Right?
>>>
>>
>> Yes, but it reserves too much memory if the conditional is true.
>>
>>> So I think there is no need to subtract one.
>>>
>>
>> If we didn't subtract one, then the order of a slab page would allow for
>> _more_ than MAX_OBJS_PER_PAGE to be allocated and that's not allowed
>> because of the restrictions in struct page.
>>
>> Consider a page size of 4K and an object size of 8 bytes.
>> get_order(8 * 32767) would be 6, so that's a 4K * 2^6 = 256K slab page
>> without the subtraction and could allocate (256K * 1024 / 8) = 32768 which
>> is greater than MAX_OBJS_PER_PAGE and not allowed.
>>
>> So we subtract one so the compound slab page is guaranteed to allocate
>> less than MAX_OBJS_PER_PAGE.
>
> Oh, sorry to bother you ... I guess I calculated a wrong result. I
> repeat your and my example carefully and you're right.
>
> Thanks very much for your patience :)
>

I guess I find what I'm wrong with. I pick a 0x8000 instead of 0x7FFF
as my example, because I though it's convenient.
But the 0x8000, as a power of two, turned out to be a proper order 7,
which can store 0x8000 objects without subtracting one.

Whatever, I made a stupid mistake.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2011-11-24 05:59    [W:0.080 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site