From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61F83C433ED for ; Mon, 12 Apr 2021 10:41:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C9CD961249 for ; Mon, 12 Apr 2021 10:41:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9CD961249 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 594FA6B0036; Mon, 12 Apr 2021 06:41:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56C566B006C; Mon, 12 Apr 2021 06:41:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45AF86B006E; Mon, 12 Apr 2021 06:41:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 2A7946B0036 for ; Mon, 12 Apr 2021 06:41:46 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D7A5D180385DC for ; Mon, 12 Apr 2021 10:41:45 +0000 (UTC) X-FDA: 78023374170.10.17A7023 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf25.hostedemail.com (Postfix) with ESMTP id 51802600010B for ; Mon, 12 Apr 2021 10:41:43 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 60439AF11; Mon, 12 Apr 2021 10:41:44 +0000 (UTC) Subject: Re: [PATCH 4/9] mm/page_alloc: optimize code layout for __alloc_pages_bulk To: Mel Gorman , Andrew Morton Cc: Chuck Lever , Jesper Dangaard Brouer , Christoph Hellwig , Alexander Duyck , Matthew Wilcox , Ilias Apalodimas , LKML , Linux-Net , Linux-MM , Linux-NFS References: <20210325114228.27719-1-mgorman@techsingularity.net> <20210325114228.27719-5-mgorman@techsingularity.net> From: Vlastimil Babka Message-ID: <71449835-d4da-657e-b4cf-b077e9636ff7@suse.cz> Date: Mon, 12 Apr 2021 12:41:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210325114228.27719-5-mgorman@techsingularity.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 51802600010B X-Stat-Signature: 9yg3bjinq76p85uift3kj5ty86jtax6c Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf25; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1618224103-984887 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/25/21 12:42 PM, Mel Gorman wrote: > From: Jesper Dangaard Brouer > > 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. Hm that's weird, WARN_ON_ONCE() uses unlikely() too, so the UD2 should end up in the out-of-fast-path part? But anyway. > [mgorman: Minor changes and rebasing] > Signed-off-by: Jesper Dangaard Brouer > Signed-off-by: Mel Gorman Acked-By: Vlastimil Babka > --- > mm/page_alloc.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index be1e33a4df39..1ec18121268b 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5001,7 +5001,7 @@ int __alloc_pages_bulk(gfp_t gfp, int preferred_nid, > unsigned int alloc_flags; > int nr_populated = 0; > > - if (WARN_ON_ONCE(nr_pages <= 0)) > + if (unlikely(nr_pages <= 0)) > return 0; > > /* > @@ -5048,7 +5048,7 @@ int __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 */ > @@ -5066,7 +5066,7 @@ int __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; >