From patchwork Tue Jul 9 02:36:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13727181 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 A233BC3271E for ; Tue, 9 Jul 2024 02:36:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 220306B0098; Mon, 8 Jul 2024 22:36:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CE2C6B0099; Mon, 8 Jul 2024 22:36:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 095FA6B009B; Mon, 8 Jul 2024 22:36:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DF78D6B0098 for ; Mon, 8 Jul 2024 22:36:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8212B1612E7 for ; Tue, 9 Jul 2024 02:36:25 +0000 (UTC) X-FDA: 82318650330.13.185079D Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by imf19.hostedemail.com (Postfix) with ESMTP id E15EF1A0012 for ; Tue, 9 Jul 2024 02:36:23 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=egyH7ntS; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.45 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=1720492569; 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=Y4tyZfQZh13n8WJqaNDrYKT2RH1lvdWq6QqkJMhvWhE=; b=paRYlPsh3BRQ8zT1rDqHYi8PwUqeWvULkSFuRMMIiUHQepqhqckg3W653fyhCNBfGKspQG 2p2gejrwaZNp9P1zEVnE4Hrc0WtmaJphcsBq4/E3KiZYnz++lyoS0YhIg97x/USmbBu0dZ crEupQ7cdZ8cmHIejuwOVwpCMywPCjM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=egyH7ntS; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.45 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=1720492569; a=rsa-sha256; cv=none; b=B8m+8RRf2pEkl+5gXTeFx5Clji/2XmBWpr6LrwazWrep7s1sDrjFutKoQ7ojgRILLM0bls jMwjigDh0QyJpJtTjnetzhy2GO9BdkLPPdEKmYmINPDFQWNMHEFz1mKQXGu15kDC9BCVvk t1QaRt0kPt1w3WRsFTz7ddUGAsDbvjU= Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-58b447c5112so5152971a12.3 for ; Mon, 08 Jul 2024 19:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720492582; x=1721097382; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y4tyZfQZh13n8WJqaNDrYKT2RH1lvdWq6QqkJMhvWhE=; b=egyH7ntSw7AgNTzpCE0Ml4uoQgoLeeDADvRY/tuuGyezY1vMrjGzJGVJI2Tg74cbNa 7QdWFV7g5sRYpKQfG8jvzWKQKMFNujOU5/Vu6463EIRTBeH0HQb5v9QhTkox8sZT/V8V tvXUdKaPRR3lgl5T/1p++kiFCO/YP3p7EWSlv2LunFkLRq6SRLrmZfgS/zTOeSbnabAw jpmX5AQ71SE+P/bCJ8jsGhe+vuulx7Mf2jxxLHHqSOPtDUGq3Cn3g7ELdXHr5gfktGbP 9fsiJU2hZ5X71SXoJzwJZCiOg5322SPaaC10MaPy0o1C22I1iboE6PMs7oQ2J7+EkbFZ x5Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720492582; x=1721097382; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y4tyZfQZh13n8WJqaNDrYKT2RH1lvdWq6QqkJMhvWhE=; b=qQo9zgumoq98X+tC0pY8MbsZ/Md0MhJg1mYBp+AyWhYTIXxg3vp6Y0LREw/SMPm/ox kYj1Ug50goVtary3R8up1FtMDBoHPa4Gr/KGT3dWd4Tlqm+Iwl229ZQs0Z0lOHIqdw8v 77ArJ/7eWW4FOUe2W9cFydD9+LGmfcxAKUFnYcmxcjmTJ1QTUat4x5kFf2FXlq39womv OBHiVy7d2+ZDwyG57p3eODzOV8+XF7xs9plO1OFy5+6ORfnHQmmEKGi1evQXcuJuwuOQ Y9gm469Akgcd2jbryQZNiYg9YeoDARyanV/67R94eugxFFs4jbMJj+hjgEVg2+FAHIo/ cbqg== X-Gm-Message-State: AOJu0YyDhntpDr02QGHa4vHXzmCniEvtWtIXB+4vhRWi1oHfhefmNmEw rviMGo32q2CVFp408QUwYWYXSfe+taoc/Gi4KEzBcYHVccFPkiVS X-Google-Smtp-Source: AGHT+IFIX/IbRXxrlYwyIgLKfOuUr+XDE9CmJ5stAxyz6jREZ2FOOXNBpDGe4TNlg6VoOPuhPSALGA== X-Received: by 2002:a05:6402:33d8:b0:58c:f5bd:eb65 with SMTP id 4fb4d7f45d1cf-594bb674df7mr651675a12.22.1720492582055; Mon, 08 Jul 2024 19:36:22 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bba54ab2sm510868a12.3.2024.07.08.19.36.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jul 2024 19:36:21 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, tandersen@netflix.com, mjguzik@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang , David Hildenbrand Subject: [PATCH v5 1/3] mm/memblock: introduce a new helper memblock_estimated_nr_free_pages() Date: Tue, 9 Jul 2024 02:36:07 +0000 Message-Id: <20240709023609.21332-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: E15EF1A0012 X-Stat-Signature: pgxd8rc7qeymhtoau8mk9xtj1wn6w8rq X-HE-Tag: 1720492583-173856 X-HE-Meta: U2FsdGVkX19StX6BzIaO9urBcBXpwzFFn6YZ6GsLzaFUl5volZqA0o8d7/IrgNBtXdk6dcBwAL4pdRYj7Tfb3GvZLoA6t5pS0f1KbcdM0ZXqpSLfNPl2tiZJzWKKysrjv3igde2qN1Ts/eVXRRMNz0WC6tY8+oLFQPrOzwwkSqsbwVxfQ1LIpKHqAcrZCJPtEM4l7S9TXXHSxrlsHtet5RMPCiKkzzzsa2qC0rPQsaYmfH7bnBuHwdoDbrBanXVZsSZLlktqc1ZmTHxN5xfVX8VLehQlxr6i3l2WTTZ4QDlYnJnKymoOjituJRS8IVK6jus40XKIvzXHJC40MEYTYwvkfGt89DA3fcmokz/erikVewj/hvAvTY4PunmgRIsx3Wd+F/ccfzUz4s+ZxpviDbXnAwR8oI5rLlKBmAl/M6cy5QAcsVeyhjEQIwW/8UXRgC7FQB3jjzrho7hmcLZM1YyVDYO2x9ETUEjzQlVfLYnE02RIiBLiu0FKIYwovV8WplJ6wDVjCPTVXsqbTg5mBNdu/LUy2BMUcGAd26HbmihHZ1JKAl0xdBIMs1YDYP+y7s3oxdCEHgZKeT+4Pz/izA+/16T+DdiiFemAZ+pSn0OE6pYtxJ8U1G822bEkqrXpnZlueJjyu1Ev2E8zv6F/cZ2hqG6BhLMDQVYEAv4bX2K/SxLf59PSPzeJVHQ865if57cfdeS29ZCejgR4EevMR1/PLG9axePuXqbPctJJeqkKrgqCkbXQ7WY8IPxJMDB3/kxPrVCgdfN9Kx48xFHxZPlD0lENXAuhB9KoA5wfmIRwOhOweZ13hC90rh+1xb/x0pk+OzySin0aQBaiP5v2cdktorYL/RNI13u05RN7SJpavk9CGXg3E7Dqx9jzJrwQT2ACzub9fhP3Syg6elkXeNxlHjdo6/8B2L4LRYX+YUX0WhEPkCo7uOyI3XUKRCe07j/pmHxplFYYjtTBlXX d995m1Ba DzRiWft6W2ob6JVDOWnzbawcdEOMl2hrxM5vm0TDEYe4Gc7gV8sKOk7PZ25xMfzDLkD2kq+rDcVqGTw2HBnGSSmjR4Ka3nMG583jT7P5W5b0vDIJxRcnSmU9HPZddsjEMnZB2+Fy10qeO+33V8kOVgoDUwUPLUpjCXwHcBo2kcDRP4AscMR/BJ8NYuww8gACZRFsWeGSIPyh9urCJitTZ1bSKx9wWo+HQ3Xhki7ccfyF0Af9SqG1dysSPuWHokqK/13eh6I6bdmlcLEne/c7f2yewTL00/UWKY5yMm6xFSjyegViMtU0x5mmDJgXN8dZRLAWWjzCE0jQUAiHn30L3xwxYKxxEUF5vIQWFm3fsSjVU/EYzJwCytTpU4gH2CbqYxnfEGU6Gp4/XxK4BdRyVq8rLvj7YAkZSUGHJd0XrOs6x5/xiMl8E8nFbOdn3xxWpmmBPZytZeRduo1mAUZJfQdv1poGvTy1t2wdt+KZ5lWR/Co8= 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 Reviewed-by: Mike Rapoport --- v5: cleanup the stale name v4: adjust comment per david's suggestion --- include/linux/memblock.h | 1 + mm/memblock.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 40c62aca36ec..aba7ed9f2531 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_free_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..ae8e58fc4e7f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1729,6 +1729,23 @@ 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. + * + * 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) {