From nobody Sat Jul 25 22:02:59 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D30803D9549 for ; Mon, 13 Jul 2026 10:22:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783938161; cv=none; b=Qn6Xewl0Gv3zk4/5LPfJQq/lRrTcHwrwEn/okuUBzSS+mOhPQ0LDfrPg5FCI9XNlak2jq/5VmZQAcdOYoqR7cWSR4zMOL3ygKjpMJ9f3JSJt8+9iwl07ilxBc7/Qd+FloI7JyaSrhf/R/aOUVq6i517vvCCfLAaYr7VwEQ9bhTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783938161; c=relaxed/simple; bh=S0apE44jg4thzwLs2H4ktkq49NTNQCRu8dBmqyqkmPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EE4A4uZKgzz5fX+OBP9P3/iJ6oPlCxOlp3419vJvXhYGBLjOCj0r8mOcPV9d1YtpB6hXUi8DTl9bGbQGRRU6X1vP2uqDNJiRTZkZMzYwT1ZSLsrnHPIMBLh5AtT2KTW1ByLd3pGvDRqTbuzZIB80y1JMZbIaz5jjMgjODMzlieM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=JPH7XAer; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="JPH7XAer" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-47f3b39f2a1so869702f8f.2 for ; Mon, 13 Jul 2026 03:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1783938156; x=1784542956; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=d9qPFT2w9NJfNkCDFx/9oMKsPCaLSc0nA2j4Q4SrUdM=; b=JPH7XAerNSnuSOAfQUJJqz1Q1b3tAESXIXh+94UkDqA0kZ+spQdux8lkZHJhjQRFRH e8DVf5i9AWFFbrCGy5BYKvqS+FNXbGL4mSY3AgWX2NWx5ZoxXgPdVzLCuuFJJR2bDtPi mU1jnnXbCv3++vY/UkBJ2Y/JwI5gcdAzOvsIxleSBk4G5wJpunQWFIdekWgwYwjShAOe Twf4rmdWRBx1lETml+MAFp9cghIYaZb2flgeGcb1LFqorPcCy1BdkhUl3E4bEvDfWuJ3 F5bWYNdejlq679WHyv4Tk7tFbOwEiQUZ862kTDXmz/9hPFSTifibnsrSiBSdc2Hh5Sgz VgRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783938156; x=1784542956; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=d9qPFT2w9NJfNkCDFx/9oMKsPCaLSc0nA2j4Q4SrUdM=; b=CrYgpk/ke9VP8B+ci9+2Y8qlJFVjBte7I9Kc1P70bnbZQqsnlKN8XjUnlMZdGTDZNZ oAnJQNEXA58kHwB+GRJauJ8X+6iGVDPsNW/uA0XwTn3a1uKWZfQKeKjN6K/5iXTu45Xu MKoX+WOfWeGHgD/q584udXGDzYAIBUntWRdzvSIKG+jG7nVyQbkK69QqiWooAU+uf5+W RJ3EUJNZvNEOXmU6rT8lEnCmDI3RPGJU2td+22UJujz5TCgnIg0PKmp140EZxzQGi6yO mzyyCn/ylnyb0jOJsgDW4scqvdsHcPNUroqBP/lVb05c2sm57gYDMzX45Q+gapBNnZab 9jUw== X-Forwarded-Encrypted: i=1; AHgh+Rrpf/d3mhW3jpOXnPwWZerL2fOLaZxsjhbEtv23dl/LsocKoeTiHB2eVfhxnl4aw7qULeqpguYXZCiz7J0=@vger.kernel.org X-Gm-Message-State: AOJu0Yyu2c0r7RlRhNs8T2nh9kW3TtO+HrojoPjens3kyw/Ku4hlbLgf NtIh9kMhun3s803VPZ0FVZ2pWjaFpqIzkjoxjLqEaR8Cso6rkXMDx0CcCY2CL1lrbl2tJTSioot GRlkvLL4= X-Gm-Gg: AfdE7clH6MRGpwyT/4mGcErK9hql0giOs/iNeh/dY4KOAQBcPkO9c/hxJxfsyEvpxFy gBsbH0AfByEdLubvRJjKJMsbY+sPgH98GjL+kvUEdPyv+l2jxnNBVvWVFHz9nSJWSyrVZtRrYhb ySGrT/QqA/Db8XjkfGWYjtB1wtErxCTtaD5fe8rhY9nb26PPnD4F7JpWJNn/HXFBOJh8gwqFXDL mT6vDbW7PlPTK29+6ZoyGNStDJRu3cMkQK7VPUhPhaHE04yH09Zd7/oFJh9m+Kd0TyiQLkZPLsj sTDnYnWZ4UqdcMGNd+2XNE+IldGeK2O61GGI1TESmXWHknKN85AeJVZYBLR+3YnaGrJCxwK6hs/ 9dJPZlogwColQjucjTsiTaKiFobI3X+qB7eIYpQ6BZ1cDbxWlDrloasvwAHwfb4NTJ2O9/fnKnc uaY1z+KBKdc6bZdcFzZca328P2S54ozB8qqGI7sFO8nCkCPHTGHAqkT3Vp6dobePaeZyFgGlsIC +urgShAkJB9wCm0NfitAnxRQE0= X-Received: by 2002:a5d:6f0a:0:b0:47f:250f:71fc with SMTP id ffacd0b85a97d-47f2dd139c2mr10176696f8f.54.1783938156185; Mon, 13 Jul 2026 03:22:36 -0700 (PDT) Received: from raven.intern.cm-ag (p200300dc6f484700023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f48:4700:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa09608d4sm84858344f8f.25.2026.07.13.03.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 03:22:35 -0700 (PDT) From: Max Kellermann To: tytso@mit.edu, jack@suse.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Max Kellermann , stable@vger.kernel.org Subject: [PATCH 1/2] jbd2: check need_resched() when skipping busy checkpoint buffers Date: Mon, 13 Jul 2026 12:22:28 +0200 Message-ID: <20260713102229.1598812-2-max.kellermann@ionos.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713102229.1598812-1-max.kellermann@ionos.com> References: <20260713102229.1598812-1-max.kellermann@ionos.com> 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 Content-Type: text/plain; charset="utf-8" journal_shrink_one_cp_list() skips busy checkpoint buffers when called with JBD2_SHRINK_BUSY_SKIP. The continue statement on this path also skips the need_resched() check at the end of the loop body. Consequently, when a checkpoint list contains mostly busy buffers, the shrinker can walk the entire list while holding journal->j_list_lock, even when a reschedule has been requested. Large checkpoint lists under memory pressure can therefore cause long lock hold times and leave other CPUs spinning on j_list_lock, resulting in soft lockups or RCU stalls. Route the busy-buffer path through the need_resched() check so that the shrinker can release j_list_lock and reschedule promptly, restoring parity with the clean-buffer path, which already checks need_resched(). This does not change which checkpoint buffers are eligible for removal. Fixes: b98dba273a0e ("jbd2: remove journal_clean_one_cp_list()") Cc: stable@vger.kernel.org Signed-off-by: Max Kellermann Reviewed-by: Jan Kara Reviewed-by: Zhang Yi --- fs/jbd2/checkpoint.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c index 1508e2f54462..5266017565ac 100644 --- a/fs/jbd2/checkpoint.c +++ b/fs/jbd2/checkpoint.c @@ -389,7 +389,7 @@ static unsigned long journal_shrink_one_cp_list(struct = journal_head *jh, ret =3D jbd2_journal_try_remove_checkpoint(jh); if (ret < 0) { if (type =3D=3D JBD2_SHRINK_BUSY_SKIP) - continue; + goto next; break; } } @@ -400,6 +400,7 @@ static unsigned long journal_shrink_one_cp_list(struct = journal_head *jh, break; } =20 +next: if (need_resched()) break; } while (jh !=3D last_jh); --=20 2.47.3 From nobody Sat Jul 25 22:02:59 2026 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C0313E4504 for ; Mon, 13 Jul 2026 10:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783938160; cv=none; b=mxn735Y8eRgBk/0OqMboy5GLOjuAxz1axt0gfSzUza6wfZ/TC26yXaYM5tp09uLEQbfQSEuZu49ZN/JnCyRT2b48PiOZoTQNG/nkFDGMf46pUyDpILSuBjudWdhJrGs5chvJR3JDKiA2NFNzD0JadcMDu7xpz2NsaEoOn7TL4XY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783938160; c=relaxed/simple; bh=9fvUIivmZtSZeqhsriqjOUYwnTIOxzDzZNMxJw1Icx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FTVgEFweoQeDHs3/zzLCAt80h+WCk8BU8zuicXPK/OhlotAy84Pw8RWrlpp7hatLlAf+H7IEE1638zYXHxDSZIw7/fzRYzniZGeZh5MF4AcOQEorW5mKtIxT0+JywgvhLTaIRR0u/IjfRQA1/KsIZ+z5g2yDoWhCsd2zd3549y4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=hSjWmLei; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="hSjWmLei" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-47122683cf3so1586490f8f.0 for ; Mon, 13 Jul 2026 03:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1783938158; x=1784542958; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BqAzbIa03EEwzYHiTtc0EGAOtlFJgcTmBpG0VFTldcE=; b=hSjWmLei+vEEXiGvSF6MKPQ5rztV4dZbdHQ5vuz6E2uZGStiMuyfsW55ofVcyABPHR Pymx7NlEe5BHrNQrHZQ9G4v9vZqJIBVAr6JwQBWp8c3O1efeUvLbzs2yL4vszBcBSt4P D5kCSK+iRJXz7hJk03DiB6nYvYic4KfIoRTapxI8ryUcO+LwCo6lIa236F8JcJuc9w8h R8p4MCKkOeaJUqDHOgyVu0Jj7iTrY/97joHgAR9dmYvDnXvzosfdRyFAmCiej9nM1ces SATv9fjzd+eojNGJgzupeA1LnB8hAMxRNNwZcnCtLAYezVSTVCSfQuqvaOzSmtebGs4F h3YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783938158; x=1784542958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=BqAzbIa03EEwzYHiTtc0EGAOtlFJgcTmBpG0VFTldcE=; b=T2oLM3/aFlKRN3uIwiRMi0cMPHoVzcFYDYFGh335sXVkimsHHtBF0hf45dUlUY70Pu JNnVhDKd/UXfuFBGSUiYnQpnbhPj7KfnxXpZ99HU/gibZLjYQC7gMA6K9f06iAyzixke YKdF1p5IUdpK4YPleid8O6Hl9GxIuauiR4UiPkKwoNwXOY5ZAsQqv3Gjn8ynPWtiyiLk NE6GUaCx0xgewz8+NoGmjQXDj2V2iNqGF4NzkzBDeub7mTbeOT1FLaQZRPGS6micplyJ 9PPLnnDH9GNljM5SKvqJYB5yho0cBA9RqIYQ64GxJQgnpCZNEKxTL5EADtuheylvNi42 CSAQ== X-Forwarded-Encrypted: i=1; AHgh+Rp/Zdc12tfy8hKRiNwiI3MNfMx4cVeJcr4ILg10SSPwaey967tbRshvdfALNw2kTWX6R1TVMP6/bYc32Co=@vger.kernel.org X-Gm-Message-State: AOJu0YwY3MiGxLkX8ax8zfe/qlNYGvAHTYmou7QPv+6aI+Oe/pWL1bSg VuEDONbKaUbll2vKtKitkMkUlLiaNNKzyEBNOSWpHKwdmfPeTF0OPy3TfL/7ZtmQIaU= X-Gm-Gg: AfdE7clHy+su61o3nWewDGGbhtu9oA+BdVvKHdOmvO+FrLh0q5drS3+8WJsFv4fAWAK YfBM43WbCqikRl8gWC0htDFa5HJ61jpsHyIEtiLZ2ySdwP10z/eZe/ifgCl5YdoqduB4nT7G3X8 7/mrwkqg8m8jdyJGvlWKd49y9Oh5g3DLZW4QYQzkDszMDCu15o7TwB2DVlmUH/pM/bw4M2eY6hZ +NDbwFzVteTwA9U5SSiXQ7REx1epQ63dy7VgGQr5EtYSTDxbI0vFL/UruR5iHc4JC1SQCVGc9MO KMlVTu60pRQBLXbUSXjNWAy4+/Jc7bFahD40IOC9jYZ3H5UPyjwSwVZ6WbA/PiUHZWYMNCaaL7o 430qtfH8qgmgmqs3LLNWzscQQUg75s/rQrGkUjfcaRC8ad8fKB04oEu6KgfJqnLqrCC52gt1R4h SO49n8Tk0y+nyAVa1+5UiPfFuxURvekSTSEm87N7N3jP1vy7UC0yHMG/UsbIpRZ9Kbwj7whEQMi d5jaiyNki6oUyg2 X-Received: by 2002:a05:6000:460f:b0:475:f0f0:9ef1 with SMTP id ffacd0b85a97d-47f2dd0d580mr8735399f8f.54.1783938157596; Mon, 13 Jul 2026 03:22:37 -0700 (PDT) Received: from raven.intern.cm-ag (p200300dc6f484700023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f48:4700:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa09608d4sm84858344f8f.25.2026.07.13.03.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 03:22:36 -0700 (PDT) From: Max Kellermann To: tytso@mit.edu, jack@suse.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Max Kellermann , stable@vger.kernel.org Subject: [PATCH 2/2] jbd2: bound shrinker scans by examined checkpoint buffers Date: Mon, 13 Jul 2026 12:22:29 +0200 Message-ID: <20260713102229.1598812-3-max.kellermann@ionos.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713102229.1598812-1-max.kellermann@ionos.com> References: <20260713102229.1598812-1-max.kellermann@ionos.com> 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 Content-Type: text/plain; charset="utf-8" The jbd2 shrinker currently accounts only checkpoint buffers that it successfully releases against nr_to_scan. Busy buffers therefore do not consume the scan budget. If a checkpoint transaction contains mostly busy buffers, the shrinker can scan its entire checkpoint list while holding journal->j_list_lock. Large checkpoint lists can result in excessive lock hold times and leave other CPUs spinning on j_list_lock, causing soft lockups or RCU stalls. Pass nr_to_scan into journal_shrink_one_cp_list() and decrement it for every buffer examined, including busy buffers. Pass NULL from checkpoint cleanup paths so their existing full-list behavior is preserved. This restores the scan-budget semantics that existed before journal_shrink_one_cp_list() was changed to always scan a complete checkpoint list. Fixes: b98dba273a0e ("jbd2: remove journal_clean_one_cp_list()") Cc: stable@vger.kernel.org Signed-off-by: Max Kellermann Reviewed-by: Jan Kara Reviewed-by: Zhang Yi --- fs/jbd2/checkpoint.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c index 5266017565ac..513273712010 100644 --- a/fs/jbd2/checkpoint.c +++ b/fs/jbd2/checkpoint.c @@ -358,15 +358,16 @@ int jbd2_cleanup_journal_tail(journal_t *journal) /* * journal_shrink_one_cp_list * - * Find all the written-back checkpoint buffers in the given list - * and try to release them. If the whole transaction is released, set - * the 'released' parameter. Return the number of released checkpointed - * buffers. + * Find written-back checkpoint buffers in the given list and try to relea= se + * them. If 'nr_to_scan' is set, scan at most that many buffers. If the wh= ole + * transaction is released, set the 'released' parameter. Return the numbe= r of + * released checkpointed buffers. * * Called with j_list_lock held. */ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh, enum jbd2_shrink_type type, + unsigned long *nr_to_scan, bool *released) { struct journal_head *last_jh; @@ -375,13 +376,15 @@ static unsigned long journal_shrink_one_cp_list(struc= t journal_head *jh, int ret; =20 *released =3D false; - if (!jh) + if (!jh || (nr_to_scan && !*nr_to_scan)) return 0; =20 last_jh =3D jh->b_cpprev; do { jh =3D next_jh; next_jh =3D jh->b_cpnext; + if (nr_to_scan) + (*nr_to_scan)--; =20 if (type =3D=3D JBD2_SHRINK_DESTROY) { ret =3D __jbd2_journal_remove_checkpoint(jh); @@ -403,7 +406,7 @@ static unsigned long journal_shrink_one_cp_list(struct = journal_head *jh, next: if (need_resched()) break; - } while (jh !=3D last_jh); + } while (jh !=3D last_jh && (!nr_to_scan || *nr_to_scan)); =20 return nr_freed; } @@ -425,7 +428,6 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journ= al_t *journal, tid_t first_tid =3D 0, last_tid =3D 0, next_tid =3D 0; tid_t tid =3D 0; unsigned long nr_freed =3D 0; - unsigned long freed; bool first_set =3D false; =20 again: @@ -458,10 +460,9 @@ unsigned long jbd2_journal_shrink_checkpoint_list(jour= nal_t *journal, next_transaction =3D transaction->t_cpnext; tid =3D transaction->t_tid; =20 - freed =3D journal_shrink_one_cp_list(transaction->t_checkpoint_list, - JBD2_SHRINK_BUSY_SKIP, &released); - nr_freed +=3D freed; - (*nr_to_scan) -=3D min(*nr_to_scan, freed); + nr_freed +=3D journal_shrink_one_cp_list(transaction->t_checkpoint_list, + JBD2_SHRINK_BUSY_SKIP, + nr_to_scan, &released); if (*nr_to_scan =3D=3D 0) break; if (need_resched() || spin_needbreak(&journal->j_list_lock)) @@ -517,7 +518,7 @@ void __jbd2_journal_clean_checkpoint_list(journal_t *jo= urnal, transaction =3D next_transaction; next_transaction =3D transaction->t_cpnext; journal_shrink_one_cp_list(transaction->t_checkpoint_list, - type, &released); + type, NULL, &released); /* * This function only frees up some memory if possible so we * dont have an obligation to finish processing. Bail out if --=20 2.47.3