Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3412932pxb; Mon, 4 Apr 2022 16:11:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe8orl8/Y4SrhxKzyqrHzbfuilaT+6GBO4kizuUPaIumFq5GRTndzRDyojJOkxNC9wTjT+ X-Received: by 2002:a17:903:41c6:b0:156:abe8:6e4a with SMTP id u6-20020a17090341c600b00156abe86e4amr376607ple.113.1649113914055; Mon, 04 Apr 2022 16:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649113914; cv=none; d=google.com; s=arc-20160816; b=yKwC5xUV6anNByiDdGdvJuEc/MXnoLIwx5PlHAjiQgM2Vyqqn3nEexrNFp6usAgsVY s03y6mhZVgjASZIoZ0fdsLwBClOUnqhj2q2zUe8AfHV5eTet60KlBZfW+J9OD6zolL56 neXKKSG/Tw6Te4SCUXm21dGfQCYXIBtJbLxqGPRmVXgmeL1OO9psqDBydHy7ac8AsWUa NJEBDmdyGChYBrNLVZxJchZK1H1wURqUdPuRMNsqy34SrSCgbjFkxUvQevNXHu8EJLuA 5Os6wSJDP/kAThLgkcKe5+64UkPR6MkK6Mp71Pn0x3GltRurVrkhscDms63Jy7V4q9ew BlEg== 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:reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=2nU+VZUHjfRgXw79i6wfh74gnFpHiuHpC7KwwpV6T0c=; b=EoBEk0Yh9u86wPsZarMjIh+QIN5iXoniCJXW9naz8jdlTvsa6VxGtjQLVK62n2WY4L TmueqanDR7n2U7Sea2SkE7sHrpnRzgomzsobwykF5BaI886HdtHfICUYLCVPU9fVZxZ3 0tt6tZXF6AqSbT740/EC3Hz+RAT9PPNKXRym+aYGz0J2Mq3iKtbU+wGc5wkBCMr4vTWR blzkS+qdG2vbPIr81sgBMm1dr8Xck/JaYRJK+8w0RVQPO9UrN/npz2rQ1FXiwaPzUsc7 velnfY6RkWypK5xnK4CqfD1cdpGmFM9sstv7UJOU/BJ0MwiN1a5T3NoHBPHTosEuXXKk ZAEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=OuASuwFK; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=f35dgA12; 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=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l17-20020a170902f69100b00153b2d1649esi11849182plg.166.2022.04.04.16.11.39; Mon, 04 Apr 2022 16:11:54 -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; dkim=pass header.i=@sent.com header.s=fm3 header.b=OuASuwFK; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=f35dgA12; 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=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346595AbiDAOAY (ORCPT + 99 others); Fri, 1 Apr 2022 10:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbiDAOAT (ORCPT ); Fri, 1 Apr 2022 10:00:19 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 088E2C79 for ; Fri, 1 Apr 2022 06:58:26 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id D9D393200F72; Fri, 1 Apr 2022 09:58:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 01 Apr 2022 09:58:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:reply-to:sender:subject :subject:to:to; s=fm3; bh=2nU+VZUHjfRgXw79i6wfh74gnFpHiuHpC7Kwwp V6T0c=; b=OuASuwFKrQxica335ULucZKiokxQcmSt4KrmN5ES0JNIb755nefSlm 3edc33v1hLP0t+++hbn32p5/Ak5JDlDw9fmTC/iZuAUYnTwB6nf7znDzlMl/QhfC hTjiJ1ZwmkyEj0yI8q6JfJwyb41KjqQgmAKYLV8gHjXhi9kGXSaCNbgIRvpnoksZ p/CQFKRtvkQQNhHsb0LGhRvnI+G7aYdrDuU0ixKwCusEYB3JQnFvLoWzPUm6ms0h ud/mQsnYX31xUYwtFz7TdiA2b8COWNTKS67w32Y9KHA6njHttK17oQZmMtLKFLTb ApZ1CEF6rnYO9ut+HCHwy6bUSmYJUJxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:reply-to :sender:subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=2nU+VZUHjfRgXw79i6wfh74gnFpHi uHpC7KwwpV6T0c=; b=f35dgA121EFkB1TBtfF78IZ6c6+Bq4ZdaFRMx3RMTaJpK l/9faZdXR6pgZYfw0zY02vrMLoGvVagPt9w9T7BMdI0vf7UCExAT6iZBYwx0TrI3 K7Kpn5yCBO7lnElRw+nc+i6rz56DF4c66CAR7gAlhKpKNjQclGsgm9Qf9GhXWutv qNme3Al6fAbwd05wRzCZPhCDchytZLJu7IfCo515Zw+ZqRFqO3VJIoRXyTwB67aZ R8mk58tkqQgGSWvgk7V0AZovlj0rOASRmHhvtPVv525ZUNHXGiLGLYtwuuXgqPlu Y+7TjwVMaCnNkL0iGBFlFzd/JozwX6CuDAPuTWruA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeiiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfforhgggfestdhqredtredttdenucfhrhhomhepkghiucgjrghn uceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepteeiiedtje fghfefueekjedvueeftddvudelhfetudffiefgfeetheeghfdvgedunecuffhomhgrihhn pehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Apr 2022 09:58:23 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: Linus Torvalds , Steven Rostedt , David Hildenbrand , Vlastimil Babka , Mel Gorman , Mike Rapoport , Oscar Salvador , Andrew Morton , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH 1/2] mm: page_alloc: simplify pageblock migratetype check in __free_one_page(). Date: Fri, 1 Apr 2022 09:58:19 -0400 Message-Id: <20220401135820.1453829-1-zi.yan@sent.com> X-Mailer: git-send-email 2.35.1 Reply-To: Zi Yan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 From: Zi Yan Move pageblock migratetype check code in the while loop to simplify the logic. It also saves redundant buddy page checking code. Suggested-by: Vlastimil Babka Link: https://lore.kernel.org/linux-mm/27ff69f9-60c5-9e59-feb2-295250077551= @suse.cz/ Signed-off-by: Zi Yan --- mm/page_alloc.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 856473e54155..2ea106146686 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1054,7 +1054,6 @@ static inline void __free_one_page(struct page *page, int migratetype, fpi_t fpi_flags) { struct capture_control *capc =3D task_capc(zone); - unsigned int max_order =3D pageblock_order; unsigned long buddy_pfn; unsigned long combined_pfn; struct page *buddy; @@ -1070,8 +1069,7 @@ static inline void __free_one_page(struct page *page, VM_BUG_ON_PAGE(pfn & ((1 << order) - 1), page); VM_BUG_ON_PAGE(bad_range(zone, page), page); =20 -continue_merging: - while (order < max_order) { + while (order < MAX_ORDER - 1) { if (compaction_capture(capc, page, order, migratetype)) { __mod_zone_freepage_state(zone, -(1 << order), migratetype); @@ -1082,6 +1080,22 @@ static inline void __free_one_page(struct page *page, =20 if (!page_is_buddy(page, buddy, order)) goto done_merging; + + if (unlikely(order >=3D pageblock_order)) { + /* + * We want to prevent merge between freepages on pageblock + * without fallbacks and normal pageblock. Without this, + * pageblock isolation could cause incorrect freepage or CMA + * accounting or HIGHATOMIC accounting. + */ + int buddy_mt =3D get_pageblock_migratetype(buddy); + + if (migratetype !=3D buddy_mt + && (!migratetype_is_mergeable(migratetype) || + !migratetype_is_mergeable(buddy_mt))) + goto done_merging; + } + /* * Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page, * merge with it and move up one order. @@ -1095,32 +1109,6 @@ static inline void __free_one_page(struct page *page, pfn =3D combined_pfn; order++; } - if (order < MAX_ORDER - 1) { - /* If we are here, it means order is >=3D pageblock_order. - * We want to prevent merge between freepages on pageblock - * without fallbacks and normal pageblock. Without this, - * pageblock isolation could cause incorrect freepage or CMA - * accounting or HIGHATOMIC accounting. - * - * We don't want to hit this code for the more frequent - * low-order merging. - */ - int buddy_mt; - - buddy_pfn =3D __find_buddy_pfn(pfn, order); - buddy =3D page + (buddy_pfn - pfn); - - if (!page_is_buddy(page, buddy, order)) - goto done_merging; - buddy_mt =3D get_pageblock_migratetype(buddy); - - if (migratetype !=3D buddy_mt - && (!migratetype_is_mergeable(migratetype) || - !migratetype_is_mergeable(buddy_mt))) - goto done_merging; - max_order =3D order + 1; - goto continue_merging; - } =20 done_merging: set_buddy_order(page, order); --=20 2.35.1