Skip to content

Commit

Permalink
mm/page_alloc: optimize code layout for __alloc_pages_bulk
Browse files Browse the repository at this point in the history
Looking at perf-report and ASM-code for __alloc_pages_bulk() it is clear
that the code activated is suboptimal.  The compiler guesses wrong and
places unlikely code at the beginning.  Due to the use of WARN_ON_ONCE()
macro the UD2 asm instruction is added to the code, which confuse the
I-cache prefetcher in the CPU.

[[email protected]: minor changes and rebasing]

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Signed-off-by: Mel Gorman <[email protected]>
Reviewed-by: Alexander Lobakin <[email protected]>
Acked-By: Vlastimil Babka <[email protected]>
Cc: Alexander Duyck <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Chuck Lever <[email protected]>
Cc: David Miller <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
netoptimizer authored and torvalds committed Apr 30, 2021
1 parent 0f87d9d commit ce76f9a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5042,7 +5042,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
unsigned int alloc_flags = ALLOC_WMARK_LOW;
int nr_populated = 0;

if (WARN_ON_ONCE(nr_pages <= 0))
if (unlikely(nr_pages <= 0))
return 0;

/*
Expand Down Expand Up @@ -5089,7 +5089,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
* If there are no allowed local zones that meets the watermarks then
* try to allocate a single page and reclaim if necessary.
*/
if (!zone)
if (unlikely(!zone))
goto failed;

/* Attempt the batch allocation */
Expand All @@ -5107,7 +5107,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,

page = __rmqueue_pcplist(zone, ac.migratetype, alloc_flags,
pcp, pcp_list);
if (!page) {
if (unlikely(!page)) {
/* Try and get at least one page */
if (!nr_populated)
goto failed_irq;
Expand Down

0 comments on commit ce76f9a

Please sign in to comment.