From patchwork Fri Apr 1 23:08:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 12798841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D03B3C433EF for ; Fri, 1 Apr 2022 23:08:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1ABCA8D0001; Fri, 1 Apr 2022 19:08:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1409A6B0072; Fri, 1 Apr 2022 19:08:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECAF58D0001; Fri, 1 Apr 2022 19:08:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id DAE6E6B0071 for ; Fri, 1 Apr 2022 19:08:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A11C825111 for ; Fri, 1 Apr 2022 23:08:10 +0000 (UTC) X-FDA: 79309850340.14.62860E8 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf17.hostedemail.com (Postfix) with ESMTP id ED5564000A for ; Fri, 1 Apr 2022 23:08:09 +0000 (UTC) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 85B365C01C6; Fri, 1 Apr 2022 19:08:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 01 Apr 2022 19:08:09 -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=n7TcKvtoCX05FSZFqOIqh4H/JQJNmNodokE+bj ntX2M=; b=VDAVqSyUvErOuKXGvLhBqj13vFM2Pu/M1VOx9zjzs/ak8FGTQAfhp3 XHIx4YEMxM5OjOhpwoWgkRIcROFUX/2JdGlAVVbgO5df2e41NkxKTJf5Dfe09ot5 0LVTmNpQUnOVZG1QU5Lg95T+7PU2GEfuf4TaR8uehV8FPLTvGQpcoYgpbtSm4IJ2 MxPjOcusxCKHstCEviiRoy/VtLEtXhu2v0FIsHq8GNNdK8mwJnJ+lCewNxfHZMUR NxQN47E0ZLekzArjh44gUEr8fKqqSX1VgYQuHjFMcU3lD+MP4ZWT0zWCA0BRaU/M AXHyaNs3aYX7IMDAFzZm2YXUJlEEshHw== 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=n7TcKvtoCX05FSZFqOIqh4H/JQJNm NodokE+bjntX2M=; b=J3Dav6ap+XnWqah7nTw20jx+92by9t7q8rNPlP0FT3s1Y uk0UFFuQLEPxldHXdl6CMMn5b9Ivl70xM/rrPV8RcuZHuhbx5ljBN27rlddUa8R0 U/CAlDwgV10LoYT/AuA2dp3+TN4tYqkGm0C/7bqKLwKoy/OlDyCQeByoXBO83Gel nV1HXp292OM0PkC5FXPRSSAo0hYmGL5EjswNb4OGowKDCvQD082Da6x0DRJGMpN2 dWRICq249llCECQWTvdKzNDgPdhgj0zFalj1nvtXn6LxsXxcj64ZQBC/ku+6S2iN lMXJB/KV1WMKlcbHucO8VNsg1uvy+HeFMK43/iiOQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeijedgudduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfforhgggfestdhqredtredttdenucfhrhhomhepkghiucgjrghn uceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepteeiiedtje fghfefueekjedvueeftddvudelhfetudffiefgfeetheeghfdvgedunecuffhomhgrihhn pehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Apr 2022 19:08:08 -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 v3 1/2] mm: page_alloc: simplify pageblock migratetype check in __free_one_page(). Date: Fri, 1 Apr 2022 19:08:03 -0400 Message-Id: <20220401230804.1658207-1-zi.yan@sent.com> X-Mailer: git-send-email 2.35.1 Reply-To: Zi Yan MIME-Version: 1.0 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=VDAVqSyU; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=J3Dav6ap; spf=pass (imf17.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: ED5564000A X-Stat-Signature: qdg7usnnf56y8m8gsguwdpf9ozbcrfjw X-HE-Tag: 1648854489-912690 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: 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 Acked-by: Vlastimil Babka --- 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 = task_capc(zone); - unsigned int max_order = 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); -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, if (!page_is_buddy(page, buddy, order)) goto done_merging; + + if (unlikely(order >= 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 = get_pageblock_migratetype(buddy); + + if (migratetype != 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 = combined_pfn; order++; } - if (order < MAX_ORDER - 1) { - /* If we are here, it means order is >= 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 = __find_buddy_pfn(pfn, order); - buddy = page + (buddy_pfn - pfn); - - if (!page_is_buddy(page, buddy, order)) - goto done_merging; - buddy_mt = get_pageblock_migratetype(buddy); - - if (migratetype != buddy_mt - && (!migratetype_is_mergeable(migratetype) || - !migratetype_is_mergeable(buddy_mt))) - goto done_merging; - max_order = order + 1; - goto continue_merging; - } done_merging: set_buddy_order(page, order);