Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Jianping Liu <frankljpliu@gmail.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca,
	libaokun@linux.alibaba.com, jack@suse.cz, ojaswin@linux.ibm.com,
	ritesh.list@gmail.com, yi.zhang@huawei.com,
	frankjpliu@tencent.com, linux-ext4@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] ext4: fix soft lockup while shrinking the extent status cache
Date: Wed, 28 Oct 2026 14:16:28 +0800	[thread overview]
Message-ID: <20261028061628.1209508-1-frankljpliu@gmail.com> (raw)

From: Jianping Liu <frankjpliu@tencent.com>

__es_shrink() walks sbi->s_es_list and reclaims extents from each
inode. On a non-preemptible kernel that walk never gives up the CPU.

There is a soft lockup report on our company's machine. The machine
with millions of active inodes, 256 CPUs, and heavy memory pressure,
concurrent shrinkers run too long.

i_es_lock is dropped after es_reclaim_extents(), and s_es_lock is not
taken again until the next inode. Once the shrink has run for one
second, call cond_resched() so the CPU can be scheduled before the
scan continues.

Signed-off-by: Jianping Liu <frankjpliu@tencent.com>
---
 fs/ext4/extents_status.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 018b6146b9d8..c9c70db5eb71 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1679,6 +1679,7 @@ static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
 	int nr_to_walk;
 	int nr_shrunk = 0;
 	int retried = 0, nr_skipped = 0;
+	unsigned long end_jiffies = jiffies + HZ;
 
 	es_stats = &sbi->s_es_stats;
 	start_time = ktime_get();
@@ -1719,6 +1720,15 @@ static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
 		nr_shrunk += es_reclaim_extents(ei, &nr_to_scan);
 		write_unlock(&ei->i_es_lock);
 
+		/*
+		 * Call cond_resched to avoid soft lockup if a kernel with
+		 * preempt disabled.
+		 */
+		if (time_after(jiffies, end_jiffies)) {
+			cond_resched();
+			end_jiffies = jiffies + HZ;
+		}
+
 		if (nr_to_scan <= 0)
 			goto out;
 		spin_lock(&sbi->s_es_lock);
-- 
2.43.7


             reply	other threads:[~2026-10-28  6:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28  6:16 Jianping Liu [this message]
2026-10-28  6:21 ` [PATCH] ext4: fix soft lockup while shrinking the extent status cache sashiko-bot

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=20261028061628.1209508-1-frankljpliu@gmail.com \
    --to=frankljpliu@gmail.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=frankjpliu@tencent.com \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.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