git: 910535a82a29 - stable/13 - uma: Avoid excessive per-CPU draining
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 31 Mar 2025 18:35:52 UTC
The branch stable/13 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=910535a82a29d71eb3951b2368aef358a207f18d
commit 910535a82a29d71eb3951b2368aef358a207f18d
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-03-17 19:12:58 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-03-31 18:36:01 +0000
uma: Avoid excessive per-CPU draining
After commit 389a3fa693ef, uma_reclaim_domain(UMA_RECLAIM_DRAIN_CPU)
calls uma_zone_reclaim_domain(UMA_RECLAIM_DRAIN_CPU) twice on each zone
in addition to globally draining per-CPU caches. This was unintended
and is unnecessarily slow; in particular, draining per-CPU caches
requires binding to each CPU.
Stop draining per-CPU caches when visiting each zone, just do it once in
pcpu_cache_drain_safe() to minimize the amount of expensive sched_bind()
calls.
Fixes: 389a3fa693ef ("uma: Add UMA_ZONE_UNMANAGED")
MFC after: 1 week
Sponsored by: Klara, Inc.
Sponsored by: NetApp, Inc.
Reviewed by: gallatin, kib
Differential Revision: https://reviews.freebsd.org/D49349
(cherry picked from commit f506d5af50fccc37f5aa9fe090e9a0d5f05506c8)
---
sys/vm/uma_core.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c
index 2236df90dfc0..7334db2a9bbd 100644
--- a/sys/vm/uma_core.c
+++ b/sys/vm/uma_core.c
@@ -5198,6 +5198,13 @@ uma_reclaim_domain(int req, int domain)
zone_foreach(uma_reclaim_domain_cb, &args);
break;
case UMA_RECLAIM_DRAIN_CPU:
+ /*
+ * Reclaim globally visible free items from all zones, then drain
+ * per-CPU buckets, then reclaim items freed while draining.
+ * This approach minimizes expensive context switching needed to
+ * drain each zone's per-CPU buckets.
+ */
+ args.req = UMA_RECLAIM_DRAIN;
zone_foreach(uma_reclaim_domain_cb, &args);
pcpu_cache_drain_safe(NULL);
zone_foreach(uma_reclaim_domain_cb, &args);