lkml.org 
[lkml]   [2004]   [Nov]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC] [PATCH] kmem_alloc (generic wrapper for kmalloc and vmalloc)
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);
+ }
+}
+
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 14:07    [W:0.078 / U:0.016 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site