From nobody Tue Sep 29 10:32:55 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42B0C340282 for ; Sat, 8 Aug 2026 19:14:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786216476; cv=none; b=K+Bq3+Jp7FvIL5oK8ko0kx2PoVwiCXBma/Cng3+rLQ5OXuqtSvjXv3Mcx501u1FLximndy2nNEVpHsytDlZ+Jzf57/MnT1lXO5oXSJ4bzEthzDiVwEXt8VperXolQ4b8vmV/LXa5EWx52+sCppLnRSaa436oVihamY72E2IkWz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786216476; c=relaxed/simple; bh=rmewHwKU0RLxMyg7HvVYt1LyE/Q/dMQa06RVJH5tDTg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=heOuFCw4WrUxNjHlcOhtjOJA/KuU80DxQvRArHAcHGcAKHYaTOA+Bn1gMk01FE4Kvtzc/10Bv+MGO14TOjsN8BcDsvrGYafQvyPqppg1N0BuTpCZIs0GCXSwooEsoPAUlh/r2T8reRRcP5kebVn7EfKjz/RdyQ3hxO7+DJWJ4mQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ZId1PKDH; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ZId1PKDH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=q/ Nn9N+TcF5PSILtONXCcDZuOZOA8yQM5ZlkYu6kinQ=; b=ZId1PKDHgexHLjjuoQ o9I5FEqqw/GttmS2S7MbHCGhYiGa32jLpGOHhRRhG6s3Lfu73NuEUPuVN18ls65J e6rCu8xpwlGnzqJ44F/lMcLCrQWB8ucdlgVPVOn5Vtd4aoHgeg+1wFUtgsepVkLC CrlKv/a2ZPZBlM9fRy4LSQD3s= Received: from localhost (unknown []) by gzsmtp3 (Coremail) with SMTP id PigvCgAXJfzaf3dqWP05MA--.26752S2; Sun, 09 Aug 2026 03:13:31 +0800 (CST) From: Hui Su 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 Subject: [PATCH] kasan: avoid unnecessary quarantine lock cycling Date: Sun, 9 Aug 2026 03:12:31 +0800 Message-ID: <20260808191230.3345930-2-sh_def@163.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PigvCgAXJfzaf3dqWP05MA--.26752S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZrWDXw47uw45ZrW5try8uFg_yoW8XryDpF 9xJFy3Gw18Z348Xr4UZF15Wr1fXa93Ka4DA3y8Gws3AF15W3W2gryFyF9Fvr4jvr4SvFn0 v3W5J340kr1jyw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piH5l8UUUUU= X-CM-SenderInfo: xvkbvvri6rljoofrz/xtbC6RuO7Wp3f9tdFwAA3i Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Hui Su --- 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); =20 --=20 2.43.0