mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] ext4: fix soft lockup while shrinking the extent status cache
@ 2026-11-06  3:31 Jianping Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Jianping Liu @ 2026-11-06  3:31 UTC (permalink / raw)
  To: tytso, adilger.kernel, libaokun, jack, ojaswin, ritesh.list,
	yi.zhang, frankjpliu, linux-ext4
  Cc: linux-kernel

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. When nr_to_scan remains, call
cond_resched_tasks_rcu_qs() before continuing the scan.

cond_resched() does not report the RCU quiescent state needed here.
It is compiled out when CONFIG_PREEMPTION=y. Otherwise it schedules
through preempt_schedule(), and RCU records that switch as a
preemption. An RCU-tasks read-side section ends only at a voluntary
context switch, cond_resched_tasks_rcu_qs(), idle, or return to
userspace. The helper reports that voluntary quiescent state and still
lets a non-preemptible kernel reschedule.

---
Changes from v1:
- Delete time out logic.
- Change "cond_resched" to "cond_resched_tasks_rcu_qs".
---
====================

Link: https://patchwork.ozlabs.org/project/linux-ext4/patch/20261028061628.1209508-1-frankljpliu@gmail.com/
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..62346eaf4350 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1721,6 +1721,16 @@ static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
 
 		if (nr_to_scan <= 0)
 			goto out;
+
+		/*
+		 * Report a voluntary RCU-tasks quiescent state before continuing.
+		 * cond_resched() is not enough: it is compiled out under
+		 * CONFIG_PREEMPTION, and otherwise switches via preemption, which
+		 * does not end an RCU-tasks read-side section.
+		 * This also lets a non-preemptible kernel reschedule.
+		 */
+		cond_resched_tasks_rcu_qs();
+
 		spin_lock(&sbi->s_es_lock);
 	}
 	spin_unlock(&sbi->s_es_lock);
-- 
2.43.7


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] ext4: fix soft lockup while shrinking the extent status cache
  2026-11-05 18:30 ` Jan Kara
@ 2026-11-06  3:42   ` frank jpliu
  0 siblings, 0 replies; 4+ messages in thread
From: frank jpliu @ 2026-11-06  3:42 UTC (permalink / raw)
  To: Jan Kara
  Cc: tytso, adilger.kernel, libaokun, ojaswin, ritesh.list, yi.zhang,
	frankjpliu, linux-ext4, linux-kernel

On Fri, Nov 6, 2026 at 2:30 AM Jan Kara <jack@suse.cz> wrote:
>
> On Wed 04-11-26 11:35:39, Jianping Liu wrote:
> > 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. When nr_to_scan remains, call
> > cond_resched_tasks_rcu_qs() before continuing the scan.
> >
> > cond_resched() does not report the RCU quiescent state needed here.
> > It is compiled out when CONFIG_PREEMPTION=y. Otherwise it schedules
> > through preempt_schedule(), and RCU records that switch as a
> > preemption. An RCU-tasks read-side section ends only at a voluntary
> > context switch, cond_resched_tasks_rcu_qs(), idle, or return to
> > userspace. The helper reports that voluntary quiescent state and still
> > lets a non-preemptible kernel reschedule.
> >
> > Changes from v1:
> > - Delete time out logic.
> > - Change "cond_resched" to "cond_resched_tasks_rcu_qs".
>
> These three lines belong below the ---. Otherwise feel free to add:

   Sorry, I had forgotten it.
   I have added  --- in the patch just now :
https://sashiko.dev/#/patchset/20261106033141.1509656-1-frankljpliu%40gmail.com

>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
>                                                                 Honza
>
> >
> > Link: https://patchwork.ozlabs.org/project/linux-ext4/patch/20261028061628.1209508-1-frankljpliu@gmail.com/
> > 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..62346eaf4350 100644
> > --- a/fs/ext4/extents_status.c
> > +++ b/fs/ext4/extents_status.c
> > @@ -1721,6 +1721,16 @@ static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
> >
> >               if (nr_to_scan <= 0)
> >                       goto out;
> > +
> > +             /*
> > +              * Report a voluntary RCU-tasks quiescent state before continuing.
> > +              * cond_resched() is not enough: it is compiled out under
> > +              * CONFIG_PREEMPTION, and otherwise switches via preemption, which
> > +              * does not end an RCU-tasks read-side section.
> > +              * This also lets a non-preemptible kernel reschedule.
> > +              */
> > +             cond_resched_tasks_rcu_qs();
> > +
> >               spin_lock(&sbi->s_es_lock);
> >       }
> >       spin_unlock(&sbi->s_es_lock);
> > --
> > 2.43.7
> >
> --
> Jan Kara <jack@suse.com>
> SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] ext4: fix soft lockup while shrinking the extent status cache
  2026-11-04  3:35 Jianping Liu
@ 2026-11-05 18:30 ` Jan Kara
  2026-11-06  3:42   ` frank jpliu
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2026-11-05 18:30 UTC (permalink / raw)
  To: Jianping Liu
  Cc: tytso, adilger.kernel, libaokun, jack, ojaswin, ritesh.list,
	yi.zhang, frankjpliu, linux-ext4, linux-kernel

On Wed 04-11-26 11:35:39, Jianping Liu wrote:
> 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. When nr_to_scan remains, call
> cond_resched_tasks_rcu_qs() before continuing the scan.
> 
> cond_resched() does not report the RCU quiescent state needed here.
> It is compiled out when CONFIG_PREEMPTION=y. Otherwise it schedules
> through preempt_schedule(), and RCU records that switch as a
> preemption. An RCU-tasks read-side section ends only at a voluntary
> context switch, cond_resched_tasks_rcu_qs(), idle, or return to
> userspace. The helper reports that voluntary quiescent state and still
> lets a non-preemptible kernel reschedule.
> 
> Changes from v1:
> - Delete time out logic.
> - Change "cond_resched" to "cond_resched_tasks_rcu_qs".

These three lines belong below the ---. Otherwise feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> 
> Link: https://patchwork.ozlabs.org/project/linux-ext4/patch/20261028061628.1209508-1-frankljpliu@gmail.com/
> 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..62346eaf4350 100644
> --- a/fs/ext4/extents_status.c
> +++ b/fs/ext4/extents_status.c
> @@ -1721,6 +1721,16 @@ static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
>  
>  		if (nr_to_scan <= 0)
>  			goto out;
> +
> +		/*
> +		 * Report a voluntary RCU-tasks quiescent state before continuing.
> +		 * cond_resched() is not enough: it is compiled out under
> +		 * CONFIG_PREEMPTION, and otherwise switches via preemption, which
> +		 * does not end an RCU-tasks read-side section.
> +		 * This also lets a non-preemptible kernel reschedule.
> +		 */
> +		cond_resched_tasks_rcu_qs();
> +
>  		spin_lock(&sbi->s_es_lock);
>  	}
>  	spin_unlock(&sbi->s_es_lock);
> -- 
> 2.43.7
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] ext4: fix soft lockup while shrinking the extent status cache
@ 2026-11-04  3:35 Jianping Liu
  2026-11-05 18:30 ` Jan Kara
  0 siblings, 1 reply; 4+ messages in thread
From: Jianping Liu @ 2026-11-04  3:35 UTC (permalink / raw)
  To: tytso, adilger.kernel, libaokun, jack, ojaswin, ritesh.list,
	yi.zhang, frankjpliu, linux-ext4
  Cc: linux-kernel

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. When nr_to_scan remains, call
cond_resched_tasks_rcu_qs() before continuing the scan.

cond_resched() does not report the RCU quiescent state needed here.
It is compiled out when CONFIG_PREEMPTION=y. Otherwise it schedules
through preempt_schedule(), and RCU records that switch as a
preemption. An RCU-tasks read-side section ends only at a voluntary
context switch, cond_resched_tasks_rcu_qs(), idle, or return to
userspace. The helper reports that voluntary quiescent state and still
lets a non-preemptible kernel reschedule.

Changes from v1:
- Delete time out logic.
- Change "cond_resched" to "cond_resched_tasks_rcu_qs".

Link: https://patchwork.ozlabs.org/project/linux-ext4/patch/20261028061628.1209508-1-frankljpliu@gmail.com/
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..62346eaf4350 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1721,6 +1721,16 @@ static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
 
 		if (nr_to_scan <= 0)
 			goto out;
+
+		/*
+		 * Report a voluntary RCU-tasks quiescent state before continuing.
+		 * cond_resched() is not enough: it is compiled out under
+		 * CONFIG_PREEMPTION, and otherwise switches via preemption, which
+		 * does not end an RCU-tasks read-side section.
+		 * This also lets a non-preemptible kernel reschedule.
+		 */
+		cond_resched_tasks_rcu_qs();
+
 		spin_lock(&sbi->s_es_lock);
 	}
 	spin_unlock(&sbi->s_es_lock);
-- 
2.43.7


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-06  3:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06  3:31 [PATCH v2] ext4: fix soft lockup while shrinking the extent status cache Jianping Liu
  -- strict thread matches above, loose matches on Subject: below --
2026-11-04  3:35 Jianping Liu
2026-11-05 18:30 ` Jan Kara
2026-11-06  3:42   ` frank jpliu

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

all inboxes | Powered by JetHome®