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 26946C38150 for ; Mon, 8 Jul 2024 00:39:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94D656B0083; Sun, 7 Jul 2024 20:39:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FD3B6B0088; Sun, 7 Jul 2024 20:39:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C4BC6B0089; Sun, 7 Jul 2024 20:39:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5E3666B0083 for ; Sun, 7 Jul 2024 20:39:19 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 049D0120FD2 for ; Mon, 8 Jul 2024 00:39:18 +0000 (UTC) X-FDA: 82314726438.08.9196B00 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf22.hostedemail.com (Postfix) with ESMTP id EFFAEC0016 for ; Mon, 8 Jul 2024 00:39:16 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DDvY63AG; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.51 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=1720399127; 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=iuTbglylbJkLgy3nA6Vq1cwMPZqasK0i2Sp9zGzr5H8=; b=wpUrG6ZgBVVJ/jbP8eb0toeoV5os1enAV7nL0mqPGQqDL+f3/oOkUlHhhewbGSinkiX24b jopkFCn1DQ/toc/6KLLRXC/QdIod5V6i/VdvL/X6veYFGvq7bXNCjqXAbhUnKSYTWr1PF0 VabnXDazrmOBZBaBeaL3VTob4g3lVgA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720399127; a=rsa-sha256; cv=none; b=QBPfsDg3RX0NwMileQjrkxut2wlF7lWI9/ewziEyxQHuECKZMGueKdfX3ILMUyOOT5C7TY QuU4bYpc619q60y5Ach53PzWQ40Pxk0195ymc7eSvxrdfEIPPbdo4uU65ww0SvkB1VKv0V Xs1qcKMVxm1V//Is3kr9BKrKgBaPLOM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DDvY63AG; spf=pass (imf22.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a77d85f7fa3so322846866b.0 for ; Sun, 07 Jul 2024 17:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720399155; x=1721003955; 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=iuTbglylbJkLgy3nA6Vq1cwMPZqasK0i2Sp9zGzr5H8=; b=DDvY63AG5WjfJ1/aThXk58ZF3jPGgBFDyNUGlGMZGAXbHMPuBS5zYLCqarQTlbnpeH BlNPY75yFHlk6jbEAAAsvimcyt8U/gy86V6Plcdo9Ij0xrfeGP9wYQSTyLkLdUPcU+UB flaxKOhCyxnxkCla/Hq1TaGRU5fZdDuYRgudXM5tXzZsWqYHPS72PG+9IR1soByfpB4J Ls0gcRRhjMsp7Egk/X9w9lmWxDXVvWCPCA/iNyDdabMozxd7C/7EHS5NPybHqs/zpAiw ITvy3MKkBNJqvEZAZKkHqDSjpWz5i9XrcY9kzJrtBvFtbjdymLhyy9aOBR5Slb8YFqGy tfgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720399155; x=1721003955; 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=iuTbglylbJkLgy3nA6Vq1cwMPZqasK0i2Sp9zGzr5H8=; b=uOl+Xh5gHyst+C+oEYVT2Us7oVkEtltKF6e/izcld4yTnMIxYruzOKLldRgTPpAahF C7GY4pmJ/6jIA0cW9h0Z3+/MvUB9z1TUpjOPSrwiAJkIhUmn5kmUlUfUgFSaT3QYgN0U 9zkbNVed5UsQzAjJy03jeu/O/B7ddJcH+Gq/YyvyLdhf5Zl917ITAK+qGt/m+3eCuF+a dp4XAbZMXOuyVJpi6cCUDOZw097otxgHBBKzFqUrYa2iTTtIo7bvqHsrcHIDQyS6iJ2e MKkp80ErYDknEbic2jDjK3sgmPLrJIdr8bjBR5MRQZh+nEJsoLQ3lhP2Tc3HQ3OZqqPE SWbA== X-Forwarded-Encrypted: i=1; AJvYcCWRxWB9zSKmZUerFCsVOz5LuzPeIDqeCmmBwsbYyG0OQZgncJZSZ6/YMb7i3V3tMZXVXzJK8tBzMP5g5m68FgCo2Ko= X-Gm-Message-State: AOJu0Yx3q6g5SdZIN7OUapUu8zJ3POy41ZZcM2+sw7q2nVniOlAchYAN x1qp/0mENERr6BHGmflVUGKN/h8onKAd+zdrmEwugYrXvklUb+5p X-Google-Smtp-Source: AGHT+IEZYkuoB+ZC6xUPDOzY48LVIjj5y7t1QTXvwb1eeL6uK5oRMd40fxkQrc9e+5upf8vNuXBYNw== X-Received: by 2002:a17:907:1189:b0:a77:f5fc:cb61 with SMTP id a640c23a62f3a-a77f5fccfaamr182021766b.0.1720399155008; Sun, 07 Jul 2024 17:39:15 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a77c0dff4a5sm314833266b.27.2024.07.07.17.39.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Jul 2024 17:39:14 -0700 (PDT) Date: Mon, 8 Jul 2024 00:39:13 +0000 From: Wei Yang To: David Hildenbrand Cc: Wei Yang , Mike Rapoport , 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 Subject: Re: [PATCH v3 1/3] mm/memblock: introduce a new helper memblock_estimated_nr_pages() Message-ID: <20240708003913.dcf7sfklrdpyhom7@master> Reply-To: Wei Yang References: <20240703005151.28712-1-richard.weiyang@gmail.com> <20240706012805.uuvysz2qgapgqj6p@master> <9f38e4f1-0ad3-4cd4-bcb7-5ec287859051@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9f38e4f1-0ad3-4cd4-bcb7-5ec287859051@redhat.com> User-Agent: NeoMutt/20170113 (1.7.2) X-Stat-Signature: mijhqww8csb6sj4wc81icnhhc6xjnoq3 X-Rspamd-Queue-Id: EFFAEC0016 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1720399156-585806 X-HE-Meta: U2FsdGVkX189X6cfm6yw213F772Lpk18ERkQJsnheK1x1+w0Wnux7WJjG4LOc2prpnSLZYauBSHePIQ0sP+YddTFZMP8wdqrqHzyod0kQBw31Tszn9KW6hKogYK+PLANWaH67JSxC4WNNzDpizaSRLlZIlFoGZ1lehquijfIClhB0mM3mtK40E4SSce88z9HGyq+ESM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jt/X+MprgfAYEwdjPGoZoGVNUs0n2aVd7mPmh87bR+oVl4/9mByKH3e+GbhNe3OCKLTgQ6hI4IgBawrQBKvmI/FGxicwyLL9bFBCrIPGKgC9Mj8MaSbD3B1ez3hFxhopFZyr4rzzLDD1BrMsJieShXYfw1mqGh2Xe/iOy2TDYJzQf6dkiRJ+2ee+nmS3iyX1dNIh38HjSFS2PzqvmT8xJWiuCTnEN5KXJ89ddg1llAbP+frI+x2vAPTfQlVVoLgJ6tc6RM62BtdWHyLJvVvwxXfQHaZXS053XupDthC3J95z52KOrE2Kw6+ZTkxdJT3tnAE7vAaJKoEaZttOzbU+gP578ykoOJcRqjX3V49aDtFE7gyN9w99MlUgRu9GMGhFtUOvNZcL8jnksSdr5DzHM5mS3 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 Sun, Jul 07, 2024 at 10:17:27AM +0200, David Hildenbrand wrote: >On 06.07.24 03:28, Wei Yang wrote: >> 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. > >These historical details should be dropped. "Since we plan ..." will easily >get outdated soon. > >* 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. > Pretty better, thanks :-) >? > >Reviewed-by: David Hildenbrand > >-- >Cheers, > >David / dhildenb -- Wei Yang Help you, Help me