From patchwork Mon Mar 18 14:21:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13595402 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 A1E80C54E58 for ; Mon, 18 Mar 2024 14:22:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED28B8D0002; Mon, 18 Mar 2024 10:22:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7F358E0005; Mon, 18 Mar 2024 10:22:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D466B8D0003; Mon, 18 Mar 2024 10:22:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C42378D0002 for ; Mon, 18 Mar 2024 10:22:11 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 34265A11C4 for ; Mon, 18 Mar 2024 14:22:11 +0000 (UTC) X-FDA: 81910374462.24.2A88433 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 7ECAF4002A for ; Mon, 18 Mar 2024 14:22:08 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MXUQs63A; spf=pass (imf12.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=1710771728; 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=KylbygHFZqY0Y1GdcbNhcWaGXpHQjrqCbtqoLy1m2Bc=; b=ALk0E+g2KnsINSlxZ2koXFwWkcXSq+lNuh6bdRLP74Mm4nJl4EtltqwWD5WwkwK+ICP35Q eZy4OzTRAYQpe5c+RBmmEBBN9DEe88yR6GdXLFZ8F9IE7N6GE34LpHNBCzwDL/2J/fyXRx sFtFqOWpR7dqnOnauY7hwbHc+OJ/AOA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710771728; a=rsa-sha256; cv=none; b=slrw9UjtPU41RWJiS1VA0Hsy/anDDveOrHvSuJseSKnF/4l3oE83+o7uLLllmWGTaVxwgu O0G+A0RRz1NEKlT7jPbe0OL8Nle20WP4Z9Et2C6WNJus+DDhWnIU2GSQzBcFdTeVHw2zcW PbNwW6x2mBBE3T8YcHPwi0B/sMe26iM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MXUQs63A; spf=pass (imf12.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=1710771727; 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=KylbygHFZqY0Y1GdcbNhcWaGXpHQjrqCbtqoLy1m2Bc=; b=MXUQs63AK9CnyuPn6EwQLaMakGdcI/ynoV3nuyYHSFnCheTrwpxuFH0GuMetDou2VzVyqh f1pezdjAWZ2GHDgExC28ri3H3rdb+r3xnDqWfj+RWCLnbd7puB/NdlTB4Wo7GAlDImiIHI LW5XnfGJwdA2m0FDXDnipgSYvLPV7NE= 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-477-Mj8ycNDdNl-3_fqL6K9nzw-1; Mon, 18 Mar 2024 10:22:04 -0400 X-MC-Unique: Mj8ycNDdNl-3_fqL6K9nzw-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 BF3D085A58C; Mon, 18 Mar 2024 14:22:03 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7BC3492BC4; Mon, 18 Mar 2024 14:22:00 +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 4/6] mm/mm_init.c: remove meaningless calculation of zone->managed_pages in free_area_init_core() Date: Mon, 18 Mar 2024 22:21:36 +0800 Message-ID: <20240318142138.783350-5-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: 7ECAF4002A X-Rspam-User: X-Stat-Signature: zcdxumftewu5874reac76byngkt9e3yu X-Rspamd-Server: rspam03 X-HE-Tag: 1710771728-936540 X-HE-Meta: U2FsdGVkX18vqnI17pZvVQ1pe6lx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XmyyPXxOzmcgU2wL6FgMdqxZ0d6joAYrDifoSlT21QGOByrg4FPPXDWFk/bgXRuwY+yA88CGgU9J4KyMfR3hQRKQOtKuNPM+g== 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: Currently, in free_area_init_core(), when initialize zone's field, a rough value is set to zone->managed_pages. That value is calculated by (zone->present_pages - memmap_pages). In the meantime, add the value to nr_all_pages and nr_kernel_pages which represent all free pages of system (only low memory or including HIGHMEM memory separately). Both of them are gonna be used in alloc_large_system_hash(). However, the rough calculation and setting of zone->managed_pages is meaningless because a) memmap pages are allocated on units of node in sparse_init() or alloc_node_mem_map(pgdat); The simple (zone->present_pages - memmap_pages) is too rough to make sense for zone; b) the set zone->managed_pages will be zeroed out and reset with acutal value in mem_init() via memblock_free_all(). Before the resetting, no buddy allocation request is issued. Here, remove the meaningless and complicated calculation of (zone->present_pages - memmap_pages), directly set zone->present_pages to zone->managed_pages. It will be adjusted in mem_init(). And also remove the assignment of nr_all_pages and nr_kernel_pages in free_area_init_core(). Instead, call the newly added calc_nr_kernel_pages() to count up all free but not reserved memory in memblock and assign to nr_all_pages and nr_kernel_pages. The counting excludes memmap_pages, and other kernel used data, which is more accurate than old way and simpler, and can also cover the ppc required arch_reserved_kernel_pages() case. Signed-off-by: Baoquan He --- mm/mm_init.c | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index c57a7fc97a16..55a2b886b7a6 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1584,41 +1584,14 @@ static void __init free_area_init_core(struct pglist_data *pgdat) for (j = 0; j < MAX_NR_ZONES; j++) { struct zone *zone = pgdat->node_zones + j; - unsigned long size, freesize, memmap_pages; - - size = zone->spanned_pages; - freesize = zone->present_pages; - - /* - * Adjust freesize so that it accounts for how much memory - * is used by this zone for memmap. This affects the watermark - * and per-cpu initialisations - */ - memmap_pages = calc_memmap_size(size, freesize); - if (!is_highmem_idx(j)) { - if (freesize >= memmap_pages) { - freesize -= memmap_pages; - if (memmap_pages) - pr_debug(" %s zone: %lu pages used for memmap\n", - zone_names[j], memmap_pages); - } else - pr_warn(" %s zone: %lu memmap pages exceeds freesize %lu\n", - zone_names[j], memmap_pages, freesize); - } - - if (!is_highmem_idx(j)) - nr_kernel_pages += freesize; - /* Charge for highmem memmap if there are enough kernel pages */ - else if (nr_kernel_pages > memmap_pages * 2) - nr_kernel_pages -= memmap_pages; - nr_all_pages += freesize; + unsigned long size = zone->spanned_pages; /* - * Set an approximate value for lowmem here, it will be adjusted - * when the bootmem allocator frees pages into the buddy system. - * And all highmem pages will be managed by the buddy system. + * Set the zone->managed_pages as zone->present_pages roughly, it + * be zeroed out and reset when memblock allocator frees pages into + * buddy system. */ - zone_init_internals(zone, j, nid, freesize); + zone_init_internals(zone, j, nid, zone->present_pages); if (!size) continue; @@ -1915,6 +1888,7 @@ void __init free_area_init(unsigned long *max_zone_pfn) check_for_memory(pgdat); } + calc_nr_kernel_pages(); memmap_init(); /* disable hash distribution for systems with a single node */