Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5692233rwb; Tue, 1 Aug 2023 06:42:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlER7RYguDWZDAT03qd+xV4Jx3pKe9+ncuK+GRtx3leiMysojF/cvmxygdglzBkXcilJEhNO X-Received: by 2002:a05:6a00:3a23:b0:687:55cb:ef94 with SMTP id fj35-20020a056a003a2300b0068755cbef94mr1466030pfb.34.1690897368851; Tue, 01 Aug 2023 06:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690897368; cv=none; d=google.com; s=arc-20160816; b=t6nPweZGJGFN5HLKi5VDmDysSfosTHE/hOa1ZA5y8K27f2bvpYTj4ORt9eumXGPFXw q7YRED8UMyoZqFEQ/iuXbdl0u9kuggyZGAGJPfRJNVGEQFrVOEBB0i7Qx0LeBAvOL7F0 ei8zIxJa1nYoEbiR43J6UnlDL2svUTyPS4LgyDdY/APuFFO80n+4bjSvDBjAWGtPWMBL IrZJC/RCh0+Jc3/rDsJRSXVWABf7bw1xFiF1ZOX5jMlcyMUGT7Pjplb3ZWMtlA9wqE3j 1bZrZ7lGEbrgq1OyLPWfC+hfbFObvCOVXU7FmPte7WlX/Hx7ZdCjbeznG2JbIaH1m9Wm 0SIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0O44SbHfMGw8JO6Nbs0MGiONaAsZsQXe4El4DYWLHwA=; fh=Mo/Lcs6WtjcRq1QaiJBjtYwS/87p5PpqCapK5ULE+Ko=; b=BlAXTWEUMbcoHtBFjtG6pgdcxOuq/P9FI/5ResQ3D/vVvIwF82sEwVLM8ldUhnz5c2 VDawaJOGu0ko2eo5KU6zp2Uo7kUJ/m8Hfu2tUIl9GA8XXjKyS4NrVaqIp2WBf1JlOaZt xc9YRIpsEgMpzMzhwezRdnPvE42ZXFZ6ZUIsKJjHCwXi4YzQAb82hEsEd6WJHe5yQJEh AFYIT0x6dqLWmvghbIj5NkJurDNFkdv49bG9OvRiPZDy0cKurufRB9BWWZZMwqDpCAb7 CsZvuuJoTJrTTmAjpp9PbOPf6wsXzcnkvkA2EKwKnIe2jMzamfB8T9Ba4KQLS80kT3IE xqiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020aa788c3000000b00682c0908d51si2904379pff.126.2023.08.01.06.42.34; Tue, 01 Aug 2023 06:42:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbjHAMhk (ORCPT + 99 others); Tue, 1 Aug 2023 08:37:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbjHAMhj (ORCPT ); Tue, 1 Aug 2023 08:37:39 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 379F91FC6 for ; Tue, 1 Aug 2023 05:37:38 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RFZLk2jjKzLnyG; Tue, 1 Aug 2023 20:34:54 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 1 Aug 2023 20:37:35 +0800 From: Miaohe Lin To: CC: , , Subject: [PATCH] mm/page_alloc: avoid unneeded alike_pages calculation Date: Tue, 1 Aug 2023 20:37:23 +0800 Message-ID: <20230801123723.2225543-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Miaohe Lin --- mm/page_alloc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8fe9ff917850..d7a357cb21ee 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -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 @@ -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) -- 2.33.0