From patchwork Wed Jun 12 02:04:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13694335 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 0A879C27C79 for ; Wed, 12 Jun 2024 02:04:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75C246B012F; Tue, 11 Jun 2024 22:04:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70C026B0130; Tue, 11 Jun 2024 22:04:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AB306B0131; Tue, 11 Jun 2024 22:04:33 -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 3EA8A6B012F for ; Tue, 11 Jun 2024 22:04:33 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E5CEE1C0E45 for ; Wed, 12 Jun 2024 02:04:32 +0000 (UTC) X-FDA: 82220592384.16.A7A5C2B Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf18.hostedemail.com (Postfix) with ESMTP id 42DA51C0004 for ; Wed, 12 Jun 2024 02:04:30 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Hxn28N0k; spf=pass (imf18.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.54 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=1718157871; a=rsa-sha256; cv=none; b=AgGaxpL2sgQvqDh+RMSVlguN15bRcUyHPH2OKmH3ATJXQnexxhsc6WWN7SbmhIsWFzxI24 PDLtBU9XPBl5rbsi11HldfOuHv34k2iCvnRrAJIPLGTXP2aCCtMz+Ws1IQDC5CKF3VmVpm g0w+Vlh0y2rK4iSMYACBBcb4ANetuD4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Hxn28N0k; spf=pass (imf18.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.54 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=1718157871; 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=+U0eSK1Oul4n0Fl8a2PNnm4hje+EpTHcKCJWkt6gGCI=; b=57siWhTSksPwLL528oQ96uash4RzVURGz6yPL5IIe15eP/5eDY309r2q/k0Wn3BBqod9TK pP4C4aoLFOvxGiHadmPVWaRkF03Fy8X1UJTZK3W16qSJ2nI7BOQTPhWZcZpjLKZKI+RgEz boFB7uT/WNBo6oJ84KM2bfNprm+vRh8= Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-579fa270e53so2712917a12.3 for ; Tue, 11 Jun 2024 19:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718157869; x=1718762669; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+U0eSK1Oul4n0Fl8a2PNnm4hje+EpTHcKCJWkt6gGCI=; b=Hxn28N0krt9Rg96yYQ8xgHngfgpj72BXI8nSsj9+zNgQ14QP9BIYaJHLsHPhvT9azW 1iTe6myYECZ+whHwX6WXlQckqwBCV4E2+WR/v3dI+q3BOdU55SISoBrlGI33WnKLXlyu rXWZaai1FyEwdjE4hCeF/l9FkQNAJ7s3FpiyBr5B2fGfQsiNfNDwnDK0YLutfd8Grhqp onLKHl27q2T7pvzXUDTi5wq+V7yjjV/hJwKJANmtzUz70vqKYSwpb7TqR4Osoz2OTBo3 GNrVFvLYj2VwfpOMBd8lUnFEvkjmATnnqYRPm49bvafJCdF3PB0irgdUR8dh7agcVzY9 +TOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718157869; x=1718762669; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+U0eSK1Oul4n0Fl8a2PNnm4hje+EpTHcKCJWkt6gGCI=; b=Mbi+osBZF1yXGFyCqKsjWhMb5yW1jikjhG1I/OcxM9DCTeVdSShaBtGwSNPVdstlvJ r9e+vOyXzMjohLBxEKBDS/bwXjVyrFZf6CfP0ZKzyR9guANcTpGeudjvbtw9PC5MEJtN v8q00fv7iKVJr6rHI1TpTfc9+exj/3cBEnN6AlQpZWa7h5A2Hz8X9T3fBwUCrnEsQ1lv 3PphVX/0/AZ3g8O38S1oaJpBB71INuFUqtK8X0lpTR9a85PRPvT04LdhmqdF/aGYuEN6 ChYXKj419WefHJkVyFteKjtYKhmmaHUAxF9SHDWCVNdOQMavfzqDO4CTD7E68HlV5meq A8RQ== X-Gm-Message-State: AOJu0YxKnlJjvfi+HdNPd4ARRbzFHNdlt6yg7UUY5hhkOsF3aft8OuDW rAXT7caSQCY6PIe4OtgQaV48XxLqYkNDLOvibGA1mNP9TdPzJYnr X-Google-Smtp-Source: AGHT+IHN+KQbk+h88IeZV3WNuie4/xIpaBjAsvppJehOEo+wmma4R8XPUb6vzn+zb3H14vgCv7iTgA== X-Received: by 2002:a50:96c4:0:b0:57c:5f7e:d0f1 with SMTP id 4fb4d7f45d1cf-57caaac72f1mr437809a12.38.1718157869298; Tue, 11 Jun 2024 19:04:29 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57c80997d90sm4808066a12.25.2024.06.11.19.04.28 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jun 2024 19:04:28 -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] mm/mm_init.c: simplify logic of deferred_[init|free]_pages Date: Wed, 12 Jun 2024 02:04:21 +0000 Message-Id: <20240612020421.31975-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Stat-Signature: bhi5op55rws7u3pp9s5ruzf3n5xw5awn X-Rspamd-Queue-Id: 42DA51C0004 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1718157870-316564 X-HE-Meta: U2FsdGVkX1/jzjzOCCtaqmhi6ih5C0XvhlDFG9YYoBD3vyadGUjhlAOgDgWh73lnOgCP+wT/mduvW8YpfME1t6cE+k0R/e2Y4woFW8+gMLO85StEeEUCYd4bCJrW/c4iglgEKGdR1tYj2OjpMb8XNa6fz+6yhJFlMLXV8Q7nWnNTQLEdITSVTEPrePePhfv2cWss9hbEaOCfNGiBD1PG8CV2GECyZwPvI05uAAxUlmHMPFTFpOmA9v1O4aMd0uhDm/l0Xy9f2GzX+5JRUV9+5kWnxiSmhoOussXBJ0Lg4nu/WIazKIEY4vgPQdgEkHTWsNh6RqDnCscL/o8h1jIUXmVgGvTo02Q1C40zBTTAoWiiaBz8Nzg0diR4MUaj3g2S/aBvmQUnUt5Yp741DCE6+VQV6gsWcgUMGIw4Q5Hptnoqb6jH05gC03059L8aWKcfclnjNtCzMNe4e94y8PnDx32Q8wrmzTVyX7iTg1zVf+xbzZywihLWJ+nfFDj4MV8L9u9ZA0hfMc2EKMSQJqj+sjS8179hlbuto4er7upwgGVXv7rPaVDQ2mndWgDJFM7FA6BU0NivkjseDHHjG0Vkvr8IV3dtleb8lx36CwwxOdinDyKl/FHKSwADtV6y9blpENsGrRzQFx3adekuf4BN7lw8dhjN68HyT212NRww1T5WFnGukO+rkyhDd1DCL0LRMx5RNctgloVUgU1K50JGBNy1AE6K2ui/i3/8bmJpQoOzA1QQB0ikZDw2dDkkJRqnxuiNO0ZNk0+0JyHY54pM91cdVqlkyirO3n0+nKMdFI4EQkw1UaD6t99v3T/rALWY0cTCsbrNEpQh/8koKNnkOJGHRCh6719HkHoYA/tt66AV6o0+qQL/ZPEkTTwmYvGdYCTxisV4YIKf4IIr0G0rlVPV9Lo4qT56M7KV9JbsMqq9WUjXuRo/qYxY38hb4R842OqrbB+yUE5/6bVRV6c I7J/6r86 6s8d8dee4UlQ9BsnWwaT2t6y1l8McVTBXZ74u9qUUcZolGib8ycE4wX/y62dqzbBJ/POxDo+0gRhCtitGh+ayNaA4ql3ZUymGdzISMcng/HLNR/aSnubdE4obXHeRwFgOoPr9sGwqYmkOkxhSwPCZYmJQ2uRfubwy6mNyC1WS7NtfGYlbetpcvINJsAyHVziex3hya2VUHZn8jF6H+xAKAozQRd0wTuMbzObIsCwDYDsRClCehemedHhzwaHQovwIUSvBw2JXnLi7enMdcxbBKSJ+xEAkHABGXaPPhgs0zQqWs16+xlL766TnKk1QuB8vvGHuTfMagILyNVUH3D+pV9rDq6XoXEI+kkMA79akpNIXKlhsuPdjw+YH/gU2beJ/fqNuB8xBso+mDLDFl47Wsr+dwd4aFYIhzfTK5PTI70q8Qfwlc3/+XO/WyfjdxMDi+zZ+wWRNkR3EU/Xo6d4o91F9hDaFGT9VVoygPWg+uwvDLtSY8K3j8K9qhNL8cYeAWVxiVVxBwhcJ7Vxd3vuJ87rk5aHgt5pSeMm5NJdtmaQNqTY+sedc1PHaHpPiQcG6lyXX 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) --- mm/mm_init.c | 63 +++++++--------------------------------------------- 1 file changed, 8 insertions(+), 55 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index c152c60eca3d..63d70fc60705 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1911,7 +1911,7 @@ unsigned long __init node_map_pfn_alignment(void) } #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT -static void __init deferred_free_range(unsigned long pfn, +static void __init deferred_free_pages(unsigned long pfn, unsigned long nr_pages) { struct page *page; @@ -1950,69 +1950,22 @@ 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 +2049,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;