Re: [PATCH] shmem: skip empty unmap ranges when punching holes

From: David Hildenbrand (Arm)

Date: Wed Nov 04 2026 - 09:13:07 EST


On 11/3/26 21:00, Hungyu Lin wrote:
>> To be clear, I was asking whether we could do
>>
>> if ((u64)(unmap_end) >= (u64)unmap_start)
>
> Sorry, I misunderstood your suggestion.
>
> With offset = 0 and len = 1, unmap_end is -1 and unmap_start is 0.
> Casting -1 to u64 makes this comparison true, so it still passes
> a zero length to unmap_mapping_range(), meaning unmap to EOF.

loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1;

Yes, that will give us -1. with offset+len == 1.

Makes sense, although it all looks more confusing than it should be :)

I'm fine with the fix, but I do wonder whether we could make unmap_end an
exclusive end instead of an inclusive end ... something for the future.

--
Cheers,

David