Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kasan: avoid unnecessary quarantine lock cycling
@ 2026-08-08 19:12 Hui Su
  0 siblings, 0 replies; only message in thread
From: Hui Su @ 2026-08-08 19:12 UTC (permalink / raw)
  To: ryabinin.a.a, akpm, kasan-dev, linux-mm
  Cc: glider, andreyknvl, dvyukov, vincenzo.frascino, linux-kernel,
	Hui Su

kasan_quarantine_remove_cache() drops quarantine_lock and restores
interrupts after scanning each non-empty quarantine batch so that
cond_resched() can schedule during a long scan.

When no reschedule is pending, the unlock/IRQ restore and subsequent
IRQ save/relock cycle is unnecessary.

Check need_resched() before cycling quarantine_lock to avoid this
overhead when rescheduling is not needed.

Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Hui Su <sh_def@163.com>
---
 mm/kasan/quarantine.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c
index 6958aa713c67..db7170f6f1b2 100644
--- a/mm/kasan/quarantine.c
+++ b/mm/kasan/quarantine.c
@@ -368,10 +368,12 @@ void kasan_quarantine_remove_cache(struct kmem_cache *cache)
 		if (qlist_empty(&global_quarantine[i]))
 			continue;
 		qlist_move_cache(&global_quarantine[i], &to_free, cache);
-		/* Scanning whole quarantine can take a while. */
-		raw_spin_unlock_irqrestore(&quarantine_lock, flags);
-		cond_resched();
-		raw_spin_lock_irqsave(&quarantine_lock, flags);
+		if (need_resched()) {
+			/* Scanning whole quarantine can take a while. */
+			raw_spin_unlock_irqrestore(&quarantine_lock, flags);
+			cond_resched();
+			raw_spin_lock_irqsave(&quarantine_lock, flags);
+		}
 	}
 	raw_spin_unlock_irqrestore(&quarantine_lock, flags);
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-08 19:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-08 19:12 [PATCH] kasan: avoid unnecessary quarantine lock cycling Hui Su

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox