From patchwork Thu Jun 13 11:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13696662 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 0DAB7C27C75 for ; Thu, 13 Jun 2024 11:45:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0EFE6B0099; Thu, 13 Jun 2024 07:45:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BE516B009A; Thu, 13 Jun 2024 07:45:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 886966B009B; Thu, 13 Jun 2024 07:45:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6B9BC6B0099 for ; Thu, 13 Jun 2024 07:45:36 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 20FE9A39BD for ; Thu, 13 Jun 2024 11:45:36 +0000 (UTC) X-FDA: 82225685472.04.FCD58AB Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) by imf03.hostedemail.com (Postfix) with ESMTP id 71AD420008 for ; Thu, 13 Jun 2024 11:45:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AsLTMBJ1; spf=pass (imf03.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.49 as permitted sender) smtp.mailfrom=richard.weiyang@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=1718279133; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=LjvMQ386IcH8QfQLqhY7FnZfSC/ajTc+hzmemnuHIZA=; b=tcD04LqL8nqPz9KVgkuNHBv9IOMi4A0qBF9fs6wA1o5CQvAMbZgKZ5xCL7dn9vPkhQngit RfKtj60ZbuNcvSs+xRzRMt9rWLyjmDHjsAVWlTcA2SMtpNAMaCgFO+VftjaqVIAQ6j+E7a U7rCP0P3TcigOA818Vj9u+gMQPngSI8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AsLTMBJ1; spf=pass (imf03.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.49 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718279133; a=rsa-sha256; cv=none; b=kGB2cFPD0f+gxxcvN9yHJHq+qWYcprdbDwAOYcQN2NDMfMP5MmlA8px6cbcf+frkULImiN XA++KkChuZOvM3vaq2Hq3mwmDjtsJGoaXTAXkvasrEVZNBKUIyUjHvypF+iufJ+bv2phMT q17ufVlV9/Nll/FsdlpAM5H778oD/J4= Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a6f09eaf420so102854466b.3 for ; Thu, 13 Jun 2024 04:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718279133; x=1718883933; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LjvMQ386IcH8QfQLqhY7FnZfSC/ajTc+hzmemnuHIZA=; b=AsLTMBJ1eOuSABclIdA8Sfnro2/c9KcE2CkxTZOQyiwpLv6skHHYeGg7JZwIybM54I Rr9zh/vsoI/rAoouTibmOTxI9rg9kbn8RfiXLZQ/ITEvDHlo/4nJXHgKxM0vyxeGCcRc HwbcsV2IrlV5IMwInH66s+b7G8Gwq2/jzH75OPT84DPVIjb3v90UQLAtYPMWz8Nxf2VN gggAW3qLNNQQJh76wREUdwjOUlqYuyG/10T4873/xgGt1rZDI5YUTqsfJUk73mM4ZHee 5rlJftoktt3gq+e4tYPBirDeLK1MPySnRkMlMHa3M5vFMeSuXOKwBJ5nG928N3WZgFxZ li2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718279133; x=1718883933; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LjvMQ386IcH8QfQLqhY7FnZfSC/ajTc+hzmemnuHIZA=; b=bSRpsysQgdQihTzudP3Af7BPpiWIpUH6BZFpDCx/ymOxM1zAZJSmq7m2ZtYipl2USx hlhYQDBoxmYTqovNniMsua9CRBHwHvDrI4MnuRddHw+ao5vhBZ0vS0/D9OkmzpSYp6b5 GUs3WXg51njdIaeURDrdBuUgRDYjcI3C9GKiT4QWxKpolGqQh/x2YbDb+pFVRZ8WV8/G R3i3O0rkQrK4Z+xWnNSkq6DScQx8wPglo7w10Zb0Bc3+RB/kGEjmyc+acEyLt9BkWWV3 zO/JxE1ehtXV+XHM000WgTZ2mBNf5IrmS4wz/cEbg1i48GfJ+FOs2ciJc100Mls/Ksju DEwA== X-Gm-Message-State: AOJu0Yx61K7NppTLfifxn+r45nskqR040hn/ELJfbUJcNKe3I4OVj6l1 ROZ9nSfMgC71Ljco6+ZNKb0Su68MKfr0A+Ge8DVMY/cLSBTgHIAd X-Google-Smtp-Source: AGHT+IFQizoV8wZMhrqzncagkNbCRLJLDvUhiocpIHj+QOBMMtKss280F08xgoFqsLE1bb67zEts5g== X-Received: by 2002:a17:906:d0cb:b0:a6f:e4f:65ff with SMTP id a640c23a62f3a-a6f48028058mr323440566b.76.1718279132625; Thu, 13 Jun 2024 04:45:32 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56db5b98sm63469366b.86.2024.06.13.04.45.31 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jun 2024 04:45:31 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , "Kirill A . Shutemov" , David Hildenbrand Subject: [PATCH v2] mm/mm_init.c: simplify logic of deferred_[init|free]_pages Date: Thu, 13 Jun 2024 11:45:25 +0000 Message-Id: <20240613114525.27528-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 71AD420008 X-Stat-Signature: w35qyjsespfyzf6jzzs3ekbnpyqid6im X-Rspam-User: X-HE-Tag: 1718279134-339033 X-HE-Meta: U2FsdGVkX19ARaTX3J8aF+510hlC2t3BWKqFXShNjdplaB72mbJE36cpfVBMmoeI2/cyFKzM2Duk3InG+FRanxDzkAL+ntNMu9XBQy9OnwUFqt3rKDB8mlL0ZA6HoOGxmCx0XKnkgXDKhFgN3skuqggRdcswjEGAVQyeGagZhcYVq/G8DYNbbvwIimCc8coLSNQHlGeYIAPCAoLQsRXiSeMFAeTR5TShKWs3+gEjyDG2ijjGk55HtGCSncGSi/QpiC/4WXUQMMc8pLY7epbZbTbnTN1pW+l08vJNiRZa2l4kcBWtoF4psbGcgrSKQyxbgY84RpXAe7gpUBpNelLahEvwtvaeDOF24mZj8hXaUiJcBFoM1MWb0KNZ7cDlUAEXwOOBwMrxeAa8ueEr3Jt5cChjKwpT6UL0ns+lWRiSmoqtHb75ygJFooqe60AQ/lU/oYRdDoJKvCCx0Og2x4B2FZ2udUyRvGg5SY85EdfuNu6GQFAUqMfu2VmG+zxhGpaAHePlqQZQWpas1t+GTWXabllq8kRycKh/TGgahg3K4HwLMwjLYQ6UuaErjApPyfU3y+HKXhfnrPeNWJQOl7HFsiQ2ooBM/uLOYxUBGwVFfvOTewhiw0bn5djsWaVlSaAd5nrXXQiqBM9QVyAcFMnKBp1INF/+3DT9qBn5CDa26brqwHTZpIhQR1UwwNHgXGFGf34tB9blgCyaE81dPbhBogPukPF9NtTREnXB+f47bgFqv0O7j0XClpDjoKKWwGQkJQFazsZGzqE9pRBRwLQCneg4TBQ9wy3Xi5+42WUWw7IMYUHthZjTr7h4E9NKqrCMOWA+d2AX7bpUS1RWrwxKPzdM6d8hzl4cyDDWDbYRYE0sRwbWwXC6NzZbOiIdH9Tt/4rSSEKBFVlZ2fZKaN+oI8HPcwkn4LR8OraTuLttnectSalDgN2lctHDpXXnv0Sah74sRLToKyiJU6g4Pdl Vh81dziT uW3QCOZQo5So6Y2t1i+flrft9hez0C4fT8uwRqYS+k5iNQ9AnSHjd2vbg9MeA5r04OYwKo6p485Y617T7EGmkYeGd2+0U5XCybmznQczgtz8vv/EbtNu/0EHdZsEQVc7nXTOqho6sgzPYMpWOggpSm7wwPkpU4koEMANfV5UCGJTL56wG9+9x0sJvp+EwrQovRclJJAB9bbF3hAIxMqyjgibjxlhezFJ6j5ZhfrJZIYlwrPsOV+pgA1HMXDTpBl1Dxh4Q9l6RZMlHTmleiTA1PKLQFmNGhRSmZi0rrtd1K+Yvu2NS1q5sJCbnoZPkqL8bvl81IlZoRld45gdUaalMMbQTnc4vdEYB7bdRrmCN/lAQIYT4DSLNqvk/Og6ROpBeqVB1jha73gMy0r2/TN3aDqc1WbHUsqIY5UqwQDU22TwYtME7rMW9h044+CYluo6ELqQWxk+n/5CMK7OVvWaHebsOHRm5SFi3/z5IV1GN3dVJSL8sHBVhGuSF54Cfmq+dQPzvebKhRk8c76V+tv4xOU41oyywRD3O8yzBW2JDDqKsc+/EXyydX5bbLg== 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: List-Subscribe: List-Unsubscribe: Function deferred_[init|free]_pages are only used in deferred_init_maxorder(), which makes sure the range to init/free is within MAX_ORDER_NR_PAGES size. With this knowledge, we can simplify these two functions. Since * only the first pfn could be IS_MAX_ORDER_ALIGNED() Also since the range passed to deferred_[init|free]_pages is always from memblock.memory for those we have already allocated memmap to cover, pfn_valid() always return true. Then we can remove related check. Signed-off-by: Wei Yang CC: Kirill A. Shutemov CC: Mike Rapoport (IBM) CC: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- v2: adjust function declaration indention per David's comment --- mm/mm_init.c | 64 +++++++--------------------------------------------- 1 file changed, 8 insertions(+), 56 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index c152c60eca3d..42fd0b822ca5 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1911,8 +1911,8 @@ unsigned long __init node_map_pfn_alignment(void) } #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT -static void __init deferred_free_range(unsigned long pfn, - unsigned long nr_pages) +static void __init deferred_free_pages(unsigned long pfn, + unsigned long nr_pages) { struct page *page; unsigned long i; @@ -1950,69 +1950,21 @@ static inline void __init pgdat_init_report_one_done(void) complete(&pgdat_init_all_done_comp); } -/* - * Returns true if page needs to be initialized or freed to buddy allocator. - * - * We check if a current MAX_PAGE_ORDER block is valid by only checking the - * validity of the head pfn. - */ -static inline bool __init deferred_pfn_valid(unsigned long pfn) -{ - if (IS_MAX_ORDER_ALIGNED(pfn) && !pfn_valid(pfn)) - return false; - return true; -} - -/* - * Free pages to buddy allocator. Try to free aligned pages in - * MAX_ORDER_NR_PAGES sizes. - */ -static void __init deferred_free_pages(unsigned long pfn, - unsigned long end_pfn) -{ - unsigned long nr_free = 0; - - for (; pfn < end_pfn; pfn++) { - if (!deferred_pfn_valid(pfn)) { - deferred_free_range(pfn - nr_free, nr_free); - nr_free = 0; - } else if (IS_MAX_ORDER_ALIGNED(pfn)) { - deferred_free_range(pfn - nr_free, nr_free); - nr_free = 1; - } else { - nr_free++; - } - } - /* Free the last block of pages to allocator */ - deferred_free_range(pfn - nr_free, nr_free); -} - /* * Initialize struct pages. We minimize pfn page lookups and scheduler checks * by performing it only once every MAX_ORDER_NR_PAGES. * Return number of pages initialized. */ -static unsigned long __init deferred_init_pages(struct zone *zone, - unsigned long pfn, - unsigned long end_pfn) +static unsigned long __init deferred_init_pages(struct zone *zone, + unsigned long pfn, unsigned long end_pfn) { int nid = zone_to_nid(zone); - unsigned long nr_pages = 0; + unsigned long nr_pages = end_pfn - pfn; int zid = zone_idx(zone); - struct page *page = NULL; + struct page *page = pfn_to_page(pfn); - for (; pfn < end_pfn; pfn++) { - if (!deferred_pfn_valid(pfn)) { - page = NULL; - continue; - } else if (!page || IS_MAX_ORDER_ALIGNED(pfn)) { - page = pfn_to_page(pfn); - } else { - page++; - } + for (; pfn < end_pfn; pfn++, page++) __init_single_page(page, pfn, zid, nid); - nr_pages++; - } return nr_pages; } @@ -2096,7 +2048,7 @@ deferred_init_maxorder(u64 *i, struct zone *zone, unsigned long *start_pfn, break; t = min(mo_pfn, epfn); - deferred_free_pages(spfn, t); + deferred_free_pages(spfn, t - spfn); if (mo_pfn <= epfn) break;