From patchwork Fri Jul 26 00:36:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13742342 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 1FBB2C3DA64 for ; Fri, 26 Jul 2024 00:36:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A8BB6B0099; Thu, 25 Jul 2024 20:36:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9581C6B009A; Thu, 25 Jul 2024 20:36:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D3076B009D; Thu, 25 Jul 2024 20:36:32 -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 5B3D16B0099 for ; Thu, 25 Jul 2024 20:36:32 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 08AAC121544 for ; Fri, 26 Jul 2024 00:36:32 +0000 (UTC) X-FDA: 82380037824.09.854770E Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf17.hostedemail.com (Postfix) with ESMTP id 558A64001F for ; Fri, 26 Jul 2024 00:36:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=C2KKs60F; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721954188; a=rsa-sha256; cv=none; b=DbgbDwnQJEQz8sibq0ZOf2gl0g08TlKUnUP8SRxIUFhqn2m5tScpDZJ7VvRmrsfmYalLgj tC8FgA8zwEeObU4iTuMVxOQ1vliSx3ibsJQS6rRTrK4ySLP7IrRheyz6bl7X8nsYIqM+95 YNeCVUpPUSo5W+nmrT2mq0l9kB2xcBs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=C2KKs60F; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721954188; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=TLeM+k4uD0VG9mUOt9G60jOuLuLwFgt7xpwzUVfZcao=; b=I48kS+ZknwG1GtRlZVZ+/rNhmVIvjmZ0PUirL1sqW5/1vZwS3UdrbWVIcm5L5Iq1vcWMxB kNrSuTejoPJFTF1Ce9bL21XLBIOTDBBvAWOVueoxxKRkZanO6DjVCzy84EzPDuQQFETBUp o7dsE/dDTAIMzwu7G+tXO5B49taAtcA= Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a7ad02501c3so132687666b.2 for ; Thu, 25 Jul 2024 17:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721954189; x=1722558989; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TLeM+k4uD0VG9mUOt9G60jOuLuLwFgt7xpwzUVfZcao=; b=C2KKs60F9zj1E6VgT18WPj6Bex9IVd0z0NJJWRBvIx9r13N12id1NdarrsLpy5cBie bNpi5DsnmftMEBHGyCYdgkVLHmF899AlJl4ZgNN4l+dqsF47sMwnlk6Isxp4VAIod63E TrDvf+9NLhdjmtAIty4U8JWNamqeWUQ1ixEphMSYCIZP/ES/hh65qgSeIKEF2iiYTVBO A+Y25rbnaih6IL8tJ494unEvKkFynonK1wPn9brMcqYwXqPs9WcOLoFGegjyomyJlhbS ggbdHCz4ycrSq9MLsks4ouFyxTMD5pfzYDDqlt2k3Mbq6z2s/Q6VQP/rZfFEH2HiwO+8 JlpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721954189; x=1722558989; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TLeM+k4uD0VG9mUOt9G60jOuLuLwFgt7xpwzUVfZcao=; b=ZU5JX47LE2Y4HLeEUkFGCr/PoWkA9gURah98UA2kylXC001bBzu6BZnkBMPnciMfgs g4jPz0iZCY9PuezXDRRKNknPR9X+A1nuHua9V/1mh094eKx1CppRVLJOH58F3Ja6uaPg q/90WOMKx2hXdqhbkaEcusgH15O1BIqFKubkKEnJDQMpdhDr94Y1bZAnvrwcj4NvsL3c 3pTmeYvBFFa0NbSxAzSNu4wWdDZBvqIxxYfNsqaG/vw3ZWnX9XoVUGQMWCvcV6CLfL3U CRJvyxkCw4GnioJQO76967EBUD1VrfqcY3qy6TtUAubKOV0fx1GoO+Ra8mlu0sz77oL5 jyrw== X-Gm-Message-State: AOJu0Yw0zTql8Me9UjEQwNk7ZS4kcpnEIaopdyd9txFJz/YyZcJ5GOVN V8cv3TEUH2BsuTxlxtBKcYmXH7veGhgbCEHzYeAv3uFvTT70fOj7 X-Google-Smtp-Source: AGHT+IG+Xe1eturU0UE6JXSxqOrt7+yDyNngamqF3AT3zfITx7Tckz3XHHm/u9BbG6vmLYsRY9pG6Q== X-Received: by 2002:a17:906:f5a5:b0:a7a:bece:621d with SMTP id a640c23a62f3a-a7acb38eefamr299466866b.3.1721954188482; Thu, 25 Jul 2024 17:36:28 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acab594b7sm120585466b.78.2024.07.25.17.36.27 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jul 2024 17:36:27 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , David Hildenbrand Subject: [PATCH v2] mm: increase totalram_pages on freeing to buddy system Date: Fri, 26 Jul 2024 00:36:12 +0000 Message-Id: <20240726003612.5578-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspam-User: X-Rspamd-Queue-Id: 558A64001F X-Rspamd-Server: rspam01 X-Stat-Signature: 57rsywgw4bnp6rycu3thm561azwx77n7 X-HE-Tag: 1721954190-281429 X-HE-Meta: U2FsdGVkX1/mtZOSrvtPfutBEAL0zpjGI5itO+MEfLapQ1eAb91BkpueLVktKS+a7SOyQsSEk08xTQ/l75/DaKFdflQS/l1gCbe9uUmuDzmSM9Qsl4Zoqulm/2JSBoVH2EDCzsr0wb0ccpxYTqjVqhyCDCRfIcNBaSbyo8XSd8xgeX2rIb7ps5sXLFnkibeECqHdC6Qgdh+QlT+uQN0wTtoqeOPQiqV7w9tW1WiDos4D37ybHy8LcGOMv9ZFrKV6hGWgPf8izflvXeTZGYdjxJUldSxFHQeuEqyOmuy4uaJzpJDKjw1gd6kYVqDDM1H6n4RRSF9o9IPBJBZaXnB2Wkv5f9nJrJUAHccgzaopMZUY/04B3zp0u46L7Tc59X2MgOOcQem8Jey2/XtbbcJ+CeZi1SEdS7d+yKlSUC01MZbLxTdctpIbV9Ohk9XgCbAPF6FigvZ9pVrzE/q9fkZcvvq58uCSOU0E7xpeeIarVt2TixF0CBuB4duLUrkayQK4JyZ4Wwm90atImOIMXWt2t2DrGzAVe+vWJIEtCzuNC8PtDTXyOA1C9sBVB/cY2f4z/2j7SsoTZFzlcBa+wdzmigkkkpsHKyrovdb9kvWzALNyjmenHL+3N5+JFGmmKE+O5vyAPWBsuWy9gVDm2gY662hP9AJs+U+UN7PCO5ds0pcgd1g4jFHGkowfxQNKHSg1s3B0Pgp8uzCjaBCfCCXk07WPmy+/vORnOeZw+3p3CMP06d1rPTscBgadq2xEKtFbvs1/WA9JXzhETWYXetZMdBGg0RTmyK9veGBJ+vWMawv9rLgWKnZhwsN23lZfBTfQYWI3khpyOz0eax9vbgBzuVxNxQu3ze0uXO8t2Iasw1k9+/01JHzHke2UtTeDfKj6eocNUcsN0HRqKYYBfmkVuJ7z0nafFUOS8t24NwxPkzCUmM1Y/1VdyBI80EiCOJRtISOJ5AA5bIJN8Ch7n/T wx713cKv QuK0mLzhJc0H+pXW65B17EDp6BCgzJfu9QwXlal9QfrTt/9C2mtideHwLV/MLCNraQLrhJfB/ew/uaZ1ueEFmNrUYQRz4WULl0Eri5GhVywij06rDNcYEPFL8c71JaNI7hufjBJ8y2G64IHJe4h9+vB07G4tpTFTZwfFnhpHH6+YAJxPbUQqVv+xBWxyS7zZWo6pJ0dn1VcA2HXX0Y5kUNT59z+5R4uThuoRQ3BBQsVbRru6Ane0SI1pLjIr1MRSPKF7ZUOKjCwNAQMUbcx7JpoTJibqAreOMy2CzZC3LwrLp7vZBoJ9BGVxsX6He5MVuJzBk1jhEDNumbvKiy1hnGJ4l0FIRPppZ4w6X+eL61zeYL41txWW5RSSoWrNhI+5fl7fTVPDoJ4IkkUlrupE8ac3WjqK6PnNE1Y79bkhgc4nybBnAVl0cec/4Qol9seZ9Wg2IagzQmuqZlXLQMKgAAGcaNe1Auv35xxzwdAHaN8BpssqPDjl21yxD59R94IcFwhIWhbAeXeNJFymAzDfqLHCsuvCFGFluFOu0y+VzOd/INKTFE/eRuncpkLd/z225T0zTcB6I05IEboO7ytdxhKRYTw== 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: Total memory represents pages managed by buddy system. After the introduction of DEFERRED_STRUCT_PAGE_INIT, it may count the pages before being managed. free_low_memory_core_early() returns number of pages for all free pages, even at this moment only early initialized pages are freed to buddy system. This means the total memory at this moment is not correct. Let's increase it when pages are freed to buddy system. Signed-off-by: Wei Yang CC: David Hildenbrand Acked-by: David Hildenbrand Acked-by: Mike Rapoport (Microsoft) Reviewed-by: Oscar Salvador --- v2: * rebase on current master * those places would be affected are merged --- mm/memblock.c | 22 ++++++---------------- mm/page_alloc.c | 4 +--- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index 213057603b65..592a22b64682 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1711,10 +1711,8 @@ void __init memblock_free_late(phys_addr_t base, phys_addr_t size) cursor = PFN_UP(base); end = PFN_DOWN(base + size); - for (; cursor < end; cursor++) { + for (; cursor < end; cursor++) memblock_free_pages(pfn_to_page(cursor), cursor, 0); - totalram_pages_inc(); - } } /* @@ -2140,7 +2138,7 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end) } } -static unsigned long __init __free_memory_core(phys_addr_t start, +static void __init __free_memory_core(phys_addr_t start, phys_addr_t end) { unsigned long start_pfn = PFN_UP(start); @@ -2148,11 +2146,9 @@ static unsigned long __init __free_memory_core(phys_addr_t start, PFN_DOWN(end), max_low_pfn); if (start_pfn >= end_pfn) - return 0; + return; __free_pages_memory(start_pfn, end_pfn); - - return end_pfn - start_pfn; } static void __init memmap_init_reserved_pages(void) @@ -2194,9 +2190,8 @@ static void __init memmap_init_reserved_pages(void) } } -static unsigned long __init free_low_memory_core_early(void) +static void __init free_low_memory_core_early(void) { - unsigned long count = 0; phys_addr_t start, end; u64 i; @@ -2211,9 +2206,7 @@ static unsigned long __init free_low_memory_core_early(void) */ for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end, NULL) - count += __free_memory_core(start, end); - - return count; + __free_memory_core(start, end); } static int reset_managed_pages_done __initdata; @@ -2244,13 +2237,10 @@ void __init reset_all_zones_managed_pages(void) */ void __init memblock_free_all(void) { - unsigned long pages; - free_unused_memmap(); reset_all_zones_managed_pages(); - pages = free_low_memory_core_early(); - totalram_pages_add(pages); + free_low_memory_core_early(); } /* Keep a table to reserve named memory */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 71d2716a554f..4701bc442df6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1248,16 +1248,14 @@ void __meminit __free_pages_core(struct page *page, unsigned int order, * map it first. */ debug_pagealloc_map_pages(page, nr_pages); - adjust_managed_page_count(page, nr_pages); } else { for (loop = 0; loop < nr_pages; loop++, p++) { __ClearPageReserved(p); set_page_count(p, 0); } - /* memblock adjusts totalram_pages() manually. */ - atomic_long_add(nr_pages, &page_zone(page)->managed_pages); } + adjust_managed_page_count(page, nr_pages); if (page_contains_unaccepted(page, order)) { if (order == MAX_PAGE_ORDER && __free_unaccepted(page))