All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] [PATCH] kmem_alloc (generic wrapper for kmalloc and vmalloc)
@ 2004-11-10  5:19 Carl-Daniel Hailfinger
  2004-11-10  6:03 ` Robert Love
  0 siblings, 1 reply; 11+ messages in thread
From: Carl-Daniel Hailfinger @ 2004-11-10  5:19 UTC (permalink / raw)
  To: Linux Kernel Mailing List

Hi,

it seems there is a bunch of drivers which want to allocate memory as
efficiently as possible in a wide range of allocation sizes. XFS and
NTFS seem to be examples. Implement a generic wrapper to reduce code
duplication.
Functions have the my_ prefixes to avoid name clash with XFS.

Patch is compile tested

Comments/flames?

Regards,
Carl-Daniel
http://www.hailfinger.org/

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.kernel.2004@gmx.net>

--- ./linux-2.6.9/mm/slab.c~	2004-11-05 14:27:49.000000000 +0100
+++ ./linux-2.6.9/mm/slab.c	2004-11-10 03:27:19.000000000 +0100
@@ -507,6 +507,8 @@
 #undef CACHE
 };

+size_t MAX_KMALLOC_SIZE;
+
 static struct arraycache_init initarray_cache __initdata =
 	{ { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
 static struct arraycache_init initarray_generic __initdata =
@@ -728,6 +730,10 @@
 	struct cache_sizes *sizes;
 	struct cache_names *names;

+#define CACHE(x) MAX_KMALLOC_SIZE = x;
+#include <linux/kmalloc_sizes.h>
+#undef CACHE
+
 	/*
 	 * Fragmentation resistance on low memory - only use bigger
 	 * page orders on machines with more than 32MB of memory.
@@ -3039,3 +3045,25 @@

 	return size;
 }
+
+void * my_kmem_alloc(size_t size, int flags)
+{
+	void	*ptr = NULL;
+
+	if (size < MAX_KMALLOC_SIZE)
+		ptr = kmalloc(size, flags);
+	if (!ptr)
+		ptr = __vmalloc(size, flags, PAGE_KERNEL);
+	return ptr;
+}
+
+void my_kmem_free(void *ptr)
+{
+	if (((unsigned long)ptr < VMALLOC_START) ||
+	    ((unsigned long)ptr >= VMALLOC_END)) {
+		kfree(ptr);
+	} else {
+		vfree(ptr);
+	}
+}
+

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-11-10 18:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-10  5:19 [RFC] [PATCH] kmem_alloc (generic wrapper for kmalloc and vmalloc) Carl-Daniel Hailfinger
2004-11-10  6:03 ` Robert Love
2004-11-10  6:31   ` Carl-Daniel Hailfinger
2004-11-10  6:57     ` Robert Love
2004-11-10  7:10     ` Nick Piggin
2004-11-10 13:36     ` Geert Uytterhoeven
2004-11-10  7:54   ` Jens Axboe
2004-11-10 17:03     ` Carl-Daniel Hailfinger
2004-11-10 17:17       ` Roland Dreier
2004-11-10 17:54     ` Adam Heath
2004-11-10 18:04       ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.