From: Andrew Morton <akpm@digeo.com>
To: Brian Gerst <bgerst@didntduck.org>
Cc: manfred@colorfullife.com, linux-kernel@vger.kernel.org
Subject: Re: [RFC,PATCH] optimize fixed size kmalloc calls
Date: Tue, 10 Jun 2003 16:00:44 -0700 [thread overview]
Message-ID: <20030610160044.1317953f.akpm@digeo.com> (raw)
In-Reply-To: <3EE531AA.4090404@quark.didntduck.org>
Brian Gerst <bgerst@didntduck.org> wrote:
>
> > 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.
It doesn't compile with older gcc's - see the `extern' decl in the middle
of the function.
The compiler should have been given a way of disabling this. It'd going to
bite again and again.
I'll fix it up.
void *kmalloc(size_t size, int flags)
{
if (__builtin_constant_p(size)) {
int i = 0;
# 1 "include/linux/kmalloc_sizes.h" 1
if (size <= 32) goto found; else i++;
if (size <= 64) goto found; else i++;
if (size <= 128) goto found; else i++;
if (size <= 256) goto found; else i++;
if (size <= 512) goto found; else i++;
if (size <= 1024) goto found; else i++;
if (size <= 2048) goto found; else i++;
if (size <= 4096) goto found; else i++;
if (size <= 8192) goto found; else i++;
if (size <= 16384) goto found; else i++;
if (size <= 32768) goto found; else i++;
if (size <= 65536) goto found; else i++;
if (size <= 131072) goto found; else i++;
# 84 "include/linux/slab.h" 2
extern void __you_cannot_kmalloc_that_much(void);
__you_cannot_kmalloc_that_much();
found:
return kmem_cache_alloc((flags & 0x01) ?
malloc_sizes[i].cs_dmacachep :
malloc_sizes[i].cs_cachep, flags);
}
return __kmalloc(size, flags);
}
prev parent reply other threads:[~2003-06-10 22:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-09 19:38 Manfred Spraul
2003-06-10 1:17 ` Brian Gerst
2003-06-10 23:00 ` Andrew Morton [this message]
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=20030610160044.1317953f.akpm@digeo.com \
--to=akpm@digeo.com \
--cc=bgerst@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
all inboxes | Powered by JetHome®