Skip to content

Commit

Permalink
mm/page_alloc: avoid unneeded alike_pages calculation
Browse files Browse the repository at this point in the history
When free_pages is 0, alike_pages is not used.  So alike_pages calculation
can be avoided by checking free_pages early to save cpu cycles.  Also fix
typo 'comparable'.  It should be 'compatible' here.

Link: https://lkml.kernel.org/r/20230801123723.2225543-1-linmiaohe@huawei.com
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Miaohe Lin authored and Andrew Morton committed Aug 21, 2023
1 parent 549f5c7 commit ebddd11
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,10 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page,

free_pages = move_freepages_block(zone, page, start_type,
&movable_pages);
/* moving whole block can fail due to zone boundary conditions */
if (!free_pages)
goto single_page;

/*
* Determine how many pages are compatible with our allocation.
* For movable allocation, it's the number of movable pages which
Expand All @@ -1854,14 +1858,9 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page,
else
alike_pages = 0;
}

/* moving whole block can fail due to zone boundary conditions */
if (!free_pages)
goto single_page;

/*
* If a sufficient number of pages in the block are either free or of
* comparable migratability as our allocation, claim the whole block.
* compatible migratability as our allocation, claim the whole block.
*/
if (free_pages + alike_pages >= (1 << (pageblock_order-1)) ||
page_group_by_mobility_disabled)
Expand Down

0 comments on commit ebddd11

Please sign in to comment.