提交 c646ff55 编写于 作者: J Jesper Dangaard Brouer 提交者: Zheng Zengkai

mm/page_alloc: optimize code layout for __alloc_pages_bulk

mainline inclusion
from mainline-5.13-rc1
commit ce76f9a1
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I3ZVL2
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ce76f9a1d9a21c2633dcd2a5605f923286e16e1d

-------------------------------------------------

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.

[mgorman@techsingularity.net: minor changes and rebasing]

Link: https://lkml.kernel.org/r/20210325114228.27719-5-mgorman@techsingularity.netSigned-off-by: NJesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: NMel Gorman <mgorman@techsingularity.net>
Reviewed-by: NAlexander Lobakin <alobakin@pm.me>
Acked-By: NVlastimil Babka <vbabka@suse.cz>
Cc: Alexander Duyck <alexander.duyck@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: David Miller <davem@davemloft.net>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit ce76f9a1)
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
Reviewed-by: NTong Tiangen <tongtiangen@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 b7444719
...@@ -4952,7 +4952,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, ...@@ -4952,7 +4952,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
unsigned int alloc_flags = ALLOC_WMARK_LOW; unsigned int alloc_flags = ALLOC_WMARK_LOW;
int nr_populated = 0; int nr_populated = 0;
if (WARN_ON_ONCE(nr_pages <= 0)) if (unlikely(nr_pages <= 0))
return 0; return 0;
/* /*
...@@ -4999,7 +4999,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, ...@@ -4999,7 +4999,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
* If there are no allowed local zones that meets the watermarks then * If there are no allowed local zones that meets the watermarks then
* try to allocate a single page and reclaim if necessary. * try to allocate a single page and reclaim if necessary.
*/ */
if (!zone) if (unlikely(!zone))
goto failed; goto failed;
/* Attempt the batch allocation */ /* Attempt the batch allocation */
...@@ -5017,7 +5017,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, ...@@ -5017,7 +5017,7 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
page = __rmqueue_pcplist(zone, ac.migratetype, alloc_flags, page = __rmqueue_pcplist(zone, ac.migratetype, alloc_flags,
pcp, pcp_list); pcp, pcp_list);
if (!page) { if (unlikely(!page)) {
/* Try and get at least one page */ /* Try and get at least one page */
if (!nr_populated) if (!nr_populated)
goto failed_irq; goto failed_irq;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册