public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Mundt <lethal@linux-sh.org>
To: Pekka J Enberg <penberg@cs.helsinki.fi>
Cc: David Howells <dhowells@redhat.com>,
	Christoph Lameter <clameter@sgi.com>,
	LKML <linux-kernel@vger.kernel.org>,
	cooloney@kernel.org, akpm@linux-foundation.org, mpm@selenic.com
Subject: Re: [PATCH] nommu: fix kobjsize() for SLOB and SLUB
Date: Mon, 2 Jun 2008 14:59:22 +0900	[thread overview]
Message-ID: <20080602055922.GA24626@linux-sh.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0806011426150.17742@sbz-30.cs.Helsinki.FI>

On Sun, Jun 01, 2008 at 02:30:28PM +0300, Pekka J Enberg wrote:
> On Sun, Jun 01, 2008 at 01:29:39PM +0300, Pekka Enberg wrote:
> > > Oh, almost, you had this bit in ksize() of SLAB:
> > > 
> > > +	page = virt_to_head_page(objp);
> > > +	if (unlikely(!PageSlab(page)))
> > > +		return PAGE_SIZE << compound_order(page);
> > > 
> > > Did you actually need it for something?
>  
> On Sun, 1 Jun 2008, Paul Mundt wrote:
> > Not that I recall, it was just for consistency with SLUB. I'll have to
> > re-test though, as I'm not sure if it was necessary or not.
> 
> OK. If we do need it, then something like this should work. But I don't 
> see how we could have these "arbitrary pointers" (meaning not returned 
> by kmalloc()) to compound pages; otherwise the BUG_ON would trigger with 
> SLAB as well. I also don't see any call-sites that do this (but I'm not an 
> expert on nommu).
> 
In the kmem_cache_alloc() case calling ksize() there is bogus, the
previous semantics for kobjsize() just defaulted to returning PAGE_SIZE
for these, since page->index was typically 0. Presently if we ksize()
those objects, we get bogus size results that are smaller than the
minimum alignment size. So we still need a way to handle that, even if
it's not frightfully accurate.

If we go back and apply your PG_slab patch for SLUB + SLOB, then
kobjsize() can just become:

diff --git a/mm/nommu.c b/mm/nommu.c
index dca93fc..3abd084 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -104,21 +104,43 @@ EXPORT_SYMBOL(vmtruncate);
 unsigned int kobjsize(const void *objp)
 {
 	struct page *page;
+	int order = 0;
 
 	/*
 	 * If the object we have should not have ksize performed on it,
 	 * return size of 0
 	 */
-	if (!objp || (unsigned long)objp >= memory_end || !((page = virt_to_page(objp))))
+	if (!objp)
 		return 0;
 
+	if ((unsigned long)objp >= memory_end)
+		return 0;
+
+	page = virt_to_head_page(objp);
+	if (!page)
+		return 0;
+
+	/*
+	 * If the allocator sets PageSlab, we know the pointer came from
+	 * kmalloc().
+	 */
 	if (PageSlab(page))
 		return ksize(objp);
 
-	BUG_ON(page->index < 0);
-	BUG_ON(page->index >= MAX_ORDER);
+	/*
+	 * The ksize() function is only guaranteed to work for pointers
+	 * returned by kmalloc(). So handle arbitrary pointers, that we expect
+	 * always to be compound pages, here.
+	 */
+	if (PageCompound(page))
+		order = compound_order(page);
 
-	return (PAGE_SIZE << page->index);
+	/*
+	 * Finally, handle arbitrary pointers that don't set PageSlab.
+	 * Default to 0-order in the case when we're unable to ksize()
+	 * the object.
+	 */
+	return PAGE_SIZE << order;
 }
 
 /*

  reply	other threads:[~2008-06-02  6:01 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.64.0805281646470.27125@sbz-30.cs.Helsinki.FI>
     [not found] ` <20080528153648.GA27783@linux-sh.org>
2008-05-28 20:03   ` [PATCH] nommu: fix kobjsize() for SLOB and SLUB Pekka Enberg
2008-05-28 20:25     ` Christoph Lameter
2008-05-28 20:25       ` Pekka Enberg
2008-05-28 20:29         ` Christoph Lameter
2008-05-29 13:08           ` David Howells
2008-05-29 13:21             ` Pekka J Enberg
2008-05-29 21:12               ` Paul Mundt
2008-06-01  7:58                 ` Pekka Enberg
2008-06-01  8:22                   ` Pekka J Enberg
2008-06-01  8:24                     ` Paul Mundt
2008-06-01  8:36                       ` Pekka J Enberg
2008-06-01  9:13                       ` Pekka J Enberg
2008-06-01 10:24                         ` Paul Mundt
2008-06-01 10:29                           ` Pekka Enberg
2008-06-01 11:21                             ` Paul Mundt
2008-06-01 11:30                               ` Pekka J Enberg
2008-06-02  5:59                                 ` Paul Mundt [this message]
2008-06-02  6:32                                   ` Pekka Enberg
2008-06-02  6:50                                     ` Paul Mundt
2008-06-02  6:58                                       ` Pekka Enberg
2008-06-02  7:01                                         ` Paul Mundt
2008-06-01  8:22                   ` Paul Mundt
2008-05-29 15:00             ` Christoph Lameter
2008-05-22 16:09 Pekka J Enberg
2008-05-22 16:48 ` Christoph Lameter
2008-05-22 23:40 ` Paul Mundt
2008-05-22 23:45   ` Christoph Lameter
2008-05-22 23:50     ` Paul Mundt
2008-05-23  0:04       ` Christoph Lameter
2008-05-28 13:12 ` David Howells
2008-05-28 13:17   ` Pekka J Enberg
2008-05-28 13:40     ` David Howells
2008-05-28 14:09   ` David Howells
2008-05-28 17:26     ` Christoph Lameter
2008-05-28 17:38       ` David Howells
2008-05-28 20:35         ` Mike Frysinger
2008-05-29 13:03           ` David Howells
2008-05-29 20:25             ` Mike Frysinger
2008-05-29 20:30               ` Christoph Lameter
2008-05-29 20:51                 ` Mike Frysinger
2008-05-29 21:29                   ` Christoph Lameter
2008-05-30  4:18                     ` Mike Frysinger
2008-05-28 14:27   ` David Howells

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=20080602055922.GA24626@linux-sh.org \
    --to=lethal@linux-sh.org \
    --cc=akpm@linux-foundation.org \
    --cc=clameter@sgi.com \
    --cc=cooloney@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpm@selenic.com \
    --cc=penberg@cs.helsinki.fi \
    /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