ext4: fix soft lockup while shrinking the extent status cache
PATCH v2 1/1 ext4: fix soft lockup while shrinking the extent status cache
From: Jianping Liu <[email protected]>
__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".
---
====================
--- fs/ext4/extents_status.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/ext4/extents_status.c +10 -0
@@ -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);
Signature · 1 line
2.43.7
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 13 lines
From: Jianping Liu <[email protected]>
__es_shrink()walkssbi->s_es_listand 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_lockis dropped afteres_reclaim_extents(), ands_es_lockis not taken again until the next inode. Whennr_to_scanremains, callcond_resched_tasks_rcu_qs()before continuing the scan.
Quoted 8 lines
cond_resched()does not report the RCU quiescent state needed here. It is compiled out whenCONFIG_PREEMPTION=y. Otherwise it schedules throughpreempt_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.
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 21 lines · Jianping Liu
From: Jianping Liu <[email protected]>
__es_shrink()walkssbi->s_es_listand 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_lockis dropped afteres_reclaim_extents(), ands_es_lockis not taken again until the next inode. Whennr_to_scanremains, callcond_resched_tasks_rcu_qs()before continuing the scan.
cond_resched()does not report the RCU quiescent state needed here. It is compiled out whenCONFIG_PREEMPTION=y. Otherwise it schedules throughpreempt_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.
Quoted 6 lines
---
Changes from v1:
- Delete time out logic.
- Change "cond_resched" to "cond_resched_tasks_rcu_qs".
---
====================
Please, the changes since v1 should not be in the part of email that goes to commit log. Next time please put it below diffstat. Otherwise feel free to add:
Honza
Quoted 31 lines
Signed-off-by Jianping Liu <[email protected]>--- fs/ext4/extents_status.c | 10 ++++++++++ 1 file changed, 10 insertions(+)fs/ext4/extents_status.c +10
-0@@ -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);Signature · 1 line
2.43.7
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR