[PATCH] fix unsuccessful folio2 split
From: Zi Yan
Date: Fri Sep 04 2026 - 15:25:06 EST
Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
---
mm/truncate.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/mm/truncate.c b/mm/truncate.c
index b58ba940be474..2c575f5e61889 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -259,6 +259,7 @@ bool truncate_inode_partial_folio(struct folio *folio, =
loff_t start, loff_t end)
* for shmem truncate
*/
struct folio *folio2;
+ bool ret =3D true;
=20
if (offset + length =3D=3D size)
goto no_split;
@@ -273,19 +274,23 @@ bool truncate_inode_partial_folio(struct folio *folio=
, loff_t start, loff_t end)
if (!folio_test_large(folio2))
goto out;
=20
- if (!folio_trylock(folio2))
+ if (!folio_trylock(folio2)) {
+ ret =3D false;
goto out;
+ }
=20
/* make sure folio2 is large and does not change its mapping */
if (folio_test_large(folio2) &&
folio2->mapping =3D=3D folio->mapping)
- folio_split_or_unmap(folio2, split_at2, min_order);
+ ret =3D !folio_split_or_unmap(folio2, split_at2, min_order);
+ else
+ ret =3D false;
=20
folio_unlock(folio2);
out:
folio_put(folio2);
no_split:
- return true;
+ return ret;
}
if (folio_test_dirty(folio))
return false;
--=20
2.53.0
>
> - Add an optional out-parameter pgoff_t *end, set to the index of the
> folio that contains @lend and must be kept by the caller's loop. It
> is only written when the folio actually straddles @lend. On the
> success path it defaults to the page index of the end edge and is
> refined to folio2->index when the second split fails to isolate the
> tail.
>
> - Rename the byte-range parameters start/end to lstart/lend to avoid
> clashing with the new @end output and to separate byte offsets from
> folio indices.
>
> Callers in truncate_inode_pages_range() and shmem_undo_range() pass &end
> only when the folio straddles lend. After all, no caller discards a
> straddling folio anymore, the in-range cleanly-split sub-folios below it
> are still dropped.
>
> Suggested-by: Brian Foster <bfoster@xxxxxxxxxx>
> Link: https://lore.kernel.org/linux-fsdevel/anH-WKA1coW6wtfG@bfoster/
> Fixes: 7460b470a131 ("mm/truncate: use folio_split() in truncate operatio=
n")
> Signed-off-by: Zhang Yi <yi.zhang@xxxxxxxxxx>
> ---
> mm/internal.h | 4 ++--
> mm/shmem.c | 12 +++++------
> mm/truncate.c | 57 ++++++++++++++++++++++++++++++---------------------
> 3 files changed, 41 insertions(+), 32 deletions(-)
>
--=20
Best Regards,
Yan, Zi