From patchwork Mon Mar 18 14:21:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13595401 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 4F6DAC54E5D for ; Mon, 18 Mar 2024 14:22:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEA8B8E0003; Mon, 18 Mar 2024 10:22:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B99378D0002; Mon, 18 Mar 2024 10:22:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A39418E0003; Mon, 18 Mar 2024 10:22:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8FE1C8D0002 for ; Mon, 18 Mar 2024 10:22:06 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6FA3140576 for ; Mon, 18 Mar 2024 14:22:06 +0000 (UTC) X-FDA: 81910374252.07.923BFC9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id B7CD5140015 for ; Mon, 18 Mar 2024 14:22:04 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NemGzvaQ; spf=pass (imf26.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.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=1710771724; 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=QzLXH6qMIHqtnzXWX62ROk/ybRe+TrfeVI7pvJQEkBFaZeGJOw3YZJfiMu4vYkOrn+75Ou EKb4bRk2yaJ8sAbDGOv+r4mqGsTLZ9fdN8mNqDjSNr9B1F0l22Xeo/Uag9KLovynNwcubq zIRjubvQjZxs0qIAUwfkeEgtHiHznwA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710771724; a=rsa-sha256; cv=none; b=nNxxSZubFOao5nB/GfZwMrEZfqjE8kfOOchZQZ+ffpMDs6KUY/ayiucor+nrTVuIALdOc9 ZU84KNnwm+gZv52GPk6DTCRT0amn5EaD8eHS0ieZ77BQuc0yjKvk6hYNUdbyUgOg0bMvsJ ppS5G/RYRLI80ky7L3/IwRAXU4GlmA4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NemGzvaQ; spf=pass (imf26.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.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=1710771724; 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=NemGzvaQz6x+9Tvmazy9vlvUIO21sLbjiOkcA5S13eU4fAPFVkHhSew531dQILq15ZDgvN yUM1bJpsBmEghjwOoxm7lAup5MIf+J1T3m8CPfs/LUed8h1MxzyB6j2CuelNA88+L7zdcl QwVAplpjhg/l1c9IZ6a9reVhfZ2hZqc= 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-357-Ksx67UdVPXy4bpjfV4ra_w-1; Mon, 18 Mar 2024 10:22:00 -0400 X-MC-Unique: Ksx67UdVPXy4bpjfV4ra_w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 3A2F4800269; Mon, 18 Mar 2024 14:22:00 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 510F6492BD4; Mon, 18 Mar 2024 14:21:57 +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 3/6] mm/mm_init.c: add new function calc_nr_kernel_pages() Date: Mon, 18 Mar 2024 22:21:35 +0800 Message-ID: <20240318142138.783350-4-bhe@redhat.com> In-Reply-To: <20240318142138.783350-1-bhe@redhat.com> References: <20240318142138.783350-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Queue-Id: B7CD5140015 X-Rspam-User: X-Stat-Signature: 4w5wqyarzz5gseexaax44ww3kq1u3nto X-Rspamd-Server: rspam03 X-HE-Tag: 1710771724-904966 X-HE-Meta: U2FsdGVkX1/6NjGlYTGbEaoNUFymfQX+h1O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QdZJO0zdd5nGHWLNlXyj19oM0dRmLgJuk4r4VykbgD7ACpFv4pxc3ENQW6Xdw/MQp4H93XHzKSEXZRjZ93qUuFrkT+jDDg== 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 --- 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)