Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2808587lqp; Mon, 25 Mar 2024 09:45:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXU1dn6cdczPgDHz1nifk3WjbFht56seXejPj0m119WzdDT8WRsZAx/rxjxjoPKrH+iPMLFu6sEWcCeTvDlFGTLUkLhMdlJ+Hs8lqlzUw== X-Google-Smtp-Source: AGHT+IE4f1wJ2CQya5zHz7LokZ+XUofFICK42GcHFsx6V6BrpkXoo0ZZzWYszk3VKCo5LHatWknv X-Received: by 2002:a05:6402:50d1:b0:56c:4f5:7227 with SMTP id h17-20020a05640250d100b0056c04f57227mr3902204edb.41.1711385131662; Mon, 25 Mar 2024 09:45:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711385131; cv=pass; d=google.com; s=arc-20160816; b=yJdGu92fHvFmnL8oX8VgbEHRCM2QuG6HspKcwGmeACA7ZzDKrFDSZqSsRWzisUVpcb Vo3qf23To7KH1v0nZawcu/NKYLu0oiUPGPBRLZLPBrvOK36kgBLEkUIt1JG/CFuEVb28 uZ4trfL00AHcdmdQ/05RJhLgrN9OmDYi0GtzDxs6fknA4hSiQIy7AaQl2G0dePlpnJ9i bsJ6B9lr96OcGGOEw0nkV9nyBVY2Wegr8RNAmP4Ze5BIIDH7yrSRIzi6OiEw7m5c7N6l L8uHj4wJ0H5WPD1Blo/CSwkViPYr6NyyJ+GA+YrsLYfixIOblEJdx5I+0DxJSZPiwzM+ imIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=DL/tRS+4pUx9m3XgAdE8DYrulXqMo6B5z0clIVzdqIA=; fh=c/oh5Up+S96DG6r/ur5MAfFIcXhUC0de4lfxNiuupEI=; b=yMfNJ87GlZEkEbXFqon/0G2EC5+qxf+6c2BX3uAtfOp5uFCBzgJuCXybTLSMBSy9yT LfiSMnRiCuaTgV8pG/lpfMxZ4ZH08x7VrQsjd9JYpDqpdrle5rROtKn0ME3zOGzTRdj1 lr3nrlt5DBduvMJmDDQM42kGXmqEc78Wrh02O0B36pkYQAJ9ng+Q8w5jGIH2bRODuBC4 1HVOJ6kkyAo4lvIlQPB1IYuubAybjLnfKFVtvtYifjD8RgA6Z+F/Zt+1tjJk/6L0UAJb ZWVYXtXs3ZeFjrA00mPZLYp5sl0SUzN9EPEulIaqarMq4HmBJnGvAO1HsKl4TMKxYm3F ChiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TO7mgnCp; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-117310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c9-20020a05640227c900b005685142df06si2611941ede.347.2024.03.25.09.45.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 09:45:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TO7mgnCp; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-117310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5E0051F31A66 for ; Mon, 25 Mar 2024 16:45:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDCC716AFB6; Mon, 25 Mar 2024 14:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TO7mgnCp" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50FDA13249F for ; Mon, 25 Mar 2024 14:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711378642; cv=none; b=IyC560TgGECE43vINK1ka6pKm+1DxmiYC77FtkpCZN5ic1OV20wFNw5n5fhA05G8iTl5Hdtkn6EHcVnKYM2D4C97dKptOcHGFJRUtM94brHaQOfpSb7zJckgZ0cjKaaipqJSrfWEsZzG+PF8QWFgKknkv5qQXQruXIZzc3q34G4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711378642; c=relaxed/simple; bh=uYITEVm7lhnJTUWEPp778d1BV6/h4dw5f+lXXIA4nZo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-type; b=AzaIrHdlzhCl0Rjg3SdXzQJwA4qs7uqBIjCSRvjG1AGP2Iw628zE8p3zZQm1u6tKKgEWHHh209XtERuWmWbBhSPU/B50i77byzv21Fd4Cc3NGpZKPH+XGYLpDyD2z+99z7GChQ2QeSNwYrjRGESERJOPf6SHrigKF5cMt4fvJsc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TO7mgnCp; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711378639; 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=TO7mgnCpwpyswvvF2CjCm/OxYMACvGUy5UDMhJ3VuPz79hREonO9FSBglTxqjd9gDLC4dS VuxWQQPsH9muZN1wli0+GkzIA8jn1rGez6zmFW+BgkP9jnAWQYxEOBJFUYiVMulb2KP2tC FrR4PAcu0xFX9WzvFMJH431mL8frH3A= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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(-) -- 2.41.0