From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Zhen Lei <thunder.leizhen@huawei.com>, Waiman Long <longman@redhat.com>
Subject: [patch 17/25] debugobjects: Rework free_object_work()
Date: Mon, 7 Oct 2024 18:50:12 +0200 (CEST) [thread overview]
Message-ID: <20241007164914.015906394@linutronix.de> (raw)
In-Reply-To: 20241007163507.647617031@linutronix.de
Convert it to batch processing with intermediate helper functions. This
reduces the final changes for batch processing.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
lib/debugobjects.c | 80 +++++++++++++++++++++++++----------------------------
1 file changed, 38 insertions(+), 42 deletions(-)
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -35,7 +35,7 @@
* frequency of 10Hz and about 1024 objects for each freeing operation.
* So it is freeing at most 10k debug objects per second.
*/
-#define ODEBUG_FREE_WORK_MAX 1024
+#define ODEBUG_FREE_WORK_MAX (1024 / ODEBUG_BATCH_SIZE)
#define ODEBUG_FREE_WORK_DELAY DIV_ROUND_UP(HZ, 10)
struct debug_bucket {
@@ -158,6 +158,21 @@ static bool pool_move_batch(struct obj_p
return true;
}
+static bool pool_pop_batch(struct hlist_head *head, struct obj_pool *src)
+{
+ if (!src->cnt)
+ return false;
+
+ for (int i = 0; src->cnt && i < ODEBUG_BATCH_SIZE; i++) {
+ struct hlist_node *node = src->objects.first;
+
+ WRITE_ONCE(src->cnt, src->cnt - 1);
+ hlist_del(node);
+ hlist_add_head(node, head);
+ }
+ return true;
+}
+
static struct debug_obj *__alloc_object(struct hlist_head *list)
{
struct debug_obj *obj;
@@ -343,55 +358,36 @@ static struct debug_obj *alloc_object(vo
return obj;
}
-/*
- * workqueue function to free objects.
- *
- * To reduce contention on the global pool_lock, the actual freeing of
- * debug objects will be delayed if the pool_lock is busy.
- */
+/* workqueue function to free objects. */
static void free_obj_work(struct work_struct *work)
{
- struct debug_obj *obj;
- unsigned long flags;
- HLIST_HEAD(tofree);
+ bool free = true;
WRITE_ONCE(obj_freeing, false);
- if (!raw_spin_trylock_irqsave(&pool_lock, flags))
+
+ if (!pool_count(&pool_to_free))
return;
- if (pool_global.cnt >= pool_global.max_cnt)
- goto free_objs;
+ for (unsigned int cnt = 0; cnt < ODEBUG_FREE_WORK_MAX; cnt++) {
+ HLIST_HEAD(tofree);
- /*
- * The objs on the pool list might be allocated before the work is
- * run, so recheck if pool list it full or not, if not fill pool
- * list from the global free list. As it is likely that a workload
- * may be gearing up to use more and more objects, don't free any
- * of them until the next round.
- */
- while (pool_to_free.cnt && pool_global.cnt < pool_global.max_cnt) {
- obj = hlist_entry(pool_to_free.objects.first, typeof(*obj), node);
- hlist_del(&obj->node);
- hlist_add_head(&obj->node, &pool_global.objects);
- WRITE_ONCE(pool_to_free.cnt, pool_to_free.cnt - 1);
- WRITE_ONCE(pool_global.cnt, pool_global.cnt + 1);
- }
- raw_spin_unlock_irqrestore(&pool_lock, flags);
- return;
-
-free_objs:
- /*
- * Pool list is already full and there are still objs on the free
- * list. Move remaining free objs to a temporary list to free the
- * memory outside the pool_lock held region.
- */
- if (pool_to_free.cnt) {
- hlist_move_list(&pool_to_free.objects, &tofree);
- WRITE_ONCE(pool_to_free.cnt, 0);
+ /* Acquire and drop the lock for each batch */
+ scoped_guard(raw_spinlock_irqsave, &pool_lock) {
+ if (!pool_to_free.cnt)
+ return;
+
+ /* Refill the global pool if possible */
+ if (pool_move_batch(&pool_global, &pool_to_free)) {
+ /* Don't free as there seems to be demand */
+ free = false;
+ } else if (free) {
+ pool_pop_batch(&tofree, &pool_to_free);
+ } else {
+ return;
+ }
+ }
+ free_object_list(&tofree);
}
- raw_spin_unlock_irqrestore(&pool_lock, flags);
-
- free_object_list(&tofree);
}
static void __free_object(struct debug_obj *obj)
next prev parent reply other threads:[~2024-10-07 16:50 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 16:49 [patch 00/25] debugobjects: Rework object handling Thomas Gleixner
2024-10-07 16:49 ` [patch 01/25] debugobjects: Delete a piece of redundant code Thomas Gleixner
2024-10-07 16:49 ` [patch 02/25] debugobjects: Collect newly allocated objects in a list to reduce lock contention Thomas Gleixner
2024-10-07 16:49 ` [patch 03/25] debugobjects: Dont destroy kmem cache in init() Thomas Gleixner
2024-10-10 2:14 ` Leizhen (ThunderTown)
2024-10-10 11:46 ` Thomas Gleixner
2024-10-10 13:31 ` Leizhen (ThunderTown)
2024-10-11 20:37 ` Thomas Gleixner
2024-10-12 1:50 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:49 ` [patch 04/25] debugobjects: Remove pointless hlist initialization Thomas Gleixner
2024-10-10 2:19 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:49 ` [patch 05/25] debugobjects: Dont free objects directly on CPU hotplug Thomas Gleixner
2024-10-10 2:33 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:49 ` [patch 06/25] debugobjects: Reuse put_objects() on OOM Thomas Gleixner
2024-10-10 2:38 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:49 ` [patch 07/25] debugobjects: Remove pointless debug printk Thomas Gleixner
2024-10-10 2:44 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 08/25] debugobjects: Provide and use free_object_list() Thomas Gleixner
2024-10-10 2:54 ` Leizhen (ThunderTown)
2024-10-11 20:40 ` Thomas Gleixner
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 09/25] debugobjects: Make debug_objects_enabled bool Thomas Gleixner
2024-10-10 3:00 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 10/25] debugobjects: Reduce parallel pool fill attempts Thomas Gleixner
2024-10-07 16:50 ` [patch 11/25] debugobjects: Move pools into a datastructure Thomas Gleixner
2024-10-10 3:47 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 12/25] debugobjects: Use separate list head for boot pool Thomas Gleixner
2024-10-10 4:04 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 13/25] debugobjects: Rename and tidy up per CPU pools Thomas Gleixner
2024-10-10 6:23 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 14/25] debugobjects: Move min/max count into pool struct Thomas Gleixner
2024-10-10 6:26 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 15/25] debugobjects: Rework object allocation Thomas Gleixner
2024-10-10 6:39 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 16/25] debugobjects: Rework object freeing Thomas Gleixner
2024-10-10 7:39 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` Thomas Gleixner [this message]
2024-10-10 8:10 ` [patch 17/25] debugobjects: Rework free_object_work() Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 18/25] debugobjects: Use static key for boot pool selection Thomas Gleixner
2024-10-10 8:12 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 19/25] debugobjects: Prepare for batching Thomas Gleixner
2024-10-10 8:15 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 20/25] debugobjects: Prepare kmem_cache allocations " Thomas Gleixner
2024-10-10 8:40 ` Leizhen (ThunderTown)
2024-10-11 20:47 ` Thomas Gleixner
2024-10-12 2:02 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 21/25] debugobjects: Implement batch processing Thomas Gleixner
2024-10-10 9:39 ` Leizhen (ThunderTown)
2024-10-11 20:48 ` Thomas Gleixner
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 22/25] debugobjects: Move pool statistics into global_pool struct Thomas Gleixner
2024-10-10 9:50 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 23/25] debugobjects: Double the per CPU slots Thomas Gleixner
2024-10-10 9:51 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 24/25] debugobjects: Refill per CPU pool more agressively Thomas Gleixner
2024-10-10 10:02 ` Leizhen (ThunderTown)
2024-10-11 20:49 ` Thomas Gleixner
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2024-10-07 16:50 ` [patch 25/25] debugobjects: Track object usage to avoid premature freeing of objects Thomas Gleixner
2024-10-10 13:13 ` Leizhen (ThunderTown)
2024-10-13 18:45 ` Thomas Gleixner
2024-10-14 1:46 ` Leizhen (ThunderTown)
2024-10-15 15:36 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
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=20241007164914.015906394@linutronix.de \
--to=tglx@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=thunder.leizhen@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.