From: Christoph Lameter <clameter@sgi.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Jeremy Fitzhardinge <jeremy@goop.org>,
Srinivasa Ds <srinivasa@in.ibm.com>,
linux-kernel@vger.kernel.org,
Srivatsa Vaddagiri <vatsa@in.ibm.com>,
Dinakar Guniguntala <dino@in.ibm.com>,
pj@sgi.com, simon.derr@bull.net, clameter@cthulhu.engr.sgi.com,
rientjes@google.com
Subject: Re: [RFC] [PATCH] cpuset operations causes Badness at mm/slab.c:777 warning
Date: Fri, 1 Jun 2007 16:46:50 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0706011642530.9992@schroedinger.engr.sgi.com> (raw)
In-Reply-To: <alpine.LFD.0.98.0706011638360.3957@woody.linux-foundation.org>
On Fri, 1 Jun 2007, Linus Torvalds wrote:
> I'm not seeing the path on the freeing side that silently accepts BADPTR.
>
> It is not ok to derefence BADPTR, but it's obviously ok to _free_ it.
Ok.
> Also, if I read the patch correctly, you _also_ return BADPTR for slabs
> that are too large. No? That would be wrong - those need to return NULL
> for "out of memory".
A too large alloc is >32MB or MAX_ORDER << PAGE_SIZE. A BUG_ON in
kmalloc_slab() will trigger.
Here is the updated patch. It works fine here:
SLUB: Return BADPTR instead of warning for kmalloc(0)
Remove the WARN_ON_ONCE and simply return BADPTR.
BADPTR can be used legitimately as long as it is not dereferenced.
Can even be freed.
Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
include/linux/slub_def.h | 18 ++++++++----------
mm/slub.c | 10 +++++-----
2 files changed, 13 insertions(+), 15 deletions(-)
Index: slub/include/linux/slub_def.h
===================================================================
--- slub.orig/include/linux/slub_def.h 2007-06-01 16:19:36.000000000 -0700
+++ slub/include/linux/slub_def.h 2007-06-01 16:43:57.000000000 -0700
@@ -12,6 +12,8 @@
#include <linux/kobject.h>
#include <linux/log2.h>
+#define BADPTR ((void *)16)
+
struct kmem_cache_node {
spinlock_t list_lock; /* Protect partial list and nr_partial */
unsigned long nr_partial;
@@ -74,13 +76,9 @@ extern struct kmem_cache kmalloc_caches[
*/
static inline int kmalloc_index(size_t size)
{
- /*
- * We should return 0 if size == 0 (which would result in the
- * kmalloc caller to get NULL) but we use the smallest object
- * here for legacy reasons. Just issue a warning so that
- * we can discover locations where we do 0 sized allocations.
- */
- WARN_ON_ONCE(size == 0);
+
+ if (!size)
+ return 0;
if (size > KMALLOC_MAX_SIZE)
return -1;
@@ -133,7 +131,7 @@ static inline void *kmalloc(size_t size,
struct kmem_cache *s = kmalloc_slab(size);
if (!s)
- return NULL;
+ return BADPTR;
return kmem_cache_alloc(s, flags);
} else
@@ -146,7 +144,7 @@ static inline void *kzalloc(size_t size,
struct kmem_cache *s = kmalloc_slab(size);
if (!s)
- return NULL;
+ return BADPTR;
return kmem_cache_zalloc(s, flags);
} else
@@ -162,7 +160,7 @@ static inline void *kmalloc_node(size_t
struct kmem_cache *s = kmalloc_slab(size);
if (!s)
- return NULL;
+ return BADPTR;
return kmem_cache_alloc_node(s, flags, node);
} else
Index: slub/mm/slub.c
===================================================================
--- slub.orig/mm/slub.c 2007-06-01 16:21:00.000000000 -0700
+++ slub/mm/slub.c 2007-06-01 16:43:27.000000000 -0700
@@ -2286,7 +2286,7 @@ void *__kmalloc(size_t size, gfp_t flags
if (s)
return slab_alloc(s, flags, -1, __builtin_return_address(0));
- return NULL;
+ return BADPTR;
}
EXPORT_SYMBOL(__kmalloc);
@@ -2297,7 +2297,7 @@ void *__kmalloc_node(size_t size, gfp_t
if (s)
return slab_alloc(s, flags, node, __builtin_return_address(0));
- return NULL;
+ return BADPTR;
}
EXPORT_SYMBOL(__kmalloc_node);
#endif
@@ -2338,7 +2338,7 @@ void kfree(const void *x)
struct kmem_cache *s;
struct page *page;
- if (!x)
+ if (!x || x == BADPTR)
return;
page = virt_to_head_page(x);
@@ -2707,7 +2707,7 @@ void *__kmalloc_track_caller(size_t size
struct kmem_cache *s = get_slab(size, gfpflags);
if (!s)
- return NULL;
+ return BADPTR;
return slab_alloc(s, gfpflags, -1, caller);
}
@@ -2718,7 +2718,7 @@ void *__kmalloc_node_track_caller(size_t
struct kmem_cache *s = get_slab(size, gfpflags);
if (!s)
- return NULL;
+ return BADPTR;
return slab_alloc(s, gfpflags, node, caller);
}
next prev parent reply other threads:[~2007-06-01 23:46 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-01 7:27 Srinivasa Ds
2007-06-01 10:50 ` Srinivasa Ds
2007-06-01 18:13 ` Christoph Lameter
2007-06-01 19:11 ` Paul Jackson
2007-06-01 19:18 ` Christoph Lameter
2007-06-01 19:47 ` Paul Jackson
2007-06-01 19:51 ` Christoph Lameter
2007-06-01 20:02 ` Paul Jackson
2007-06-01 20:06 ` Christoph Lameter
2007-06-01 20:19 ` Paul Jackson
2007-06-01 20:43 ` Christoph Lameter
2007-06-01 20:54 ` Paul Jackson
2007-06-01 20:30 ` Jeremy Fitzhardinge
2007-06-01 20:44 ` Paul Jackson
2007-06-01 20:47 ` Christoph Lameter
2007-06-01 20:56 ` Jeremy Fitzhardinge
2007-06-01 20:59 ` Andrew Morton
2007-06-01 21:45 ` Christoph Lameter
2007-06-01 22:16 ` Andrew Morton
2007-06-01 22:20 ` Christoph Lameter
2007-06-01 22:33 ` Andrew Morton
2007-06-01 22:41 ` Christoph Lameter
2007-06-01 23:00 ` Linus Torvalds
2007-06-01 23:29 ` Christoph Lameter
2007-06-01 23:41 ` Linus Torvalds
2007-06-01 23:46 ` Christoph Lameter [this message]
2007-06-01 23:57 ` Linus Torvalds
2007-06-02 0:12 ` Christoph Lameter
2007-06-02 0:16 ` Andrew Morton
2007-06-02 0:26 ` Christoph Lameter
2007-06-02 1:04 ` Linus Torvalds
2007-06-02 0:46 ` Jeremy Fitzhardinge
2007-06-02 1:05 ` Valdis.Kletnieks
2007-06-02 1:24 ` Christoph Lameter
2007-06-01 23:02 ` Andrew Morton
2007-06-01 23:16 ` Christoph Lameter
2007-06-01 23:21 ` Christoph Lameter
2007-06-01 23:36 ` Linus Torvalds
2007-06-01 23:42 ` Christoph Lameter
2007-06-01 23:25 ` Linus Torvalds
2007-06-02 0:41 ` Jeremy Fitzhardinge
2007-06-02 0:43 ` Jeremy Fitzhardinge
2007-06-02 0:51 ` Andrew Morton
2007-06-02 0:59 ` Jeremy Fitzhardinge
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=Pine.LNX.4.64.0706011642530.9992@schroedinger.engr.sgi.com \
--to=clameter@sgi.com \
--cc=akpm@linux-foundation.org \
--cc=clameter@cthulhu.engr.sgi.com \
--cc=dino@in.ibm.com \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pj@sgi.com \
--cc=rientjes@google.com \
--cc=simon.derr@bull.net \
--cc=srinivasa@in.ibm.com \
--cc=torvalds@linux-foundation.org \
--cc=vatsa@in.ibm.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
all inboxes | Powered by JetHome®