From patchwork Mon Mar 25 14:56:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13602378 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 31726C54E64 for ; Mon, 25 Mar 2024 14:57:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCD5E6B00A7; Mon, 25 Mar 2024 10:57:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B7ED16B00A8; Mon, 25 Mar 2024 10:57:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A483D6B00A9; Mon, 25 Mar 2024 10:57:37 -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 91CB36B00A7 for ; Mon, 25 Mar 2024 10:57:37 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5751B160693 for ; Mon, 25 Mar 2024 14:57:37 +0000 (UTC) X-FDA: 81935865354.28.E9647F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id B700E180002 for ; Mon, 25 Mar 2024 14:57:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cC6WiVML; spf=pass (imf16.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711378655; h=from:from:sender: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1Ez2QF5MYw9LVg300C2Oo4I1YSujmhzgBkyBgmFJgxw=; b=sPPW5VVreE1Ib3VynS6K8dmgbq6JEFIrhfImht3BXI0tji2S0Tsg85kNG1RI9cddp4r58B djhQ0wZ2j1OUz1SrAFoIgOXkB4bH41YLcFgKz4ejPPmMqWweUYPs8nhSmjZdHjoNJybf2V D5k6Yg8udajRcUQUoEDdGErNmwFodKo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711378655; a=rsa-sha256; cv=none; b=hAyxmBNK41mJE/fLR0eaGYukqpGAXtvNlpdGxzdSM/4VHEyzsMFzkSlqfl5XzN1jRJdp1T 2zHR54DO7yqV9CVTliNcisbtDoWuUpykuBBegAZG4aMzQ6k/uyOZipyz+8CqgC5Eka7oVq 6wo02NmlQVTA02zOXSb9v5bsg9siMSU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cC6WiVML; spf=pass (imf16.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711378655; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Ez2QF5MYw9LVg300C2Oo4I1YSujmhzgBkyBgmFJgxw=; b=cC6WiVMLRtYjQ8sFwri1SzQq6RDiCgJ+rkrfcfgMprim78TNmgRYy3wK0ufPjexfqMjIxk +s2xHJIRmcDRrD+c4nUVwv4hc+KIPOzHLqLBGahO2Fk+UTEPVyE/f/HXJkTC31NkFbnUFq 121G6NunzmhmrzpnlquQd+wqs/tXYp0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-UPy8WchcPpKKNZJqlR81mg-1; Mon, 25 Mar 2024 10:57:29 -0400 X-MC-Unique: UPy8WchcPpKKNZJqlR81mg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0BBCA800267; Mon, 25 Mar 2024 14:57:29 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id D78C43C22; Mon, 25 Mar 2024 14:57:25 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org, rppt@kernel.org, Baoquan He Subject: [PATCH v2 3/6] mm/mm_init.c: add new function calc_nr_all_pages() Date: Mon, 25 Mar 2024 22:56:43 +0800 Message-ID: <20240325145646.1044760-4-bhe@redhat.com> In-Reply-To: <20240325145646.1044760-1-bhe@redhat.com> References: <20240325145646.1044760-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Stat-Signature: b4eoyuxo4a58juzkjze85ghtn7pp9wj6 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B700E180002 X-Rspam-User: X-HE-Tag: 1711378655-174842 X-HE-Meta: U2FsdGVkX1/T5mW8q9FGzNWV15skb5Vx1mOcSPCAXLhw6dW7k19E/XTzO2naEadN20nRWeLMdgSkXoHIvNvMRxjqtg0IXtcEd+RkYAeNBw3g+JgD4iOu5eAK0zXNTq3G9TUokfUIM+CJFe0zm1GY+7ONWyb/yvKEWAjYEiUJBjo/6NgyIkdl+9fDvk8lQLq5EtBVEIEcK2YXOZY3G8M9+lvniDbF+FSAYBtIOCVDRQVC3ubUS5MT/z29sitNYAb0uA8skyuir79qMMm28ADrPJ3fd2Pr9UYernbvt3hA1uh8gayYhBZq5iGt7lFrR7lomHZp8zH/dYZzS2TGfCc6REi1WKn3PvJEhzW9txH93eylUYtyfcegfPsbgGiC3rOv8h+XJR2ZArLZzNUIOUBCMnvHF9mOz5iJUbOIgjyiVQl1M+ivBS/Ag/8cnsnrTpGrXd3VBku47dSm50NWvY42pKgMovvjqWPpkVdrjRbERpudppcz3+sxcRN4ytVqV6gO55sgvtQs/17Vcqm75tiXrC9XlhttQ3ziWxuUSK8apW2+eLvKkv+egRDANqaHZuCrGbSoRivmmm31RIntOzKmQqtzXocj3rFHAUkOHItuyt3mjP+dSOsp+MfdhSi1oa7bogNod6OdXj8wf9b+nq13A/cjfAz+8ZovXq7xgOA3WXaIenS+7Z/ArZQgYNC0SiRdgLkTFiz4y8QZjnp8DItJ7oqLB/fm3+MAsZHIiLSBuCxtG0ulkCCz3OMRDKXgLl7uZ0rcmp256NwigyfSfKvVIW5KlSl9qykQXgF2YETPtY7aWV0JIZCKVixCrqLnWlK8h7W9dVtgxRJcY9eTQSaMXuxLy7HvyWBFJMjvyUn+Czf50gx4zjJdyXs4qAzDsjV6YVuBzwcypY9+VbMp6pYJrH4lGdpLQZM9Mos76ZvfDfAjX2IUnBvxWDrSnHfnoo2B 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: This is a preparation to calculate nr_kernel_pages and nr_all_pages, both of which will be used later in alloc_large_system_hash(). nr_all_pages counts up all free but not reserved memory in memblock allocator, including HIGHMEM memory. While nr_kernel_pages counts up all free but not reserved low memory in memblock allocator, excluding HIGHMEM memory. Signed-off-by: Baoquan He Reviewed-by: Mike Rapoport (IBM) --- mm/mm_init.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/mm_init.c b/mm/mm_init.c index 153fb2dc666f..c57a7fc97a16 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1264,6 +1264,30 @@ static void __init reset_memoryless_node_totalpages(struct pglist_data *pgdat) pr_debug("On node %d totalpages: 0\n", pgdat->node_id); } +static void __init calc_nr_kernel_pages(void) +{ + unsigned long start_pfn, end_pfn; + phys_addr_t start_addr, end_addr; + u64 u; +#ifdef CONFIG_HIGHMEM + unsigned long high_zone_low = arch_zone_lowest_possible_pfn[ZONE_HIGHMEM]; +#endif + + for_each_free_mem_range(u, NUMA_NO_NODE, MEMBLOCK_NONE, &start_addr, &end_addr, NULL) { + start_pfn = PFN_UP(start_addr); + end_pfn = PFN_DOWN(end_addr); + + if (start_pfn < end_pfn) { + nr_all_pages += end_pfn - start_pfn; +#ifdef CONFIG_HIGHMEM + start_pfn = clamp(start_pfn, 0, high_zone_low); + end_pfn = clamp(end_pfn, 0, high_zone_low); +#endif + nr_kernel_pages += end_pfn - start_pfn; + } + } +} + static void __init calculate_node_totalpages(struct pglist_data *pgdat, unsigned long node_start_pfn, unsigned long node_end_pfn)