From patchwork Thu Oct 20 21:53:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014052 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 F245CC433FE for ; Thu, 20 Oct 2022 21:54:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90D1F8E0009; Thu, 20 Oct 2022 17:54:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BD8C8E0001; Thu, 20 Oct 2022 17:54:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 785DA8E0009; Thu, 20 Oct 2022 17:54:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6BB538E0001 for ; Thu, 20 Oct 2022 17:54:37 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3A5371204E4 for ; Thu, 20 Oct 2022 21:54:37 +0000 (UTC) X-FDA: 80042682594.06.FBC78F6 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by imf22.hostedemail.com (Postfix) with ESMTP id E708BC0014 for ; Thu, 20 Oct 2022 21:54:36 +0000 (UTC) Received: by mail-qv1-f51.google.com with SMTP id t16so608981qvm.9 for ; Thu, 20 Oct 2022 14:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D/FIsjw19eZ3OnJAIkw3KCiDeRv2n8mXkgoaXFlI9ro=; b=Jfxyh2ci01RrSPT9NlGFNscPY5PnsXAUGYcYoRSlBmjDz2eJE3LFrmNFqOjrNXF+V7 kH7Xlpre2JSJCWaxUVgT2xDPJMzJX5z+2wD5qUCsUREd0mY/eySZwJWln98Pra1/1gbI fdmxz5E2ZJWa8NubMcYhANwAlL2V5iNmTwIDWbIxEfbqDC8yvhsWJAZ+kFU+7giGU7DC wvFTrJT7YJ0e9wl+7meEo6c8q0ukXsJVNF2a7Z6z4aN61MeappkLjeJyJUo2B5Vqouqn cfqt7nA9MgPPPtx5fwH3bgE+niTxHXdMv3M/Tbp64/fEWFwMqF//10fYVb5EeAksvWUg kHgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D/FIsjw19eZ3OnJAIkw3KCiDeRv2n8mXkgoaXFlI9ro=; b=ieHnhrcO+qIvP7U/cEM7qDi0a8H4sNWDqzy7HakHvj6ORt1RLyBpGpCeuGukL/TSww DqE1H+ISrQlUjiUo2VW4Z/mJiS9IOGRXZR38YDPK2SjCbbrxmgOQbHWUlEYOGkAG29ze RZUcaiVkLytNTbpQSN0NhiQr8Glvd28bvQMpqfPlnp09v+iekYmgWYVbL46fuEpPxTGY r4Zt2mMhiXViPsPo9Shkt4oI9KOlErXgC6YKbtEK0VVf4nbstrMDNJu4yWZlvusiepSd HTMWZTUhE0WiooVJDoMlkrYofC452o1hzG5VKtqed6CI2uN2xil/yGYEUJkKOceQpkYI RIlg== X-Gm-Message-State: ACrzQf0JLXhVTASgdo17xoIrL95hFQ/doYuNCnWECV2YYLCz7eweRwUG /ywSmGIijq4crp8lP5Fjlwo= X-Google-Smtp-Source: AMsMyM6pLENQr5vbjvY+6Kql1ESyWRc/dvrXQFOAxarXh38H3a3fK/a5qUu7a9qn0oImRKl027uuPg== X-Received: by 2002:ad4:5968:0:b0:4b4:7d98:7ede with SMTP id eq8-20020ad45968000000b004b47d987edemr13626883qvb.130.1666302876219; Thu, 20 Oct 2022 14:54:36 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:35 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 5/9] mm/page_alloc: introduce init_reserved_pageblock() Date: Thu, 20 Oct 2022 14:53:14 -0700 Message-Id: <20221020215318.4193269-6-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302876; a=rsa-sha256; cv=none; b=c9WS1MUBiDIVUyP01Bq/3blP45G4vRLnnMOSzeAFQrU665aT1SEDVQz6SbEEkVlV/Rk8hc g6j21Y4WxWhZkTUMZJZ3kFsAV2FFfMHeSl86qlFsq/OZAVhEjUpiXTa/d7kmj/uIYCat48 baDl6B1MGGtf3HNj2AiF8VHntWSXyig= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Jfxyh2ci; spf=pass (imf22.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666302876; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D/FIsjw19eZ3OnJAIkw3KCiDeRv2n8mXkgoaXFlI9ro=; b=ecBECLBVBXTQumX7BW/S77ipIL/Ki2S7jYftDD16JqFjimLQxqabOQ19iLcm7JbZ3AcTNS RDztyktouQ+6FAZTqh6FUEmoJBFc/GzWd+hSJ5umEeGWpdHO9AMlr0OrSU3lsPOI5nekxX voLC++TqDpxGWDq9njz2UOy2VMqyUX4= X-Stat-Signature: dybzbsptkd7fa9kakiyidncwewp54j7t X-Rspamd-Queue-Id: E708BC0014 X-Rspam-User: X-Rspamd-Server: rspam03 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Jfxyh2ci; spf=pass (imf22.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1666302876-137974 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: Most of the implementation of init_cma_reserved_pageblock() is common to the initialization of any reserved pageblock for use by the page allocator. This commit breaks that functionality out into the new common function init_reserved_pageblock() for use by code other than CMA. The CMA specific code is relocated from page_alloc to the point where init_cma_reserved_pageblock() was invoked and the new function is used there instead. The error path is also updated to use the function to operate on pageblocks rather than pages. Signed-off-by: Doug Berger --- include/linux/gfp.h | 5 +---- mm/cma.c | 15 +++++++++++---- mm/page_alloc.c | 8 ++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ef4aea3b356e..6d66193f336d 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -347,9 +347,6 @@ extern struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask, #endif void free_contig_range(unsigned long pfn, unsigned long nr_pages); -#ifdef CONFIG_CMA -/* CMA stuff */ -extern void init_cma_reserved_pageblock(struct page *page); -#endif +extern void init_reserved_pageblock(struct page *page); #endif /* __LINUX_GFP_H */ diff --git a/mm/cma.c b/mm/cma.c index 4a978e09547a..6208a3e1cd9d 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "cma.h" @@ -116,8 +117,13 @@ static void __init cma_activate_area(struct cma *cma) } for (pfn = base_pfn; pfn < base_pfn + cma->count; - pfn += pageblock_nr_pages) - init_cma_reserved_pageblock(pfn_to_page(pfn)); + pfn += pageblock_nr_pages) { + struct page *page = pfn_to_page(pfn); + + set_pageblock_migratetype(page, MIGRATE_CMA); + init_reserved_pageblock(page); + page_zone(page)->cma_pages += pageblock_nr_pages; + } spin_lock_init(&cma->lock); @@ -133,8 +139,9 @@ static void __init cma_activate_area(struct cma *cma) out_error: /* Expose all pages to the buddy, they are useless for CMA. */ if (!cma->reserve_pages_on_error) { - for (pfn = base_pfn; pfn < base_pfn + cma->count; pfn++) - free_reserved_page(pfn_to_page(pfn)); + for (pfn = base_pfn; pfn < base_pfn + cma->count; + pfn += pageblock_nr_pages) + init_reserved_pageblock(pfn_to_page(pfn)); } totalcma_pages -= cma->count; cma->count = 0; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a4c2c157bacf..d7a5a05ead4b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2308,9 +2308,8 @@ void __init page_alloc_init_late(void) set_zone_contiguous(zone); } -#ifdef CONFIG_CMA -/* Free whole pageblock and set its migration type to MIGRATE_CMA. */ -void __init init_cma_reserved_pageblock(struct page *page) +/* Free whole pageblock */ +void __init init_reserved_pageblock(struct page *page) { unsigned i = pageblock_nr_pages; struct page *p = page; @@ -2320,14 +2319,11 @@ void __init init_cma_reserved_pageblock(struct page *page) set_page_count(p, 0); } while (++p, --i); - set_pageblock_migratetype(page, MIGRATE_CMA); set_page_refcounted(page); __free_pages(page, pageblock_order); adjust_managed_page_count(page, pageblock_nr_pages); - page_zone(page)->cma_pages += pageblock_nr_pages; } -#endif /* * The order of subdivision here is critical for the IO subsystem.