From patchwork Mon Jul 8 01:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13726112 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 6B4E0C38150 for ; Mon, 8 Jul 2024 01:00:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D577E6B007B; Sun, 7 Jul 2024 21:00:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D071E6B0082; Sun, 7 Jul 2024 21:00:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF5AD6B0083; Sun, 7 Jul 2024 21:00:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9C9596B007B for ; Sun, 7 Jul 2024 21:00:23 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 17D69A0F74 for ; Mon, 8 Jul 2024 01:00:23 +0000 (UTC) X-FDA: 82314779526.21.EA5C45C Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf20.hostedemail.com (Postfix) with ESMTP id 5FE8C1C0007 for ; Mon, 8 Jul 2024 01:00:21 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=f6KkLV68; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720400389; 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=H3NdiAyId3OkrVUGqOgRgAW66faEghB0UHBtTZW80kM=; b=k9wukL6rDoyDyVwdmm5fzUVUPvYDCKJ7luECb0jIU67k+vC5G2sTBdzrE/bmTQlGDTUuFg yEwVJWPfAeJKObdvXzLVOx4NqbgsDO+7LqMejhXDMql0C/Kp48QK+GBHskTHq37IsH0IAp bV0Hdostmc7iU0UFWgt8TS3IKZw9aXk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720400389; a=rsa-sha256; cv=none; b=oKKLlXKOkzEoNc65kk5pWGzD09m1OSMRe61HhY0XrZOIH9Zmu9Y8xWY+yEBk2gXAxLGyXg 8lKo8J686qkmonev8eIcE5hKMsUJ58LmByaqvpOSmT1lv1XjxpzXcvD3SPze7FvwEgWgD1 mlm4zZ1FwA/pit0koRurQW8c+Q4wYNE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=f6KkLV68; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a77d9217e6fso208507666b.2 for ; Sun, 07 Jul 2024 18:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720400420; x=1721005220; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H3NdiAyId3OkrVUGqOgRgAW66faEghB0UHBtTZW80kM=; b=f6KkLV689G8IwClGyeygANUIid7X1z+quBy4yHh36N5JwJOmSqWnqkDefKFtD7eZQ0 8oljK9p5+XigNqWRXvr9KbWpCPkrw0IGRHdyOnVfTE2ePF7BJ+OD73+oNcdodVx5iDy4 JSA4EGrUeGlJuk+iYQtCK+XGXcDRK1iGruYEv66KhlX6yMkIzW3Z21pcgFEIm07dlmbh duGPGRcqvYNDGz5sQH//j7068AX14noFg4kAr38rxBHttfTpKfRR0xQ7yfItgu5OJKiu dAfOtpRKrQs/I3YHQgofSdYBSCfzqWbD8iKp6D62jBf0wn3Bpb8T+vIcDaJzKxxM3Zht Xi9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720400420; x=1721005220; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H3NdiAyId3OkrVUGqOgRgAW66faEghB0UHBtTZW80kM=; b=R8LBTvFNk1lgExK2EUBzgh+NgGkhDjPjsJtWf95CpGzx0fUQEfLbZs0iYPENq6JGNl 6r93Hvd4pPVTqA1/5S0rLDCs7Ksx6PeF8KbYW1V53bW7b3NkwyQqihMrkAfqJMwGrupm W3s+8gq9UOIQoHHoJjb8Aa1k64upUsxjttw3WHP23cCpygBGdjJpAvjDpALyMiOPM08H +LubvrO9wQOH7fCNcevHmYY23WKS4l7lVuKUwWyFbQ+5C+jC+gAfnnsykstc2DPyooCp zJ9nzS6I6T2NqF9utgWdsQyVqnJBih2lmuuY3rsF9sCpEzIVTMLs1TMJgEkotP4dB8Gf YfYQ== X-Gm-Message-State: AOJu0Yy49Ldoy3N5gLh8Y9j5H6oVd/rw1yF7EHcNKPc1x05kAa6zN5Tv OEe2FxD1CwigxSaPmMZls5kNoCwzzSGP+QKunv/TUJlZcM47LjPf X-Google-Smtp-Source: AGHT+IH0ggJbCGlEbdNIAlUNjEkV2/8ro0xOqCXLERCyOHyPaxPfuby2ZfgoB96xxYv+uuaOgXO/Tg== X-Received: by 2002:a17:906:34d3:b0:a6f:3155:bb89 with SMTP id a640c23a62f3a-a77ba72759cmr734858766b.70.1720400419585; Sun, 07 Jul 2024 18:00:19 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a77e3f48abcsm175087666b.186.2024.07.07.18.00.18 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Jul 2024 18:00:19 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, mjguzik@gmail.com, tandersen@netflix.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang , David Hildenbrand Subject: [PATCH v4 1/3] mm/memblock: introduce a new helper memblock_estimated_nr_free_pages() Date: Mon, 8 Jul 2024 01:00:08 +0000 Message-Id: <20240708010010.32347-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5FE8C1C0007 X-Stat-Signature: iwyyschpwt8x1qgkynpd81rdrbm1okjb X-Rspam-User: X-HE-Tag: 1720400421-329946 X-HE-Meta: U2FsdGVkX18zYfFSm8pgOW7YEFZE1yAF6sYPGr5SBirIDGcrWKufEyuErSTR4DKlxhvj/DM251HzExB2PiasPYul06auXW5s5XMfIDKEWpPPp9tQ+j3ESJx5IBw78RbpaBUT61cN2Qizck65KJWnY8PTY/IdcpYz+WaYUYf2umIBQjyFDUB+cPCwoFCIjZiNch9Lyz/23f0NRX5IgKnW5GgPYvZfQiPOxg9wPVvbAbJwnse6j4HzC4QNJu0CWJLJ+c0u+KWybJvp4q37S3lA2xe43QduBwcbp+sF+mGu11oc1k4NLwmjhYPsTyF2/yXvxJ+qeZwbpMbKJdr6PxUtFgNYzQIzWAP0MkHJiaSszIzJ7ZAffFMbYGREx1EJi90Iind/bytmSw6/lp10m5PZOpefUE5+7Wvt+961TkE5NlK8sJTcZurB6kU5mV/zkMc3elHQGGqlHy8zbMGt1V8JrYZLNopTNyLR4Pe7zmXfFhWeYjjbehTxJe6JSGVJTz84D03He2+OVSLXA/ss+DTpO2R7RGCU9mn0lWlypC1umeAf3b2sacpPmgsWTrOBSWzu/Q0eWj/seqoMYb728U78YAbCKZgXAzf2Om+QvOkN4rYfGKjUabdFL0rKV5V3Kz+/0/WD5KOi/zrg0V8OW+wz3rVb8v3lA1KwcYCn5niYV2CdpT7mTU2HKu+//28ymMV9IM+qHdVtwoatgQQhk/HvhQbrla6h0qRjVTvwLBdzvDnQkfO3P6GtgW+o3pP4IMAi2GDLmvnyoCmHzeyKiSGt54gBGdgEEno746HQjN5ESokhlHQs2FdplAaj13DJp9Y2eaqhHR9X4gpIE0bGDVo0rOyjrtMsnMtj8nyo1CT2n76Yl4kD6CaunfZ56PQGzhxuXTuL/+Dimg1uWF5W2zWEBj4x/iv7mDDz2kERK5ZcKejB1fm6wOngCVG5NjuSuCOA6Lyz9x+PeOdvOMDc0k4 Oo3mBc5N 3LFPV9oEcxpG6dcz5sxGoMrRXvsoceU11pf0aWhWoHyFNFHih8ZYdK+ONJqC5BIK8p9ZmuTK/WAosx65Lq8TbxEuuScxai1PwwdZywPrXWcX91ReiAuilAqxmgYR/1rqrGFVQYb79n5owh6uqPZI05wAVka35OatMaeN7qxotNOIcnlO2FEXvPap25Vw4C5HUpkDVv/BhltF/drGRVwB6AuzV1o2n01FojwdJuZOz9yYnFuEwbmi3on51MQfOWSNOwJR+KoDKEMWP1qEeoZVQ6dw6+zFzXvum/dp9YL6NIsfub45cNw/MA+4D6/6kVMZbZ9eSIeh3LXr3v4QCSW9fB9JMgdbL5WvwrIgOuB2FphzOG69bNa/U9/Z3cwnPdToUuAqXG9LdG1t1dClY8FsPW3D2/EDNBsi7eR31Y1rTo1eKP4UB4w8Sr8Hb3dJgJkZxWlFnWvqioc39wk+dkPjTysQ6cSNBqSwuCHR8IAH0cyOzR3g= 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: During bootup, system may need the number of free pages in the whole system to do some calculation before all pages are freed to buddy system. Usually this number is get from totalram_pages(). Since we plan to move the free pages accounting in __free_pages_core(), this value may not represent total free pages at the early stage, especially when CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled. Instead of using raw memblock api, let's introduce a new helper for user to get the estimated number of free pages from memblock point of view. Signed-off-by: Wei Yang CC: David Hildenbrand Reviewed-by: David Hildenbrand --- v4: adjust comment per david's suggestion --- include/linux/memblock.h | 1 + mm/memblock.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 40c62aca36ec..7d1c32b3dc12 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -486,6 +486,7 @@ static inline __init_memblock bool memblock_bottom_up(void) phys_addr_t memblock_phys_mem_size(void); phys_addr_t memblock_reserved_size(void); +unsigned long memblock_estimated_nr_pages(void); phys_addr_t memblock_start_of_DRAM(void); phys_addr_t memblock_end_of_DRAM(void); void memblock_enforce_memory_limit(phys_addr_t memory_limit); diff --git a/mm/memblock.c b/mm/memblock.c index e81fb68f7f88..26162902789f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1729,6 +1729,26 @@ phys_addr_t __init_memblock memblock_reserved_size(void) return memblock.reserved.total_size; } +/** + * memblock_estimated_nr_free_pages - return estimated number of free pages + * from memblock point of view + * + * During bootup, subsystems might need a rough estimate of the number of free + * pages in the whole system, before precise numbers are available from the + * buddy. Especially with CONFIG_DEFERRED_STRUCT_PAGE_INIT, the numbers + * obtained from the buddy might be very imprecise during bootup. + * + * While we can get the estimated number of free pages from memblock, which is + * good enough for estimation. + * + * Return: + * An estimated number of free pages from memblock point of view. + */ +unsigned long __init memblock_estimated_nr_free_pages(void) +{ + return PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size()); +} + /* lowest address */ phys_addr_t __init_memblock memblock_start_of_DRAM(void) {