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 --- 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