From: Steven Rostedt <rostedt@goodmis.org>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Luuk van der Duim <luukvanderduim@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
Manfred Spraul <manfred@colorfullife.com>,
Andrew Morton <akpm@osdl.org>
Subject: Re: [PATCH] micro optimization of cache_estimate in slab.c
Date: Sun, 18 Dec 2005 13:37:42 -0500 [thread overview]
Message-ID: <1134931062.13138.214.camel@localhost.localdomain> (raw)
In-Reply-To: <84144f020512180927lc6492abpb28c047f9e0c535c@mail.gmail.com>
On Sun, 2005-12-18 at 19:27 +0200, Pekka Enberg wrote:
> Hi Steven,
>
> On 12/18/05, Steven Rostedt <rostedt@goodmis.org> wrote:
> > + do {
> > + x = 1;
> > + while ((x+i)*size + ALIGN(base+(x+i)*extra, align) <= wastage)
> > + x <<= 1;
> > + i += (x >> 1);
> > + } while (x > 1);
>
> The above is pretty hard to read. Perhaps we could give x and i better
> names? Also, couldn't we move left part of the expression into a
> separate static inline function for readability?
Actually, Luuk sent me this patch made by Balbir Singh that was done a
while ago.
extra = sizeof(kmem_bufctl_t);
}
- i = 0;
+ i = (wastage - base)/(size + extra);
while (i*size + L1_CACHE_ALIGN(base+i*extra) <= wastage)
i++;
- if (i > 0)
+ while (i*size + L1_CACHE_ALIGN(base+i*extra) > wastage)
i--;
This actually has a O(1) with a K=2. Analyzing this further, I've come
up with the below patch. This patch removes the need for the second
while, and adds a comment to why. The size is already calculated to be
no smaller than the alignment. So that the division will not return
something greater than 1 of what is needed. So the if (i > 0) after the
while is all that is needed. So this patch is O(1) K=1.
-- Steve
Index: linux-2.6.15-rc5/mm/slab.c
===================================================================
--- linux-2.6.15-rc5.orig/mm/slab.c 2005-12-16 16:24:09.000000000 -0500
+++ linux-2.6.15-rc5/mm/slab.c 2005-12-18 13:30:13.000000000 -0500
@@ -708,7 +708,14 @@
base = sizeof(struct slab);
extra = sizeof(kmem_bufctl_t);
}
- i = 0;
+ /*
+ * Divide the amount we have, by the amount we need for
+ * each object. Since the size is already calculated
+ * to be no less than the alignment, this result will
+ * not be any greater than 1 that we need, and this will
+ * be subtracted after the while loop.
+ */
+ i = (wastage - base)/(size + extra);
while (i*size + ALIGN(base+i*extra, align) <= wastage)
i++;
if (i > 0)
next prev parent reply other threads:[~2005-12-18 18:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-18 8:23 Steven Rostedt
2005-12-18 17:27 ` Pekka Enberg
2005-12-18 18:37 ` Steven Rostedt [this message]
2005-12-18 19:29 ` Luuk van der Duim
2005-12-19 7:43 ` Pekka J Enberg
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=1134931062.13138.214.camel@localhost.localdomain \
--to=rostedt@goodmis.org \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luukvanderduim@gmail.com \
--cc=manfred@colorfullife.com \
--cc=penberg@cs.helsinki.fi \
/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®