From: Christoph Lameter <clameter@sgi.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>,
Srinivasa Ds <srinivasa@in.ibm.com>,
linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Srivatsa Vaddagiri <vatsa@in.ibm.com>,
Dinakar Guniguntala <dino@in.ibm.com>,
pj@sgi.com, simon.derr@bull.net, rientjes@google.com
Subject: Re: [RFC] [PATCH] cpuset operations causes Badness at mm/slab.c:777 warning
Date: Fri, 1 Jun 2007 16:16:55 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0706011615540.9781@schroedinger.engr.sgi.com> (raw)
In-Reply-To: <20070601160241.33b304bf.akpm@linux-foundation.org>
> So a kmalloc(62) would get upped to 66, so we allocate from size-128
> and put the number 62 at bytes 124-127 and we poison bytes 62-123?
Hmmm... We are going rapidly here. This is a patch that I am testing right
now. It right adjust the object and the patch is manageable:
SLUB mm-only: Right align kmalloc objects to trigger overwrite detection
Right align kmalloc objects if they are less than the full kmalloc slab size.
This will move the object to be flush with the end of the object in order
to allow the easy detection of writes / reads after the end of the kmalloc
object.
Without slub_debug overwrites will destroy the free pointer of the next object
or the next object. Read will yield garbage that is likely zero.
With slub_debug redzone checks will be triggered. Reads will read redzone
poison.
This patch is only for checking things out. There are issues:
1. Alignment of kmalloc objects may now be different. In particular
objects whose size is not a multiple of wordsize may be not word alignmed.
2. __kmalloc and kfree need to touch an additional cacheline in
struct kmem_cache thereby reducing performance.
3. An object allocated via kmalloc may no longer be freed via kmem_cache_free.
So we need to figure out some may to make this configurable. Preferably
runtime configurable.
Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
include/linux/slub_def.h | 22 +++++++++++++++++++---
mm/slub.c | 11 ++++++++---
2 files changed, 27 insertions(+), 6 deletions(-)
Index: slub/include/linux/slub_def.h
===================================================================
--- slub.orig/include/linux/slub_def.h 2007-06-01 15:56:42.000000000 -0700
+++ slub/include/linux/slub_def.h 2007-06-01 16:00:03.000000000 -0700
@@ -120,6 +120,19 @@ static inline struct kmem_cache *kmalloc
return &kmalloc_caches[index];
}
+static inline unsigned long kmalloc_size(size_t size)
+{
+ int index = kmalloc_index(size);
+
+ if (index >= KMALLOC_SHIFT_LOW)
+ return 1 << index;
+
+ if (index == 2)
+ return 192;
+ return 96;
+}
+
+
#ifdef CONFIG_ZONE_DMA
#define SLUB_DMA __GFP_DMA
#else
@@ -135,7 +148,8 @@ static inline void *kmalloc(size_t size,
if (!s)
return NULL;
- return kmem_cache_alloc(s, flags);
+ return kmem_cache_alloc(s, flags)
+ + kmalloc_size(size) - size;
} else
return __kmalloc(size, flags);
}
@@ -148,7 +162,8 @@ static inline void *kzalloc(size_t size,
if (!s)
return NULL;
- return kmem_cache_zalloc(s, flags);
+ return kmem_cache_zalloc(s, flags)
+ + kmalloc_size(size) - size;
} else
return __kzalloc(size, flags);
}
@@ -159,7 +174,8 @@ extern void *__kmalloc_node(size_t size,
static inline void *kmalloc_node(size_t size, gfp_t flags, int node)
{
if (__builtin_constant_p(size) && !(flags & SLUB_DMA)) {
- struct kmem_cache *s = kmalloc_slab(size);
+ struct kmem_cache *s = kmalloc_slab(size) +
+ kmalloc_size(size) - size;
if (!s)
return NULL;
Index: slub/mm/slub.c
===================================================================
--- slub.orig/mm/slub.c 2007-06-01 15:51:05.000000000 -0700
+++ slub/mm/slub.c 2007-06-01 16:15:21.000000000 -0700
@@ -2283,9 +2283,10 @@ static struct kmem_cache *get_slab(size_
void *__kmalloc(size_t size, gfp_t flags)
{
struct kmem_cache *s = get_slab(size, flags);
+ int offset = size - s->size;
if (s)
- return slab_alloc(s, flags, -1, __builtin_return_address(0));
+ return slab_alloc(s, flags, -1, __builtin_return_address(0)) + offset;
return NULL;
}
EXPORT_SYMBOL(__kmalloc);
@@ -2294,9 +2295,10 @@ EXPORT_SYMBOL(__kmalloc);
void *__kmalloc_node(size_t size, gfp_t flags, int node)
{
struct kmem_cache *s = get_slab(size, flags);
+ int offset = size - s->size;
if (s)
- return slab_alloc(s, flags, node, __builtin_return_address(0));
+ return slab_alloc(s, flags, node, __builtin_return_address(0)) + offset;
return NULL;
}
EXPORT_SYMBOL(__kmalloc_node);
@@ -2337,6 +2339,7 @@ void kfree(const void *x)
{
struct kmem_cache *s;
struct page *page;
+ unsigned long addr = (unsigned long) x;
if (!x)
return;
@@ -2344,7 +2347,9 @@ void kfree(const void *x)
page = virt_to_head_page(x);
s = page->slab;
- slab_free(s, page, (void *)x, __builtin_return_address(0));
+ addr &= ~((unsigned long)s->size - 1);
+
+ slab_free(s, page, (void *)addr, __builtin_return_address(0));
}
EXPORT_SYMBOL(kfree);
next prev parent reply other threads:[~2007-06-01 23:17 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
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 [this message]
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.0706011615540.9781@schroedinger.engr.sgi.com \
--to=clameter@sgi.com \
--cc=akpm@linux-foundation.org \
--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®