Re: [PATCH v1] mm/readahead: Optimize nr_to_read boundary check

From: Matthew Wilcox
Date: Fri Jul 25 2025 - 11:45:48 EST


On Fri, Jul 25, 2025 at 11:28:34PM +0800, Xiaole He wrote:
> If nr_to_read is, for instance, 3, and end_index - index + 1 is also 3
> (meaning 3 pages remain), the condition 3 > 2 evaluates to true, leading
> to nr_to_read being assigned 3 again. While compilers might optimize
> this trivial self-assignment, it introduces unnecessary logical overhead
> and reduces code clarity.

But it makes the initial comparison more complex (by one operation) and
I bet you can't measure the difference anyway. I'm not inclined to
tweak this.