From: Thomas Gleixner <tglx@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
tglx@linutronix.de
Subject: [tip:core/debugobjects] debugobjects: delay free of internal objects
Date: Tue, 17 Mar 2009 11:30:31 GMT [thread overview]
Message-ID: <tip-337fff8b5ed0573ea106491c6de47bd7fe623500@git.kernel.org> (raw)
In-Reply-To: <200903162049.58058.nickpiggin@yahoo.com.au>
Commit-ID: 337fff8b5ed0573ea106491c6de47bd7fe623500
Gitweb: http://git.kernel.org/tip/337fff8b5ed0573ea106491c6de47bd7fe623500
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Mon, 16 Mar 2009 10:04:53 +0100
Commit: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 17 Mar 2009 12:28:30 +0100
debugobjects: delay free of internal objects
Impact: avoid recursive kfree calls, less slab activity on heavy load
debugobjects checks on kfree whether tracked objects are freed. When a
tracked object is freed debugobjects frees the internal reference
object as well. The debug object slab cache is marked to not recurse
into debugobjects when a slab objects is freed, but the recursive call
can be problematic versus locking in the memory allocator.
Defer the freeing of debug slab objects via schedule_work. The reasons
not to use RCU are:
1) rcu makes the data structure larger
2) there is no real need for rcu as nothing references the obj after
we freed it
3) under heavy load it is easier to reuse the to be freed objects instead
of allocating new objects from the slab. This lowered the slab activity
significantly in a heavy load networking test where lots of timers are
created/destroyed. The workqueue based delayed free allows us just to
put the to be freed objects back into the object pool and reuse them
right away.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
LKML-Reference: <200903162049.58058.nickpiggin@yahoo.com.au>
---
lib/debugobjects.c | 53 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index fdcda3d..2755a3b 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -50,6 +50,9 @@ static int debug_objects_enabled __read_mostly
static struct debug_obj_descr *descr_test __read_mostly;
+static void free_obj_work(struct work_struct *work);
+static DECLARE_WORK(debug_obj_work, free_obj_work);
+
static int __init enable_object_debug(char *str)
{
debug_objects_enabled = 1;
@@ -154,25 +157,51 @@ alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr)
}
/*
- * Put the object back into the pool or give it back to kmem_cache:
+ * workqueue function to free objects.
*/
-static void free_object(struct debug_obj *obj)
+static void free_obj_work(struct work_struct *work)
{
- unsigned long idx = (unsigned long)(obj - obj_static_pool);
+ struct debug_obj *obj;
unsigned long flags;
- if (obj_pool_free < ODEBUG_POOL_SIZE || idx < ODEBUG_POOL_SIZE) {
- spin_lock_irqsave(&pool_lock, flags);
- hlist_add_head(&obj->node, &obj_pool);
- obj_pool_free++;
- obj_pool_used--;
- spin_unlock_irqrestore(&pool_lock, flags);
- } else {
- spin_lock_irqsave(&pool_lock, flags);
- obj_pool_used--;
+ spin_lock_irqsave(&pool_lock, flags);
+ while (obj_pool_free > ODEBUG_POOL_SIZE) {
+ obj = hlist_entry(obj_pool.first, typeof(*obj), node);
+ hlist_del(&obj->node);
+ obj_pool_free--;
+ /*
+ * We release pool_lock across kmem_cache_free() to
+ * avoid contention on pool_lock.
+ */
spin_unlock_irqrestore(&pool_lock, flags);
kmem_cache_free(obj_cache, obj);
+ spin_lock_irqsave(&pool_lock, flags);
}
+ spin_unlock_irqrestore(&pool_lock, flags);
+}
+
+/*
+ * Put the object back into the pool and schedule work to free objects
+ * if necessary.
+ */
+static void free_object(struct debug_obj *obj)
+{
+ unsigned long flags;
+ int sched = 0;
+
+ spin_lock_irqsave(&pool_lock, flags);
+ /*
+ * schedule work when the pool is filled and the cache is
+ * initialized:
+ */
+ if (obj_pool_free > ODEBUG_POOL_SIZE && obj_cache)
+ sched = !work_pending(&debug_obj_work);
+ hlist_add_head(&obj->node, &obj_pool);
+ obj_pool_free++;
+ obj_pool_used--;
+ spin_unlock_irqrestore(&pool_lock, flags);
+ if (sched)
+ schedule_work(&debug_obj_work);
}
/*
next prev parent reply other threads:[~2009-03-17 11:31 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-28 13:53 [PATCH 00/21] lockdep: pending queue Peter Zijlstra
2009-01-28 13:53 ` [PATCH 01/21] lockdep: annotate reclaim context (__GFP_NOFS) Peter Zijlstra
[not found] ` <tip-bf722c9d324864b4256edaa330751b77f2a19861@git.kernel.org>
2009-03-15 6:48 ` SLOB lockup (was: Re: [tip:core/locking] lockdep: annotate reclaim context (__GFP_NOFS), fix SLOB) Ingo Molnar
2009-03-15 6:51 ` Ingo Molnar
2009-03-15 9:06 ` Nick Piggin
2009-03-15 9:47 ` Ingo Molnar
2009-03-15 10:04 ` Nick Piggin
2009-03-15 15:16 ` Thomas Gleixner
2009-03-16 9:49 ` Nick Piggin
2009-03-17 11:30 ` [tip:core/debugobjects] debugobjects: replace static objects when slab cache becomes available Thomas Gleixner
2009-03-17 11:30 ` Thomas Gleixner [this message]
2009-03-15 14:56 ` SLOB lockup (was: Re: [tip:core/locking] lockdep: annotate reclaim context (__GFP_NOFS), fix SLOB) Matt Mackall
2009-03-16 10:00 ` Nick Piggin
2009-03-16 14:52 ` Matt Mackall
2009-03-16 15:00 ` Nick Piggin
2009-03-23 8:42 ` Pekka Enberg
2009-03-15 18:56 ` Ingo Molnar
2009-01-28 13:53 ` [PATCH 02/21] lockdep: sanitize bit names Peter Zijlstra
2009-01-28 13:53 ` [PATCH 03/21] lockdep: sanitize reclaim " Peter Zijlstra
2009-01-28 13:53 ` [PATCH 04/21] lockdep: lockdep_states.h Peter Zijlstra
2009-01-28 13:53 ` [PATCH 05/21] lockdep: simplify mark_held_locks Peter Zijlstra
2009-01-28 13:53 ` [PATCH 06/21] lockdep: simplify mark_lock() Peter Zijlstra
2009-01-28 13:53 ` [PATCH 07/21] lockdep: move state bit definitions around Peter Zijlstra
2009-01-28 13:54 ` [PATCH 08/21] lockdep: generate the state bit definitions Peter Zijlstra
2009-01-28 13:54 ` [PATCH 09/21] lockdep: generate usage strings Peter Zijlstra
2009-01-28 13:54 ` [PATCH 10/21] lockdep: split up mark_lock_irq() Peter Zijlstra
2009-01-28 13:54 ` [PATCH 11/21] lockdep: simplify the mark_lock_irq() helpers Peter Zijlstra
2009-01-28 13:54 ` [PATCH 12/21] lockdep: further simplify " Peter Zijlstra
2009-01-28 13:54 ` [PATCH 13/21] lockdep: simplify mark_lock_irq() helpers #3 Peter Zijlstra
2009-01-28 13:54 ` [PATCH 14/21] lockdep: merge the _READ mark_lock_irq() helpers Peter Zijlstra
2009-01-28 13:54 ` [PATCH 15/21] lockdep: merge the !_READ " Peter Zijlstra
2009-01-28 13:54 ` [PATCH 16/21] lockdep: fully reduce mark_lock_irq() Peter Zijlstra
2009-01-28 13:54 ` [PATCH 17/21] lockdep: remove macro usage from mark_held_locks() Peter Zijlstra
2009-01-28 13:54 ` [PATCH 18/21] lockdep: add comments to mark_lock_irq() Peter Zijlstra
2009-01-28 13:54 ` [PATCH 19/21] lockdep: simplify get_user_chars() Peter Zijlstra
2009-01-28 13:54 ` [PATCH 20/21] lockdep: get_user_chars() redo Peter Zijlstra
2009-01-28 13:54 ` [PATCH 21/21] lockdep: simplify check_prev_add_irq() Peter Zijlstra
2009-01-29 13:54 ` [PATCH 22/21] lockdep: use stringify.h Peter Zijlstra
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=tip-337fff8b5ed0573ea106491c6de47bd7fe623500@git.kernel.org \
--to=tglx@linutronix.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@redhat.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