All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carl-Daniel Hailfinger <c-d.hailfinger.kernel.2004@gmx.net>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [RFC] [PATCH] kmem_alloc (generic wrapper for kmalloc and vmalloc)
Date: Wed, 10 Nov 2004 06:19:30 +0100	[thread overview]
Message-ID: <4191A4E2.7040502@gmx.net> (raw)

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);
+	}
+}
+

             reply	other threads:[~2004-11-10  5:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-10  5:19 Carl-Daniel Hailfinger [this message]
2004-11-10  6:03 ` [RFC] [PATCH] kmem_alloc (generic wrapper for kmalloc and vmalloc) 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

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=4191A4E2.7040502@gmx.net \
    --to=c-d.hailfinger.kernel.2004@gmx.net \
    --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 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.