From: Manfred Spraul <manfred@colorfullife.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH,RFC] faster kmalloc lookup
Date: Sat, 26 Oct 2002 21:22:12 +0200 [thread overview]
Message-ID: <3DBAEB64.1090109@colorfullife.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 241 bytes --]
kmalloc spends a large part of the total execution time trying to find
the cache for the passed in size.
What about the attached patch (against 2.5.44-mm5)?
It uses fls jump over the caches that are definitively too small.
--
Manfred
[-- Attachment #2: patch-fast-kmalloc --]
[-- Type: text/plain, Size: 1219 bytes --]
--- 2.5/mm/slab.c Sat Oct 26 21:13:33 2002
+++ build-2.5/mm/slab.c Sat Oct 26 20:40:09 2002
@@ -424,6 +430,7 @@
CN("size-131072")
};
#undef CN
+static struct cache_sizes *malloc_hints[sizeof(size_t)*8];
struct arraycache_init initarray_cache __initdata = { { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
struct arraycache_init initarray_generic __initdata = { { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
@@ -587,6 +594,7 @@
void __init kmem_cache_init(void)
{
size_t left_over;
+ int i;
init_MUTEX(&cache_chain_sem);
INIT_LIST_HEAD(&cache_chain);
@@ -604,6 +612,18 @@
* that initializes ac_data for all new cpus
*/
register_cpu_notifier(&cpucache_notifier);
+
+ for (i=0;i<sizeof(size_t)*8;i++) {
+ struct cache_sizes *csizep = malloc_sizes;
+ int size = (1<<i)/2+1;
+
+ for ( ; csizep->cs_size; csizep++) {
+ if (size > csizep->cs_size)
+ continue;
+ break;
+ }
+ malloc_hints[i] = csizep;
+ }
}
@@ -1796,7 +1816,11 @@
*/
void * kmalloc (size_t size, int flags)
{
- struct cache_sizes *csizep = malloc_sizes;
+ struct cache_sizes *csizep;
+
+ if(unlikely(size<2))
+ size=2;
+ csizep = malloc_hints[fls((size-1))];
for (; csizep->cs_size; csizep++) {
if (size > csizep->cs_size)
next reply other threads:[~2002-10-26 19:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-26 19:22 Manfred Spraul [this message]
2002-10-26 22:30 ` Alan Cox
2002-10-27 10:08 ` Manfred Spraul
2002-10-27 13:29 ` Manfred Spraul
2002-10-28 13:05 ` Nikita Danilov
2002-10-28 13:18 ` Marcus Alanen
2002-10-28 13:26 ` Nikita Danilov
2002-10-28 16:03 ` Manfred Spraul
2002-10-31 9:35 ` Arjan van de Ven
2002-10-31 23:03 ` Manfred Spraul
[not found] <3DBAEB64.1090109@colorfullife.com.suse.lists.linux.kernel>
[not found] ` <1036056917.2872.0.camel@dhcp59-228.rdu.redhat.com.suse.lists.linux.kernel>
[not found] ` <3DC1B6D0.8050202@colorfullife.com.suse.lists.linux.kernel>
2002-11-01 8:03 ` Andi Kleen
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=3DBAEB64.1090109@colorfullife.com \
--to=manfred@colorfullife.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome