From: Christoph Lameter <cl@linux.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: glommer@parallels.com, penberg@kernel.org, linux-kernel@vger.kernel.org
Subject: Fix off by one error in slab.h
Date: Tue, 30 Apr 2013 15:16:12 +0000 [thread overview]
Message-ID: <0000013e5b83ec27-03a11e6a-157a-40ac-a65d-0281ee0d40fe-000000@email.amazonses.com> (raw)
In-Reply-To: <201304300645.FCE37285.tVHJLSOMQFOFFO@I-love.SAKURA.ne.jp>
Subject: Fix off by one error in slab.h
We ran into some strange issues as a result of an off by one isse in slab.h
The root of the issue is the treatment of KMALLOC_SHIFT_HIGH that is confusing.
Make KMALLOC_SHIFT_HIGH the first unsupported size instead of the last supported.
Signed-off-by: Christoph Lameter <cl@linux.com>
Index: linux/include/linux/slab.h
===================================================================
--- linux.orig/include/linux/slab.h 2013-04-30 09:54:23.636533564 -0500
+++ linux/include/linux/slab.h 2013-04-30 10:10:35.676932866 -0500
@@ -176,8 +176,8 @@ struct kmem_cache {
* to do various tricks to work around compiler limitations in order to
* ensure proper constant folding.
*/
-#define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT - 1) <= 25 ? \
- (MAX_ORDER + PAGE_SHIFT - 1) : 25)
+#define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT) <= 26 ? \
+ (MAX_ORDER + PAGE_SHIFT) : 26)
#define KMALLOC_SHIFT_MAX KMALLOC_SHIFT_HIGH
#define KMALLOC_SHIFT_LOW 5
#else
@@ -185,7 +185,7 @@ struct kmem_cache {
* SLUB allocates up to order 2 pages directly and otherwise
* passes the request to the page allocator.
*/
-#define KMALLOC_SHIFT_HIGH (PAGE_SHIFT + 1)
+#define KMALLOC_SHIFT_HIGH (PAGE_SHIFT + 2)
#define KMALLOC_SHIFT_MAX (MAX_ORDER + PAGE_SHIFT)
#define KMALLOC_SHIFT_LOW 3
#endif
@@ -193,7 +193,7 @@ struct kmem_cache {
/* Maximum allocatable size */
#define KMALLOC_MAX_SIZE (1UL << KMALLOC_SHIFT_MAX)
/* Maximum size for which we actually use a slab cache */
-#define KMALLOC_MAX_CACHE_SIZE (1UL << KMALLOC_SHIFT_HIGH)
+#define KMALLOC_MAX_CACHE_SIZE ((1UL << (KMALLOC_SHIFT_HIGH -1)))
/* Maximum order allocatable via the slab allocagtor */
#define KMALLOC_MAX_ORDER (KMALLOC_SHIFT_MAX - PAGE_SHIFT)
@@ -206,9 +206,9 @@ struct kmem_cache {
#define KMALLOC_MIN_SIZE (1 << KMALLOC_SHIFT_LOW)
#endif
-extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
+extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH];
#ifdef CONFIG_ZONE_DMA
-extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
+extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH];
#endif
/*
Index: linux/mm/slab_common.c
===================================================================
--- linux.orig/mm/slab_common.c 2013-04-30 09:54:23.636533564 -0500
+++ linux/mm/slab_common.c 2013-04-30 09:54:53.693039252 -0500
@@ -319,11 +319,11 @@ struct kmem_cache *__init create_kmalloc
return s;
}
-struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
+struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH];
EXPORT_SYMBOL(kmalloc_caches);
#ifdef CONFIG_ZONE_DMA
-struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
+struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH];
EXPORT_SYMBOL(kmalloc_dma_caches);
#endif
@@ -446,7 +446,7 @@ void __init create_kmalloc_caches(unsign
if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2])
kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
- for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++)
+ for (i = KMALLOC_SHIFT_LOW; i < KMALLOC_SHIFT_HIGH; i++)
if (!kmalloc_caches[i])
kmalloc_caches[i] = create_kmalloc_cache(NULL,
1 << i, flags);
@@ -454,7 +454,7 @@ void __init create_kmalloc_caches(unsign
/* Kmalloc array is now usable */
slab_state = UP;
- for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
+ for (i = 0; i < KMALLOC_SHIFT_HIGH; i++) {
struct kmem_cache *s = kmalloc_caches[i];
char *n;
@@ -467,7 +467,7 @@ void __init create_kmalloc_caches(unsign
}
#ifdef CONFIG_ZONE_DMA
- for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
+ for (i = 0; i < KMALLOC_SHIFT_HIGH; i++) {
struct kmem_cache *s = kmalloc_caches[i];
if (s) {
next prev parent reply other threads:[~2013-04-30 15:28 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-24 12:08 [linux-next-20130422] Bug in bootup code or debug code? Tetsuo Handa
2013-04-25 12:20 ` [linux-next-20130422] Bug in SLAB? Tetsuo Handa
2013-04-29 2:40 ` Tetsuo Handa
2013-04-29 10:12 ` Pekka Enberg
2013-04-29 14:44 ` Glauber Costa
2013-04-29 14:59 ` Christoph Lameter
2013-04-29 15:16 ` Glauber Costa
2013-04-29 15:46 ` Christoph Lameter
2013-04-29 15:54 ` Glauber Costa
2013-04-29 15:28 ` Tetsuo Handa
2013-04-29 16:16 ` Tetsuo Handa
2013-05-09 12:25 ` Tetsuo Handa
2013-05-09 14:14 ` Christoph Lameter
2013-05-09 21:54 ` Tetsuo Handa
2013-05-10 12:38 ` Tetsuo Handa
2013-05-10 15:57 ` Christoph Lameter
[not found] ` <201305272153.HEH51089.OHFQMOOtFLSFVJ@I-love.SAKURA.ne.jp>
2013-06-17 11:59 ` Tetsuo Handa
2013-04-29 17:48 ` Christoph Lameter
2013-04-29 21:45 ` Tetsuo Handa
2013-04-30 14:26 ` Christoph Lameter
2013-04-30 16:01 ` Tetsuo Handa
2013-04-30 17:27 ` Christoph Lameter
2013-05-01 8:05 ` Pekka Enberg
2013-05-02 15:12 ` Christoph Lameter
2013-05-01 12:14 ` Tetsuo Handa
2013-05-02 11:51 ` Tetsuo Handa
2013-05-02 20:53 ` Christoph Lameter
2013-05-03 8:26 ` Tetsuo Handa
2013-05-03 15:43 ` Christoph Lameter
2013-05-06 6:59 ` Geert Uytterhoeven
2013-05-06 7:27 ` Pekka Enberg
2013-05-03 18:04 ` Christoph Lameter
2013-05-03 18:48 ` Tetsuo Handa
2013-05-03 19:21 ` Christoph Lameter
2013-05-04 0:15 ` Tetsuo Handa
2013-05-06 13:46 ` Christoph Lameter
2013-05-07 10:38 ` Tetsuo Handa
2013-05-07 14:28 ` Christoph Lameter
2013-07-01 20:09 ` Andrew Morton
2013-07-01 21:45 ` Tetsuo Handa
2013-07-01 21:53 ` Andrew Morton
2013-07-02 12:49 ` Tetsuo Handa
2013-07-02 19:12 ` Andrew Morton
2013-07-07 15:58 ` Pekka Enberg
2013-05-06 6:32 ` Pekka Enberg
2013-05-06 13:47 ` Christoph Lameter
2013-05-06 20:24 ` Pekka Enberg
2013-05-07 14:23 ` Christoph Lameter
2013-05-07 14:44 ` Pekka Enberg
2013-05-07 15:40 ` Christoph Lameter
2013-04-30 14:34 ` Christoph Lameter
2013-05-01 8:03 ` Pekka Enberg
2013-05-02 15:13 ` Christoph Lameter
2013-04-30 15:16 ` Christoph Lameter [this message]
2013-04-29 2:56 ` Zhan Jianyu
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=0000013e5b83ec27-03a11e6a-157a-40ac-a65d-0281ee0d40fe-000000@email.amazonses.com \
--to=cl@linux.com \
--cc=glommer@parallels.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@kernel.org \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
/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).