From: David Rientjes <rientjes@google.com>
To: zhihua che <zhihua.che@gmail.com>
Cc: Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@cs.helsinki.fi>,
linux-kernel@vger.kernel.org
Subject: Re: Slub Allocator: Why get_order(size * MAX_OBJS_PER_PAGE) - 1 in function slab_order()?
Date: Tue, 22 Nov 2011 18:53:21 -0800 (PST) [thread overview]
Message-ID: <alpine.DEB.2.00.1111221847320.30008@chino.kir.corp.google.com> (raw)
In-Reply-To: <CABexPfF-31f1vcJpqdsDHKUHfes1230vwGMtm6ETZXVQQf4bcA@mail.gmail.com>
On Wed, 23 Nov 2011, zhihua che wrote:
> Hi, everyone,
> I'm reading the kernel codes about slub allocator and I come
> across a confusion. Precisely, I'm reading the initialization of the
> slub allocator, kmem_cache_init(), and I find it needs call
> calculate_sizes() to determine the order of a kmem_cache, given the
> size of the object. In turn, it calls the get_order() to get a
> possible order. The problem is, in the start of this function, why it
> looks like this:
>
> if (order_objects(min_order, size, reserved) > MAX_OBJS_PER_PAGE)
> return get_order(size * MAX_OBJS_PER_PAGE) - 1;
>
> I don't know why it subtracts one from the order returned by
> get_order().
> because as far as I know, get_order() returns the order the
> slab requires to reserve size * MAX_OBJS_PER_PAGE memory. If it
> subtracts 1 from the order returned by get_order(), the slab can't
> store MAX_OBJS_PER_PAGE objects at all, instead it can only store half
> of the MAX_OBJS_PER_PAGE objects.
> Could you correct me if I think in a wrong way.
I agree it looks confusing, but it's correct. SLUB can only store
MAX_OBJS_PER_PAGE because of limitations in struct page (see the comments
in include/linux/mm_types.h). So if the order will yield a page that
could fit _more_ than MAX_OBJS_PER_PAGE, we need to reduce the order by a
factor of 1.
next prev parent reply other threads:[~2011-11-23 2:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-22 20:40 Slub Allocator: Why get_order(size * MAX_OBJS_PER_PAGE) - 1 in function slab_order()? zhihua che
2011-11-23 2:53 ` David Rientjes [this message]
[not found] ` <CABexPfEte8U5pVBJ=LvRKMY5=oW7F2vRjw_d9893Yy8W88hfDg@mail.gmail.com>
2011-11-23 6:59 ` Fwd: " zhihua che
2011-11-23 23:06 ` David Rientjes
[not found] ` <CABexPfFFiNf8gj9EHnnWABmcK_wCiRkhxQObUnr0_oY2Dkp+JA@mail.gmail.com>
2011-11-24 4:44 ` zhihua che
2011-11-24 4:55 ` zhihua che
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.00.1111221847320.30008@chino.kir.corp.google.com \
--to=rientjes@google.com \
--cc=cl@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
--cc=zhihua.che@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).