public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Andrew Morton <akpm@osdl.org>
Cc: Linus Torvalds <torvalds@osdl.org>,
	Paolo Ornati <ornati@fastwebnet.it>,
	Arjan van de Ven <arjan@infradead.org>,
	linux-kernel@vger.kernel.org,
	Pekka J Enberg <penberg@cs.Helsinki.FI>
Subject: [patch] mm/slab.c: fix early init assumption
Date: Fri, 2 Jun 2006 21:45:11 +0200	[thread overview]
Message-ID: <20060602194510.GA971@elte.hu> (raw)
In-Reply-To: <20060602134458.GA4914@elte.hu>

Subject: mm/slab.c: fix early init assumption
From: Ingo Molnar <mingo@elte.hu>

the SLAB bootstrap code assumes that the first two kmalloc caches
created (the INDEX_AC and INDEX_L3 kmalloc caches) wont be off-slab.
But due to AC and L3 structure size increase in lockdep, one of them
ended up being off-slab, and subsequently crashing with:

Unable to handle kernel NULL pointer dereference at 0000000000000000 RIP:
 [<ffffffff80267478>] kmem_cache_alloc+0x26/0x7d

the fix is to introduce a bootstrap flag and to use it to prevent
off-slab caches being created so early during bootup.

(the calculation for off-slab caches is quite complex so i didnt want
to complicate things with introducing yet another INDEX_ calculation,
the flag approach is simpler and smaller.)

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 mm/slab.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Index: linux/mm/slab.c
===================================================================
--- linux.orig/mm/slab.c
+++ linux/mm/slab.c
@@ -333,6 +333,8 @@ static __always_inline int index_of(cons
 	return 0;
 }
 
+static int slab_early_init = 1;
+
 #define INDEX_AC index_of(sizeof(struct arraycache_init))
 #define INDEX_L3 index_of(sizeof(struct kmem_list3))
 
@@ -1377,6 +1379,8 @@ void __init kmem_cache_init(void)
 				NULL, NULL);
 	}
 
+	slab_early_init = 0;
+
 	while (sizes->cs_size != ULONG_MAX) {
 		/*
 		 * For performance, all the general caches are L1 aligned.
@@ -2128,8 +2132,12 @@ kmem_cache_create (const char *name, siz
 #endif
 #endif
 
-	/* Determine if the slab management is 'on' or 'off' slab. */
-	if (size >= (PAGE_SIZE >> 3))
+	/*
+	 * Determine if the slab management is 'on' or 'off' slab.
+	 * (bootstrapping cannot cope with offslab caches so dont do
+	 *  it too early on.)
+	 */
+	if ((size >= (PAGE_SIZE >> 3)) && !slab_early_init)
 		/*
 		 * Size is large, assume best to place the slab management obj
 		 * off-slab (should allow better packing of objs).

      reply	other threads:[~2006-06-02 19:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-02 13:44 [patch] mm/slab.c: fix offslab_limit bug Ingo Molnar
2006-06-02 19:45 ` Ingo Molnar [this message]

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=20060602194510.GA971@elte.hu \
    --to=mingo@elte.hu \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ornati@fastwebnet.it \
    --cc=penberg@cs.Helsinki.FI \
    --cc=torvalds@osdl.org \
    /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