FAILED: patch "[PATCH] mm/shmem: report RCU-tasks quiescent states while undoing a range" failed to apply to 6.1-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x ebd1a08c192109c83a87ddf42793ed6283180faf
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From ebd1a08c192109c83a87ddf42793ed6283180faf Mon Sep 17 00:00:00 2001
From: Breno Leitao <[email protected]>
Date: Fri, 18 Sep 2026 04:24:37 -0700
Subject: [PATCH] mm/shmem: report RCU-tasks quiescent states while undoing a
range
This shows up in the Meta fleet on ftruncate() of large tmpfs files:
INFO: rcu_tasks detected stalls on tasks:
00000000752fd185: .. nvcsw: 59455/59455 holdout: 1 idle_cpu: -1/0
task:rocksdb:bottom state:R running task
__folio_split
find_get_entry
find_get_entries
truncate_inode_partial_folio
shmem_undo_range
shmem_setattr
notify_change
do_ftruncate
__x64_sys_ftruncate
do_syscall_64shmem_undo_range() walks the whole of the requested range in folio_batch sized steps, twice, and its two cond_resched() calls are the only reschedule points in that walk.
cond_resched() is not an RCU-tasks quiescent state. Use cond_resched_tasks_rcu_qs() at both points so the walk reports an RCU-tasks quiescent state as it proceeds.
--- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c +2 -2
@@ -1367,7 +1367,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend, }folio_batch_remove_exceptionals (&fbatch);folio_batch_release (&fbatch); -cond_resched (); +cond_resched_tasks_rcu_qs (); }/*
@@ -1408,7 +1408,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend, index = start;while (index < end) { -cond_resched (); +cond_resched_tasks_rcu_qs ();if (!find_get_entries (mapping, &index, end -1 , &fbatch, indices)) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 filemap: find_lock_entries() now updates start offset
From: "Vishal Moola (Oracle)" <[email protected]>
[ Upstream commit 3392ca121872dd8c33015c7703d4981c78819be3 ]
Patch series "Rework find_get_entries() and find_lock_entries()", v3.
Originally the callers of find_get_entries() and find_lock_entries() were keeping track of the start index themselves as they traverse the search range.
This resulted in hacky code such as in shmem_undo_range():
index = folio->index + folio_nr_pages(folio) - 1;
where the - 1 is only present to stay in the right spot after incrementing index later. This sort of calculation was also being done on every folio despite not even using index later within that function.
These patches change find_get_entries() and find_lock_entries() to calculate the new index instead of leaving it to the callers so we can avoid all these complications.
This patch (of 2):
Initially, find_lock_entries() was being passed in the start offset as a value. That left the calculation of the offset to the callers. This led to complexity in the callers trying to keep track of the index.
Now find_lock_entries() takes in a pointer to the start offset and updates the value to be directly after the last entry found. If no entry is found, the offset is not changed. This gets rid of multiple hacky calculations that kept track of the start offset.
Stable-dep-of: ebd1a08c1921 ("mm/shmem: report RCU-tasks quiescent states while undoing a range")
--- mm/filemap.c | 15 ++++++++++++--- mm/internal.h | 2 +- mm/shmem.c | 8 ++------ mm/truncate.c | 11 +++-------- 4 files changed, 18 insertions(+), 18 deletions(-)
mm/filemap.c +12 -3
@@ -2125,16 +2125,16 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t start,* * Return: The number of entries which were found. */ -unsigned find_lock_entries (struct address_space *mapping,pgoff_t start, +unsigned find_lock_entries (struct address_space *mapping,pgoff_t *start,pgoff_t end,struct folio_batch *fbatch,pgoff_t *indices) { -XA_STATE (xas, &mapping->i_pages, start); +XA_STATE (xas, &mapping->i_pages, *start);struct folio *folio;rcu_read_lock ();while ((folio =find_get_entry (&xas, end,XA_PRESENT ))) {if (!xa_is_value (folio)) { -if (folio->index < start) +if (folio->index < *start) goto put;if (folio->index +folio_nr_pages (folio) -1 > end) goto put;
@@ -2157,6 +2157,15 @@ unsigned find_lock_entries(struct address_space *mapping, pgoff_t start, }rcu_read_unlock (); +if (folio_batch_count (fbatch)) { +unsigned long nr =1 ; +int idx =folio_batch_count (fbatch) -1 ; + + folio = fbatch->folios[idx]; +if (!xa_is_value (folio) && !folio_test_hugetlb (folio)) + nr =folio_nr_pages (folio); + *start = indices[idx] + nr; + }return folio_batch_count (fbatch); }
mm/internal.h +1 -1
@@ -125,7 +125,7 @@ static inline void force_page_cache_readahead(struct address_space *mapping,force_page_cache_ra (&ractl, nr_to_read); } -unsigned find_lock_entries (struct address_space *mapping,pgoff_t start, +unsigned find_lock_entries (struct address_space *mapping,pgoff_t *start,pgoff_t end,struct folio_batch *fbatch,pgoff_t *indices);unsigned find_get_entries (struct address_space *mapping,pgoff_t start,pgoff_t end,struct folio_batch *fbatch,pgoff_t *indices);
mm/shmem.c +2 -6
@@ -931,21 +931,18 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,folio_batch_init (&fbatch); index = start; -while (index < end &&find_lock_entries (mapping, index, end -1 , +while (index < end &&find_lock_entries (mapping, &index, end -1 , &fbatch, indices)) {for (i =0 ; i <folio_batch_count (&fbatch); i++) { folio = fbatch.folios[i]; - index = indices[i]; -if (xa_is_value (folio)) {if (unfalloc)continue ; nr_swaps_freed += !shmem_free_swap (mapping, - index, folio); + indices[i], folio);continue ; } - index +=folio_nr_pages (folio) -1 ;if (!unfalloc || !folio_test_uptodate (folio))truncate_inode_folio (mapping, folio);
@@ -954,7 +951,6 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,folio_batch_remove_exceptionals (&fbatch);folio_batch_release (&fbatch);cond_resched (); - index++; }/*
mm/truncate.c +3 -8
@@ -385,9 +385,8 @@ void truncate_inode_pages_range(struct address_space *mapping,folio_batch_init (&fbatch); index = start; -while (index < end &&find_lock_entries (mapping, index, end -1 , +while (index < end &&find_lock_entries (mapping, &index, end -1 , &fbatch, indices)) { - index = indices[folio_batch_count (&fbatch) -1 ] +1 ;truncate_folio_batch_exceptionals (mapping, &fbatch, indices);for (i =0 ; i <folio_batch_count (&fbatch); i++)truncate_cleanup_folio (fbatch.folios[i]);
@@ -534,20 +533,17 @@ unsigned long invalidate_mapping_pagevec(struct address_space *mapping,int i;folio_batch_init (&fbatch); -while (find_lock_entries (mapping, index, end, &fbatch, indices)) { +while (find_lock_entries (mapping, &index, end, &fbatch, indices)) {for (i =0 ; i <folio_batch_count (&fbatch); i++) {struct folio *folio = fbatch.folios[i];/* We rely upon deletion not changing folio->index */ - index = indices[i];if (xa_is_value (folio)) { count +=invalidate_exceptional_entry (mapping, - index, - folio); + indices[i], folio);continue ; } - index +=folio_nr_pages (folio) -1 ; ret =mapping_evict_folio (mapping, folio);folio_unlock (folio);
@@ -566,7 +562,6 @@ unsigned long invalidate_mapping_pagevec(struct address_space *mapping,folio_batch_remove_exceptionals (&fbatch);folio_batch_release (&fbatch);cond_resched (); - index++; }return count; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 mm/shmem: report RCU-tasks quiescent states while undoing a range
From: Breno Leitao <[email protected]>
[ Upstream commit ebd1a08c192109c83a87ddf42793ed6283180faf ]
This shows up in the Meta fleet on ftruncate() of large tmpfs files:
INFO: rcu_tasks detected stalls on tasks:
00000000752fd185: .. nvcsw: 59455/59455 holdout: 1 idle_cpu: -1/0
task:rocksdb:bottom state:R running task
__folio_split
find_get_entry
find_get_entries
truncate_inode_partial_folio
shmem_undo_range
shmem_setattr
notify_change
do_ftruncate
__x64_sys_ftruncate
do_syscall_64shmem_undo_range() walks the whole of the requested range in folio_batch sized steps, twice, and its two cond_resched() calls are the only reschedule points in that walk.
cond_resched() is not an RCU-tasks quiescent state. Use cond_resched_tasks_rcu_qs() at both points so the walk reports an RCU-tasks quiescent state as it proceeds.
--- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c +2 -2
@@ -950,7 +950,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, }folio_batch_remove_exceptionals (&fbatch);folio_batch_release (&fbatch); -cond_resched (); +cond_resched_tasks_rcu_qs (); }/*
@@ -991,7 +991,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, index = start;while (index < end) { -cond_resched (); +cond_resched_tasks_rcu_qs ();if (!find_get_entries (mapping, index, end -1 , &fbatch, indices)) {
Signature · 1 line
2.53.0