From mboxrd@z Thu Jan 1 00:00:00 1970 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 D908AC3271E for ; Sat, 6 Jul 2024 01:28:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B1BB6B0085; Fri, 5 Jul 2024 21:28:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 261786B0089; Fri, 5 Jul 2024 21:28:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 129236B008A; Fri, 5 Jul 2024 21:28:11 -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 E3D306B0085 for ; Fri, 5 Jul 2024 21:28:10 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 77B40A1DC7 for ; Sat, 6 Jul 2024 01:28:10 +0000 (UTC) X-FDA: 82307591940.17.CEBB83F Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by imf22.hostedemail.com (Postfix) with ESMTP id 83BC1C000B for ; Sat, 6 Jul 2024 01:28:08 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=McGym1v7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.54 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=1720229258; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dezBeZYBfU1/Z8rbV7e63ypFbBRAlUgUO3szpvjxTnk=; b=Zpyh+h2e10hElp+T6+sJxzX9JkDBZnNt0Kf4dtcqxmxfiTRQYwVSrXCiCw0Jz7EPQJleCU rV/C+2FTFMDeLPbHpKaT8mGOqnDpkoNu2NYAaG1dgFUu2yrAbOaXlYGUOWVNqkThfJyU32 7IQKHjgnszAZ26aCK8Z620moCUw/F3M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720229258; a=rsa-sha256; cv=none; b=WNAA72T4RstscejMMB5S+rkHAIyeSo0Xm4tufhRs/E80HmH5tfr41FKJvTCzuESCWrkLhk ZnirqsecslYi7Y51tErdFISk5bOOFnebExwgYar114schxojI617QoEOoXxzN8o0iFk9Uh B5iyI2u2sB9QeZFBSh618wfLUjALjx4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=McGym1v7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77abe5c709so272503566b.2 for ; Fri, 05 Jul 2024 18:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720229287; x=1720834087; darn=kvack.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=dezBeZYBfU1/Z8rbV7e63ypFbBRAlUgUO3szpvjxTnk=; b=McGym1v7mGAcHZ/sjuT9w3ViWSN096+XXvqWb5606cMl3FfDo/65V6aJCiaw9TTDUk NKC9i9JOjchU1UzgXWjLxDDJfGxWhKkidVFkHIfrRCFf1qnmmYNLzgkvTmSyhoxOfSH0 5aVMdhWAmm8+J5+8ctpIkc4FVbe5u0Jh0LYzN5ZlXpA1AhxPR7/NhZ0KXLEyBYfvjLxz LOmFy//bXP1FfBhyQB+Fb81jP+ZNtn8cAGYXZt4KeqO/hA08O4HGTunVnjdjqg+qanI6 gWlp+fj2H5hjOiUtCbHnHgnzYnYDj9AR2jSSE7VvuR7Aol5LrACCfOdgPkRktzdi86c8 36sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720229287; x=1720834087; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dezBeZYBfU1/Z8rbV7e63ypFbBRAlUgUO3szpvjxTnk=; b=GDG2PqQa72pSqUqzSg63WZHP6lhCYoDV4vJ9R7uHrsVd1UKxxIO23WXLZnxTUfo72K mCALSBNlimU1JYi1MnjFF4WtFO2eenI9xyQg/sa4XantJkSmjXaC27rGc3WhmzkZPN3m hWX6oHUGMPrTccWdh/NbDlBpGh07mbiVmrg16vdO72nRX1alcEDMKusRGGBf5Zu9E7rU SaIR9viXJcM3KcZl9UCusbZDNV1OFl7XpsBspXO5/xVasn3+7zmIq46HCQ8bBXkKoY7e 8pUEnBquR+P11QyCTI2hjq7g9FW3HCFg9lKkVbYA9qDQFbEieQohva0i4WNmFkw4qqNs eaGw== X-Forwarded-Encrypted: i=1; AJvYcCVceUFh/TtQUyfk4v0d40SxDS2GXRiyDVtomMOX0xKAGKlewM/FcCFY28XTW9OnRf5vAC6yWiyNMPJFTSJRP2gdPLQ= X-Gm-Message-State: AOJu0Yzb6jEjJO8HnbqSs02/o9qPZ8WVJy5Ou0GHXplD1YN0mvKUwjg6 VFWuRHB6ahqOvCYBLHhoZ6Q/VkBuOQbXL7HoSFb8S4yRYTl+gjRW X-Google-Smtp-Source: AGHT+IGJL2ZXApYLOQQK50g7hYRvGqRO6fAVuvhBD7w9sgnqw2wDu83cJkm1L62jaCQwTV7JQxMZqw== X-Received: by 2002:a17:907:97c8:b0:a72:6b08:ab1a with SMTP id a640c23a62f3a-a77ba711897mr498694466b.46.1720229286635; Fri, 05 Jul 2024 18:28:06 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72ab065651sm720670366b.126.2024.07.05.18.28.05 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Jul 2024 18:28:05 -0700 (PDT) Date: Sat, 6 Jul 2024 01:28:05 +0000 From: Wei Yang To: Mike Rapoport Cc: Wei Yang , akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, mjguzik@gmail.com, tandersen@netflix.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com Subject: Re: [PATCH v3 1/3] mm/memblock: introduce a new helper memblock_estimated_nr_pages() Message-ID: <20240706012805.uuvysz2qgapgqj6p@master> Reply-To: Wei Yang References: <20240703005151.28712-1-richard.weiyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 83BC1C000B X-Stat-Signature: qqxnfpx8qdehu9d5hh7rghuxd3ym5w6y X-Rspam-User: X-HE-Tag: 1720229288-359634 X-HE-Meta: U2FsdGVkX18S4qH9HsSg07pHcVuExWByJg0dtdfY43eq4W6LcahF59Wf3GNVLaXy5AfOmsYXJmY53Z/SX8x8xNAEHeWyxCLLk9eyiBy2UZx27o0eqRyjaJT2ZTWWJEQ7T6zoN5As9LqWV1AHCKtTbGnaKhFCTocJqf69+4sVfEyLAsT/j1CyXioGJHfUor+rCbRCHmJMirF2ElcfUKjNlTAjluIpl63mXXc/wITz0eShO4BfwywJxQ+D6w/4D1rUTw/0gACYk41i/lg6TJuLFNVnmRK8sJcJDKZowapAWZyzJborCl33qvxqnySS9RwdXRVa6J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KbfBl4gBxAaoSsNVYO4XzNolmtST3OyNfG5382U8d5vZjeslmf375lsFFkOvSqxWpTvr/gZrB2o/cH4wRA9P3/d0UhCj9kGbuZX+q37nAra4J7fsnMu969z82AjAG03T3oLnZJekSLwkjr76KZzcuy8q4Er0go+MHU9SSmuF+gpl0HjAA5BkR/IQcDbQR9rtjuEKsYDUo/11e5KvWl2Blkx5tw7eEC7eUiTRrJQi1WQ/TlPPERp7ngSjMigguYeJTXz9moBUGq8PSJ+H3G 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: On Fri, Jul 05, 2024 at 12:09:48PM +0300, Mike Rapoport wrote: >On Wed, Jul 03, 2024 at 12:51:49AM +0000, Wei Yang wrote: >> Instead of using raw memblock api, we wrap a new helper for user. > >The changelog should be more elaborate and explain why this function is >needed. > >> Signed-off-by: Wei Yang >> --- >> include/linux/memblock.h | 1 + >> mm/memblock.c | 19 +++++++++++++++++++ >> 2 files changed, 20 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..c1f1aac0459f 100644 >> --- a/mm/memblock.c >> +++ b/mm/memblock.c >> @@ -1729,6 +1729,25 @@ phys_addr_t __init_memblock memblock_reserved_size(void) >> return memblock.reserved.total_size; >> } >> >> +/** >> + * memblock_estimated_nr_pages - return number of pages from memblock point of >> + * view > >This function returns the estimate for free pages, not the number of pages >in RAM. > >How about memblock_estimated_nr_free_pages()? > >> + * some calculation before all pages are freed to buddy system, especially >> + * when CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled. > >I'm failing to parse this sentence. The return value here won't depend on >CONFIG_DEFERRED_STRUCT_PAGE_INIT. > >> + * >> + * At this point, we can get this information from memblock. Since the system >> + * state is not settle down and address alignment, the value is an estimation. >> + * >> + * Return: >> + * An estimated number of pages from memblock point of view. > > ^ free > >> + */ >> +unsigned long __init memblock_estimated_nr_pages(void) >> +{ >> + return PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size()); >> +} >> + >> /* lowest address */ >> phys_addr_t __init_memblock memblock_start_of_DRAM(void) >> { >> -- >> 2.34.1 >> Thanks for review. Is this one looks better? Subject: [PATCH] mm/memblock: introduce a new helper memblock_estimated_nr_free_pages() 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 --- include/linux/memblock.h | 1 + mm/memblock.c | 22 ++++++++++++++++++++++ 2 files changed, 23 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..00decc42e02b 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1729,6 +1729,28 @@ 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, 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. + * + * While we can get the estimated number of free pages from memblock, which is + * good enough for the calculation. + * + * 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) { -- 2.34.1 -- Wei Yang Help you, Help me