From: Matthew Dobson <colpatch@us.ibm.com>
To: kernel-janitors@lists.osdl.org
Cc: manfred@colorfullife.com, Pekka J Enberg <penberg@cs.Helsinki.FI>,
linux-kernel@vger.kernel.org
Subject: [PATCH 7/9] Cleanup cache_reap()
Date: Thu, 10 Nov 2005 16:05:19 -0800 [thread overview]
Message-ID: <4373E03F.6060302@us.ibm.com> (raw)
In-Reply-To: <4373DD82.8010606@us.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 82 bytes --]
cache_reap() could also use a little love. Here's a patch to clean it up.
-Matt
[-- Attachment #2: cache_reap.patch --]
[-- Type: text/x-patch, Size: 2684 bytes --]
General readability fixes.
* Goto to end of function instead of duplicating code in case of
failure to grab cache_chain_sem.
* Replace a list_for_each/list_entry combo with an identical but
more readable list_for_each_entry loop.
* Move the declaration of a variables not referenced outside of
certain loops inside those loops.
* Store the numa_node_id() in a local variable.
Signed-off-by: Matthew Dobson <colpatch@us.ibm.com>
Index: linux-2.6.14+slab_cleanup/mm/slab.c
===================================================================
--- linux-2.6.14+slab_cleanup.orig/mm/slab.c 2005-11-10 11:48:47.540627688 -0800
+++ linux-2.6.14+slab_cleanup/mm/slab.c 2005-11-10 11:48:49.384347400 -0800
@@ -3302,45 +3302,32 @@ static void drain_array_locked(kmem_cach
*/
static void cache_reap(void *unused)
{
- struct list_head *walk;
- struct kmem_list3 *l3;
-
- if (down_trylock(&cache_chain_sem)) {
- /* Give up. Setup the next iteration. */
- schedule_delayed_work(&__get_cpu_var(reap_work),
- REAPTIMEOUT_CPUC + smp_processor_id());
- return;
- }
+ kmem_cache_t *searchp;
- list_for_each(walk, &cache_chain) {
- kmem_cache_t *searchp;
- struct list_head* p;
- int tofree;
- struct slab *slabp;
+ if (down_trylock(&cache_chain_sem))
+ goto out;
- searchp = list_entry(walk, kmem_cache_t, next);
+ list_for_each_entry(searchp, &cache_chain, next) {
+ struct kmem_list3 *l3;
+ int tofree, nid = numa_node_id();
if (searchp->flags & SLAB_NO_REAP)
goto next;
check_irq_on();
-
- l3 = searchp->nodelists[numa_node_id()];
+ l3 = searchp->nodelists[nid];
if (l3->alien)
drain_alien_cache(searchp, l3);
spin_lock_irq(&l3->list_lock);
- drain_array_locked(searchp, ac_data(searchp), 0,
- numa_node_id());
+ drain_array_locked(searchp, ac_data(searchp), 0, nid);
if (time_after(l3->next_reap, jiffies))
goto next_unlock;
-
l3->next_reap = jiffies + REAPTIMEOUT_LIST3;
if (l3->shared)
- drain_array_locked(searchp, l3->shared, 0,
- numa_node_id());
+ drain_array_locked(searchp, l3->shared, 0, nid);
if (l3->free_touched) {
l3->free_touched = 0;
@@ -3350,7 +3337,9 @@ static void cache_reap(void *unused)
tofree = 5 * searchp->num;
tofree = (l3->free_limit + tofree - 1) / tofree;
do {
- p = l3->slabs_free.next;
+ struct list_head *p = l3->slabs_free.next;
+ struct slab *slabp;
+
if (p == &(l3->slabs_free))
break;
@@ -3377,6 +3366,7 @@ next:
check_irq_on();
up(&cache_chain_sem);
drain_remote_pages();
+out:
/* Setup the next iteration */
schedule_delayed_work(&__get_cpu_var(reap_work),
REAPTIMEOUT_CPUC + smp_processor_id());
next prev parent reply other threads:[~2005-11-11 0:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-10 23:53 [PATCH 0/9] Cleanup mm/slab.c v2 Matthew Dobson
2005-11-10 23:56 ` [PATCH 1/9] CodingStyle-ify mm/slab.c Matthew Dobson
2005-11-10 23:58 ` [PATCH 2/9] Use 'nid' Matthew Dobson
2005-11-13 20:15 ` Pavel Machek
2005-11-10 23:59 ` [PATCH 3/9] Fix alloc_percpu's args Matthew Dobson
2005-11-11 0:01 ` [PATCH 4/9] Create helper for /proc/slabinfo Matthew Dobson
2005-11-11 0:03 ` [PATCH 5/9] Create helper for kmem_cache_create() Matthew Dobson
2005-11-11 0:04 ` [PATCH 6/9] Cleanup kmem_cache_create() Matthew Dobson
2005-11-11 8:10 ` Ingo Oeser
2005-11-11 18:28 ` Matthew Dobson
2005-11-11 0:05 ` Matthew Dobson [this message]
2005-11-11 0:06 ` [PATCH 8/9] Cleanup slabinfo_write() Matthew Dobson
2005-11-11 0:07 ` [PATCH 9/9] Cleanup a loop in set_slab_attr() Matthew Dobson
2005-11-11 7:29 ` [PATCH 0/9] Cleanup mm/slab.c v2 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=4373E03F.6060302@us.ibm.com \
--to=colpatch@us.ibm.com \
--cc=kernel-janitors@lists.osdl.org \
--cc=linux-kernel@vger.kernel.org \
--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