linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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: Fwd: Slub Allocator: Why get_order(size * MAX_OBJS_PER_PAGE) - 1 in function slab_order()?
Date: Wed, 23 Nov 2011 15:06:37 -0800 (PST)	[thread overview]
Message-ID: <alpine.DEB.2.00.1111231501030.24794@chino.kir.corp.google.com> (raw)
In-Reply-To: <CABexPfHxM=NpwrrbFrTJUVZHzORpVaqAwoh1yC7d=RTfwnQWwg@mail.gmail.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 968 bytes --]

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.

  reply	other threads:[~2011-11-23 23:06 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
     [not found]   ` <CABexPfEte8U5pVBJ=LvRKMY5=oW7F2vRjw_d9893Yy8W88hfDg@mail.gmail.com>
2011-11-23  6:59     ` Fwd: " zhihua che
2011-11-23 23:06       ` David Rientjes [this message]
     [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.1111231501030.24794@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).