From: Hui Su <sh_def@163.com>
To: ryabinin.a.a@gmail.com, akpm@linux-foundation.org,
kasan-dev@googlegroups.com, linux-mm@kvack.org
Cc: glider@google.com, andreyknvl@gmail.com, dvyukov@google.com,
vincenzo.frascino@arm.com, linux-kernel@vger.kernel.org,
Hui Su <sh_def@163.com>
Subject: [PATCH] kasan: avoid unnecessary quarantine lock cycling
Date: Sun, 9 Aug 2026 03:12:31 +0800 [thread overview]
Message-ID: <20260808191230.3345930-2-sh_def@163.com> (raw)
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
reply other threads:[~2026-08-08 19:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260808191230.3345930-2-sh_def@163.com \
--to=sh_def@163.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryabinin.a.a@gmail.com \
--cc=vincenzo.frascino@arm.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