* [PATCH] mm: skip empty finite ranges in truncate_pagecache_range
@ 2026-10-27 21:15 Hungyu Lin
0 siblings, 0 replies; only message in thread
From: Hungyu Lin @ 2026-10-27 21:15 UTC (permalink / raw)
To: willy
Cc: jack, akpm, lczerner, tytso, hughd, linux-fsdevel, linux-mm,
linux-kernel, dennylin0707
For a finite range ending before the first page boundary,
truncate_pagecache_range() calculates unmap_end as -1. The unsigned
comparison then treats the empty full-page interval as nonempty.
For example, lstart == 0 and lend == 0 cause unmap_mapping_range() to be
called with a zero length, meaning unmap to EOF. Punching one byte at
offset zero in a mapped FUSE file can therefore remove mappings outside
the hole, causing unnecessary page-table work and subsequent faults.
Compare the exclusive rounded end against the rounded start, while
explicitly preserving lend == -1 as the EOF sentinel. Perform the
addition after converting to u64 so the largest inclusive end does not
introduce a signed overflow in the comparison.
Fixes: 5a7203947a1d ("mm: teach truncate_inode_pages_range() to handle non page aligned ranges")
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
mm/truncate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/truncate.c b/mm/truncate.c
index b58ba940be47..43c6cf99027f 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -919,7 +919,7 @@ void truncate_pagecache_range(struct inode *inode, loff_t lstart, loff_t lend)
* once (before truncating pagecache), and without "even_cows" flag:
* hole-punching should not remove private COWed pages from the hole.
*/
- if ((u64)unmap_end > (u64)unmap_start)
+ if (lend == -1 || (u64)unmap_end + 1 > (u64)unmap_start)
unmap_mapping_range(mapping, unmap_start,
1 + unmap_end - unmap_start, 0);
truncate_inode_pages_range(mapping, lstart, lend);
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-27 21:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-27 21:15 [PATCH] mm: skip empty finite ranges in truncate_pagecache_range Hungyu Lin
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®