From patchwork Mon Mar 25 14:56:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13602375 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 ED39FC54E64 for ; Mon, 25 Mar 2024 14:57:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 899686B00A1; Mon, 25 Mar 2024 10:57:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8494F6B00A2; Mon, 25 Mar 2024 10:57:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 739FD6B00A3; Mon, 25 Mar 2024 10:57:20 -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 63FD56B00A1 for ; Mon, 25 Mar 2024 10:57:20 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0E8021C0827 for ; Mon, 25 Mar 2024 14:57:20 +0000 (UTC) X-FDA: 81935864640.15.986B02B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 370EEA0005 for ; Mon, 25 Mar 2024 14:57:18 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cJm4KVCs; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711378638; a=rsa-sha256; cv=none; b=Km4IZhIbYKwqcWz2y67+c+7aQpBPwr9wrdXMBusTaDZI78R5y9WyRZeX2+rq4GZASvDuXu ZmNksF8HZL3Wm/xJFZW2KpTd949I7XunRO3HtlQ7V9N3AgwU9bRdXsALKS+2jVxa9uQob+ i1oh4zxKFiUnfTAYjRRcNycM1z0qL70= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cJm4KVCs; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.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=1711378638; 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: references:dkim-signature; bh=DL/tRS+4pUx9m3XgAdE8DYrulXqMo6B5z0clIVzdqIA=; b=V3bgAhhpFByuNLyCFZ8VZqw+CQsuUk3wfgfZp3rFNEkuQN+wjxZ7tl9NOZMhhZTvnsgJb/ Fw8hHKuvUYkkv2NBT9MwQX4I9xi2qoNq6SmxKQJXZJhXnyIUlNl5RP3J86XuMcG91YASeM vhj1WUbVyCl8kgkQIsKonA6in343uws= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711378637; 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; bh=DL/tRS+4pUx9m3XgAdE8DYrulXqMo6B5z0clIVzdqIA=; b=cJm4KVCshZejO442MDFcoLHCDxyaUKjH6+YguLpoPnuNlIbxX3DrXExSzWLVJGlHABbzuN KUEHPOFfzzlXN5jQzZqzrzWdm2JbCyfax0Yk4450nPqWPNwPuTv3f4GK67/WTgI6t7Ss97 vNU2wTaRTa7HUZp3UcIXOLSOvFf0J2c= 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-344-8fUELVHUOWGLH-ZeoGwWYw-1; Mon, 25 Mar 2024 10:57:15 -0400 X-MC-Unique: 8fUELVHUOWGLH-ZeoGwWYw-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 8914E800264; Mon, 25 Mar 2024 14:57:15 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15D883C20; Mon, 25 Mar 2024 14:57:10 +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 0/6] mm/mm_init.c: refactor free_area_init_core() Date: Mon, 25 Mar 2024 22:56:40 +0800 Message-ID: <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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 370EEA0005 X-Stat-Signature: 7cwbr11hfawgqeja1obgxrqsa4qyubaf X-HE-Tag: 1711378638-129765 X-HE-Meta: U2FsdGVkX1+sH5VNbcktubF2ofhBZh9mLvo0Sn2U21xn564PulmTeKcgzoL3zYBWM88Ba2yuE+S0EFz1QrMLPg3UtL3YyrgZK5k71Ege2LTyGTNPh4o1CNEumdytIzyDb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.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In function free_area_init_core(), the code calculating zone->managed_pages and the subtracting dma_reserve from DMA zone looks very confusing. From git history, the code calculating zone->managed_pages was for zone->present_pages originally. The early rough assignment is for optimize zone's pcp and water mark setting. Later, managed_pages was introduced into zone to represent the number of managed pages by buddy. Now, zone->managed_pages is zeroed out and reset in mem_init() when calling memblock_free_all(). zone's pcp and wmark setting relying on actual zone->managed_pages are done later than mem_init() invocation. So we don't need rush to early calculate and set zone->managed_pages, just set it as zone->present_pages, will adjust it in mem_init(). And also add a new function calc_nr_kernel_pages() to count up free but not reserved pages in memblock, then assign it to nr_all_pages and nr_kernel_pages after memmap pages are allocated. Changelog: ---------- v1->v2: ======= These are all suggested by Mike, thanks to him. - Swap the order of patch 1 and 2 in v1 to describe code change better, Mike suggested this. - Change to initializ zone->managed_pages as 0 in free_area_init_core() as there isn't any page added into buddy system. And also improve the ambiguous description in log. These are all in patch 4. Baoquan He (6): x86: remove unneeded memblock_find_dma_reserve() mm/mm_init.c: remove the useless dma_reserve mm/mm_init.c: add new function calc_nr_all_pages() mm/mm_init.c: remove meaningless calculation of zone->managed_pages in free_area_init_core() mm/mm_init.c: remove unneeded calc_memmap_size() mm/mm_init.c: remove arch_reserved_kernel_pages() arch/powerpc/include/asm/mmu.h | 4 -- arch/powerpc/kernel/fadump.c | 5 -- arch/x86/include/asm/pgtable.h | 1 - arch/x86/kernel/setup.c | 2 - arch/x86/mm/init.c | 47 ------------- include/linux/mm.h | 4 -- mm/mm_init.c | 125 ++++++++------------------------- 7 files changed, 29 insertions(+), 159 deletions(-)