Skip to content

Commit e03c16f

Browse files
Panky-codesakpm00
authored andcommitted
readahead: use ilog2 instead of a while loop in page_cache_ra_order()
A while loop is used to adjust the new_order to be lower than the ra->size. ilog2 could be used to do the same instead of using a loop. ilog2 typically resolves to a bit scan reverse instruction. This is particularly useful when ra->size is smaller than the 2^new_order as it resolves in one instruction instead of looping to find the new_order. No functional changes. Link: https://lkml.kernel.org/r/20240115102523.2336742-1-kernel@pankajraghav.com Signed-off-by: Pankaj Raghav <p.raghav@samsung.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent cabbb6d commit e03c16f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

mm/readahead.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,8 @@ void page_cache_ra_order(struct readahead_control *ractl,
500500

501501
if (new_order < MAX_PAGECACHE_ORDER) {
502502
new_order += 2;
503-
if (new_order > MAX_PAGECACHE_ORDER)
504-
new_order = MAX_PAGECACHE_ORDER;
505-
while ((1 << new_order) > ra->size)
506-
new_order--;
503+
new_order = min_t(unsigned int, MAX_PAGECACHE_ORDER, new_order);
504+
new_order = min_t(unsigned int, new_order, ilog2(ra->size));
507505
}
508506

509507
filemap_invalidate_lock_shared(mapping);

0 commit comments

Comments
 (0)