From patchwork Tue Aug 1 12:37:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 129296 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2653725vqg; Tue, 1 Aug 2023 06:05:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlE6Gy26tqqwusrppdo/gtpfOUiv1li9HwflW9QY6qB7PXNfTy/kgb1C11LMobxUNjq5qQkN X-Received: by 2002:a05:6a20:9719:b0:11c:fc27:cda4 with SMTP id hr25-20020a056a20971900b0011cfc27cda4mr13075368pzc.11.1690895141822; Tue, 01 Aug 2023 06:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690895141; cv=none; d=google.com; s=arc-20160816; b=LHsD+NVZeCE3ZpmAAdcgCblOHFVfQkGHG4vdc9oqcfgGn1tO/442+pXUZY6hq2hgW8 idMGdIf5c5vK1bwFd55cZ8A7pka0KhIPEAIvjkO+ZTE0TH4/ton3egGFPjxtW6Db/FAc 4yQIzr/6vQm8fpIQb0gqbV8ME/N+4939ay1cCfRiEF/+DDfDXAfM7x1yEMHMUvKGHbtt x0bkNJP180UQRSLpj7P2fFMkDrjEmuTrCFFezACS8X6Fh74HSTZXdCRBvWI1g3BZYiOf d1s2BEhkRlxN4PG0SSbSRyeFRuy6uRXdl4hkaE7qFwh/Hdt28BgoXhy3Y0YHgezHrcyO egaw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fd21-20020a056a002e9500b0068664d7f3f2si9281861pfb.88.2023.08.01.06.05.28; Tue, 01 Aug 2023 06:05:41 -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 S232039AbjHAMhk (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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773032063881896417 X-GMAIL-MSGID: 1773032063881896417 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)