From: Brian Gerst <bgerst@quark.didntduck.org>
To: Manfred Spraul <manfred@colorfullife.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC,PATCH] optimize fixed size kmalloc calls
Date: Mon, 09 Jun 2003 21:17:30 -0400 [thread overview]
Message-ID: <3EE531AA.4090404@quark.didntduck.org> (raw)
In-Reply-To: <3EE4E23E.4070307@colorfullife.com>
[-- Attachment #1: Type: text/plain, Size: 601 bytes --]
Manfred Spraul wrote:
> Hi,
>
> kmalloc(constant,GFP_KERNEL) spends a singificant amount of time in the
> initial loop that finds the correct cache. For constant allocations, the
> correct cache can be indentified at compile time.
>
> What do you think about the attached patch? It's not pretty, but it
> should work will all gcc versions. Any other ideas?
> Just FYI: The function that forced me to use use switch/case instead of
> if is interrupts_open in fs/proc/proc_misc.c.
How about this? GCC 3.2.2 is able to optimize it away properly from the
tests that I've run.
--
Brian Gerst
[-- Attachment #2: kmalloc-const-1 --]
[-- Type: text/plain, Size: 2498 bytes --]
diff -ur linux-2.5.70-bk/include/linux/slab.h linux/include/linux/slab.h
--- linux-2.5.70-bk/include/linux/slab.h 2003-05-26 22:27:29.000000000 -0400
+++ linux/include/linux/slab.h 2003-06-09 17:24:40.000000000 -0400
@@ -62,7 +62,36 @@
extern void kmem_cache_free(kmem_cache_t *, void *);
extern unsigned int kmem_cache_size(kmem_cache_t *);
-extern void *kmalloc(size_t, int);
+/* Size description struct for general caches. */
+struct cache_sizes {
+ size_t cs_size;
+ kmem_cache_t *cs_cachep;
+ kmem_cache_t *cs_dmacachep;
+};
+extern struct cache_sizes malloc_sizes[];
+extern void *__kmalloc(size_t, int);
+
+static inline void *kmalloc(size_t size, int flags)
+{
+ if (__builtin_constant_p(size)) {
+ int i = 0;
+#define CACHE(x) \
+ if (size <= x) \
+ goto found; \
+ else \
+ i++;
+#include "kmalloc_sizes.h"
+#undef CACHE
+ extern void __you_cannot_kmalloc_that_much(void);
+ __you_cannot_kmalloc_that_much();
+found:
+ return kmem_cache_alloc((flags & GFP_DMA) ?
+ malloc_sizes[i].cs_dmacachep :
+ malloc_sizes[i].cs_cachep, flags);
+ }
+ return __kmalloc(size, flags);
+}
+
extern void kfree(const void *);
extern unsigned int ksize(const void *);
diff -ur linux-2.5.70-bk/kernel/ksyms.c linux/kernel/ksyms.c
--- linux-2.5.70-bk/kernel/ksyms.c 2003-06-08 23:50:12.000000000 -0400
+++ linux/kernel/ksyms.c 2003-06-09 16:44:27.000000000 -0400
@@ -95,7 +95,8 @@
EXPORT_SYMBOL(kmem_cache_size);
EXPORT_SYMBOL(set_shrinker);
EXPORT_SYMBOL(remove_shrinker);
-EXPORT_SYMBOL(kmalloc);
+EXPORT_SYMBOL(malloc_sizes);
+EXPORT_SYMBOL(__kmalloc);
EXPORT_SYMBOL(kfree);
#ifdef CONFIG_SMP
EXPORT_SYMBOL(__alloc_percpu);
diff -ur linux-2.5.70-bk/mm/slab.c linux/mm/slab.c
--- linux-2.5.70-bk/mm/slab.c 2003-06-08 23:50:13.000000000 -0400
+++ linux/mm/slab.c 2003-06-09 16:43:55.000000000 -0400
@@ -385,11 +385,7 @@
#define GET_PAGE_SLAB(pg) ((struct slab *)(pg)->list.prev)
/* These are the default caches for kmalloc. Custom caches can have other sizes. */
-static struct cache_sizes {
- size_t cs_size;
- kmem_cache_t *cs_cachep;
- kmem_cache_t *cs_dmacachep;
-} malloc_sizes[] = {
+struct cache_sizes malloc_sizes[] = {
#define CACHE(x) { .cs_size = (x) },
#include <linux/kmalloc_sizes.h>
{ 0, }
@@ -1967,7 +1963,7 @@
* platforms. For example, on i386, it means that the memory must come
* from the first 16MB.
*/
-void * kmalloc (size_t size, int flags)
+void * __kmalloc (size_t size, int flags)
{
struct cache_sizes *csizep = malloc_sizes;
next prev parent reply other threads:[~2003-06-10 1:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-09 19:38 [RFC,PATCH] optimize fixed size kmalloc calls Manfred Spraul
2003-06-10 1:17 ` Brian Gerst [this message]
2003-06-10 23:00 ` Andrew Morton
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=3EE531AA.4090404@quark.didntduck.org \
--to=bgerst@quark.didntduck.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
/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