From patchwork Mon Mar 25 15:04:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13602384 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 10E7FC54E58 for ; Mon, 25 Mar 2024 15:05:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 968126B0095; Mon, 25 Mar 2024 11:05:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8515D6B0099; Mon, 25 Mar 2024 11:05:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A7546B009A; Mon, 25 Mar 2024 11:05:20 -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 501E86B0095 for ; Mon, 25 Mar 2024 11:05:20 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0A87F1C0398 for ; Mon, 25 Mar 2024 15:05:20 +0000 (UTC) X-FDA: 81935884800.30.33E8A93 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 33B83140021 for ; Mon, 25 Mar 2024 15:05:18 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="hc2CkX/x"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711379118; 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=yS1QabYOVuBAleB9ESxmuWyI/J0b4Jk31u6hea9akjToKdH84nn++jhvxLEMqZ/2itdDNI mLeDKKIfElinoTP3HcpW7mg6m3hz7XJ9b7uTJTrICyPetfOYZFJ7raSZ9ENP1Q8LB2+g+U FcLuv8t22VZuvp8gq7SZIpUVQgRLd3E= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="hc2CkX/x"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711379118; a=rsa-sha256; cv=none; b=tkop0UEI4KcPDPz35BRe3NOtCm3UG+XfZb9ZUHR8yJG0SxbhSmU9/B88900Y+aSorEZrY0 UUHi+euOU9OF9mNI0l1bpjbfyoEIt36E3dME162cYQHWBayxxpIL7pQBg5fxZgsCoV/oOP i8tLhe+X7WVUYrJWOl3OVvaVXxCFA+I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711379117; 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=hc2CkX/xlgts3PRd1xVeoU2wZakf4pl36Z3l1IsgaiHaNwbs5xwMA4R04VOqoUkxBqzXGs a4lCf+sQkSObZOZNcPRwO1D6GQOCOU7Gk7zGSW2LunYtOsk6VxtArmYfn66aYn+QvVTdFx gviKrxQ3Mptw1P2wAdGhTAllg/Z8Nu4= 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-313-6aVqa4z6M2qwjG0KqT3yug-1; Mon, 25 Mar 2024 11:05:16 -0400 X-MC-Unique: 6aVqa4z6M2qwjG0KqT3yug-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 BD8C187984D; Mon, 25 Mar 2024 15:05:14 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45FA6C04121; Mon, 25 Mar 2024 15:05:11 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, mgorman@suse.de, Baoquan He Subject: [PATCH 2/7] mm/mm_init.c: add new function calc_nr_all_pages() Date: Mon, 25 Mar 2024 23:04:54 +0800 Message-ID: <20240325150459.1045407-3-bhe@redhat.com> In-Reply-To: <20240325150459.1045407-1-bhe@redhat.com> References: <20240325150459.1045407-1-bhe@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain X-Rspam-User: X-Stat-Signature: w81gs1h1xw9om7z6trgf1o4xab4kwote X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 33B83140021 X-HE-Tag: 1711379118-453962 X-HE-Meta: U2FsdGVkX1+0S55xKYfi0ZxM8wsdEcLqwdemm2G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pogS8GpkoLBnrLalPllA6dNX8LfJ7n06zMLL8UxtHucOGf635nVwd8TgK3FTfDIlsMarMtr42ZCYj99RFAXgg== 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)