From: Mike Kravetz <kravetz@us.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Dave Hansen <haveblue@us.ibm.com>,
Christoph Lameter <clameter@sgi.com>,
Andy Whitcroft <apw@shadowen.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] alloc_memory_early() routines
Date: Tue, 9 May 2006 14:07:23 -0700 [thread overview]
Message-ID: <20060509210722.GD3168@w-mikek2.ibm.com> (raw)
In-Reply-To: <20060508224952.0b43d0fd.akpm@osdl.org>
Add alloc_memory_early() routines so that code needing to allocate
space during boot need not be aware of which allocator is in use.
Includes first use of such routine by the SPARSEMEM code.
I did not include support for 'large' allocations as suggested by
Dave, or corresponding free_memory_early() routines. The only
immediate need is for NUMA/node aware allocation. Others can be
added as the needs arise.
Signed-off-by: Mike Kravetz <kravetz@us.ibm.com>
diff -Naupr linux-2.6.17-rc3-mm1/include/linux/slab.h linux-2.6.17-rc3-mm1.work3/include/linux/slab.h
--- linux-2.6.17-rc3-mm1/include/linux/slab.h 2006-05-03 22:19:15.000000000 +0000
+++ linux-2.6.17-rc3-mm1.work3/include/linux/slab.h 2006-05-09 21:09:37.000000000 +0000
@@ -150,10 +150,12 @@ static inline void *kcalloc(size_t n, si
extern void kfree(const void *);
extern unsigned int ksize(const void *);
+extern void *alloc_memory_early(size_t size, gfp_t flags);
#ifdef CONFIG_NUMA
extern void *kmem_cache_alloc_node(kmem_cache_t *, gfp_t flags, int node);
extern void *kmalloc_node(size_t size, gfp_t flags, int node);
+extern void *alloc_memory_early_node(size_t size, gfp_t flags, int node);
#else
static inline void *kmem_cache_alloc_node(kmem_cache_t *cachep, gfp_t flags, int node)
{
@@ -163,6 +165,10 @@ static inline void *kmalloc_node(size_t
{
return kmalloc(size, flags);
}
+static inline void *alloc_memory_early_node(size_t size, gfp_t flags, int node)
+{
+ return alloc_memory_early(size, flags);
+}
#endif
extern int FASTCALL(kmem_cache_reap(int));
diff -Naupr linux-2.6.17-rc3-mm1/mm/slab.c linux-2.6.17-rc3-mm1.work3/mm/slab.c
--- linux-2.6.17-rc3-mm1/mm/slab.c 2006-05-03 22:19:16.000000000 +0000
+++ linux-2.6.17-rc3-mm1.work3/mm/slab.c 2006-05-09 21:38:23.000000000 +0000
@@ -108,6 +108,7 @@
#include <linux/mempolicy.h>
#include <linux/mutex.h>
#include <linux/rtmutex.h>
+#include <linux/bootmem.h>
#include <asm/uaccess.h>
#include <asm/cacheflush.h>
@@ -3266,8 +3267,24 @@ void *kmalloc_node(size_t size, gfp_t fl
return kmem_cache_alloc_node(cachep, flags, node);
}
EXPORT_SYMBOL(kmalloc_node);
+
+void * __init alloc_memory_early_node(size_t size, gfp_t flags, int node)
+{
+ if (g_cpucache_up == FULL)
+ return kmalloc_node(size, flags, node);
+ else
+ return alloc_bootmem_node(NODE_DATA(node), size);
+}
#endif
+void * __init alloc_memory_early(size_t size, gfp_t flags)
+{
+ if (g_cpucache_up == FULL)
+ return kmalloc(size, flags);
+ else
+ return alloc_bootmem(size);
+}
+
/**
* kmalloc - allocate memory
* @size: how many bytes of memory are required.
diff -Naupr linux-2.6.17-rc3-mm1/mm/sparse.c linux-2.6.17-rc3-mm1.work3/mm/sparse.c
--- linux-2.6.17-rc3-mm1/mm/sparse.c 2006-05-03 22:19:16.000000000 +0000
+++ linux-2.6.17-rc3-mm1.work3/mm/sparse.c 2006-05-09 20:37:51.000000000 +0000
@@ -32,11 +32,7 @@ static struct mem_section *sparse_index_
unsigned long array_size = SECTIONS_PER_ROOT *
sizeof(struct mem_section);
- if (system_state == SYSTEM_RUNNING)
- section = kmalloc_node(array_size, GFP_KERNEL, nid);
- else
- section = alloc_bootmem_node(NODE_DATA(nid), array_size);
-
+ section = alloc_memory_early_node(array_size, GFP_KERNEL, nid);
if (section)
memset(section, 0, array_size);
next prev parent reply other threads:[~2006-05-09 21:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-09 5:35 Add SYSTEM_BOOTING_KMALLOC_AVAIL system_state Mike Kravetz
2006-05-09 5:49 ` Andrew Morton
2006-05-09 6:01 ` Christoph Lameter
2006-05-09 17:20 ` Dave Hansen
2006-05-09 17:48 ` Mike Kravetz
2006-05-09 21:07 ` Mike Kravetz [this message]
2006-05-10 7:09 ` [PATCH] alloc_memory_early() routines Pekka Enberg
2006-05-10 7:11 ` Christoph Lameter
2006-05-10 7:16 ` Pekka J Enberg
2006-05-10 8:29 ` Andi Kleen
2006-05-10 16:16 ` Mike Kravetz
2006-05-10 17:42 ` Pekka J Enberg
2006-05-10 7:19 ` Pekka Enberg
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=20060509210722.GD3168@w-mikek2.ibm.com \
--to=kravetz@us.ibm.com \
--cc=akpm@osdl.org \
--cc=apw@shadowen.org \
--cc=clameter@sgi.com \
--cc=haveblue@us.ibm.com \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®