From patchwork Fri Aug 9 19:10:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13759158 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 1BB8EC3DA4A for ; Fri, 9 Aug 2024 19:10:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0730D6B0098; Fri, 9 Aug 2024 15:10:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3E4E6B009A; Fri, 9 Aug 2024 15:10:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1C206B009E; Fri, 9 Aug 2024 15:10:30 -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 A6CE76B0098 for ; Fri, 9 Aug 2024 15:10:30 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2A78AC14A9 for ; Fri, 9 Aug 2024 19:10:30 +0000 (UTC) X-FDA: 82433648220.05.AC5BFF5 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by imf20.hostedemail.com (Postfix) with ESMTP id 47BF91C003B for ; Fri, 9 Aug 2024 19:10:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=oGRavLrb; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.169 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723230574; a=rsa-sha256; cv=none; b=AJYw339IeDhjBQvzMs3h2ZYqFVAdGB3oQopV8LBNQKznvMvte5VirL5COi88+Ej7xLUb+T uBiAGvopBpr0unVZ5wAQ0r7H79HVRVos1VkrIF3Y/0axcmRzAp+NVelOgGXYpog45eukY1 TG/gcCys0aB16z/jiRjTFFuszeV3aDI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=oGRavLrb; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.169 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723230574; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7scNbfOD3UNvIo9y0T+pYKNfJFgM2C7HW5kYHlU5U7s=; b=d2SBwdRmCFHB/jT71ucikSntx3X1nnrUG1ZMTf22XoRJyhxwHZ1XBp1V7wfEhMXeVavAvD dAwAw9sDk11HBScTSj002vKIsFLLTTDU5drFDlgZCc6aKN4uqZULskz9Y/ubWQRm/idgLO wIYnNOYgWcFWqsqigb9y/TLeCCWdczs= Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7a1d436c95fso153039685a.3 for ; Fri, 09 Aug 2024 12:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1723230627; x=1723835427; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=7scNbfOD3UNvIo9y0T+pYKNfJFgM2C7HW5kYHlU5U7s=; b=oGRavLrbF7S6wPl4F4hWHGiL0Es/TjlnDpuT1CErEcPlpuvoNuDaIA4vUvF9nKjR8J v/5zrWkrwrJdGoFUKSOnAzcT94x+1LD5eLVt/EIsI7hybnZ/n8uOu6HaKOsHTHYSwmjy /A+iGppAV17TAgv3UCWROhTv2EWdOvotPnRhLjZ32GofmtL7uYTG9mOTRnnqwVPLeHRZ CmR+n3eE6p7w4Cnk92wpPXeItbtcaL/r2YMPaXnOOYZfINVsFVOzRoHJOgw3tjIFx0xd hJVt3mvRQ56iy4eZ3ZexkVdgQZTTjkFtosCIAdL0CXTYneE5aSyQhSGskYOyvCrt+34Y PRTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723230627; x=1723835427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7scNbfOD3UNvIo9y0T+pYKNfJFgM2C7HW5kYHlU5U7s=; b=GAkIwfwnFkKjcjKTNRHmSzKDL9qwPS558hGCtsaHNS87qMXcZaJNJaKKjQD+Gb0ZW7 krso3Et1JvDdjVPCci9D7IMYXub8XeMD1B3ee30wKlT5Xrd/VgSBWW+FOIr1MASObly6 VU5cEnGtjXK2W602zlte8nsWI4fM1CGwS+I/DUQbj+5TmB9Rn09gAMvwF0Q30ZWPGwR/ uv5USh8rSDuSkqvK6KNy8j/9+fb1gLXSM90cNL+zeUwhCFh8o0JQlqPG1YVaZUdqU4R4 uo8QQlkzaYLA3lieieG9inONcdOvCPgYQXp14YMrHGapzyFSCjAwQn3iWMQIugNOmFwL /XIQ== X-Forwarded-Encrypted: i=1; AJvYcCUprT8fl4F0MH3Q8JVSFUk4zqHBTLIu2P7gxxYIE1CXuBYWFvMBJo6oo4zzwHkjWRuOre52UeJIunz7FCiwd2c2M8Q= X-Gm-Message-State: AOJu0Yw6/Bs/RNuFqVYYQORxE1b5F2zsYRcASEka+q/gJ0v3HAEJeAnr mkr7H12W54/Bkv6bRicINsB3YX8POj+eAkL0QoxywVyKiURgfAbxikllAqnjtDI= X-Google-Smtp-Source: AGHT+IG+izZuVqrrLECU59ZUsz/j/pq6H+/mhN6LagU3A3JWt/ctLE0qFWvHYBV7BwQjZPC1c0cfJA== X-Received: by 2002:a05:620a:2456:b0:79d:5f67:a836 with SMTP id af79cd13be357-7a4c17aafddmr317308185a.26.1723230627259; Fri, 09 Aug 2024 12:10:27 -0700 (PDT) Received: from soleen.c.googlers.com.com (118.239.150.34.bc.googleusercontent.com. [34.150.239.118]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4c7df5a55sm5522085a.86.2024.08.09.12.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 12:10:26 -0700 (PDT) From: Pasha Tatashin To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, cerasuolodomenico@gmail.com, hannes@cmpxchg.org, j.granados@samsung.com, lizhijian@fujitsu.com, muchun.song@linux.dev, nphamcs@gmail.com, pasha.tatashin@soleen.com, rientjes@google.com, rppt@kernel.org, souravpanda@google.com, vbabka@suse.cz, willy@infradead.org, dan.j.williams@intel.com, yi.zhang@redhat.com, alison.schofield@intel.com, david@redhat.com, yosryahmed@google.com Subject: [PATCH v5 3/3] mm: don't account memmap per-node Date: Fri, 9 Aug 2024 19:10:20 +0000 Message-ID: <20240809191020.1142142-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog In-Reply-To: <20240809191020.1142142-1-pasha.tatashin@soleen.com> References: <20240809191020.1142142-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 47BF91C003B X-Stat-Signature: wdc8t6a5rcq7xt37c5to5aobffggn8zo X-Rspam-User: X-HE-Tag: 1723230628-173066 X-HE-Meta: U2FsdGVkX19uQP4lqaHmDwBVt81anUR0/tEadT2SlyW+zNEaFiuH034eUSuZoakPCp9DGoqDzyDy2u/a3opWpi8FmX6bqAf4/TuHW59L1SuMCDMJIjrSmv+tXLa4cjWaRQVVsM2yC88M4gUXnXeB7ZDEwRa4vM7YCErkfMsCR3zz9XuI3gJyCwn3fGBWGBwoVuBav3FPrQyyPQpxsZ3b6sHyBVKjJ3wWjbLBu8aaL4GbmKid7hR1v9uzhyIyOGsQSxMy2+HKgU66TbBeaXPU+6hrRHYzgzAqZxlgL4mi4HxLnkX3AA7zc4qEptztJPnJjUr+W6JwgJ3lPCbzhIilMXNCzpyiqMGbBXN6PetqMnCob8iM1VdUe4F9zmLAd6RrD8sLnogzdgMf/7fRLsnpC/LpbSTWZ2M8PF/Q52YQWhhPh+08ZIgIEmPb0gOoXl36Jw8d1UPB0/1agzNYpfXc5REb/fPITCPcmAXYIjVhWInWNej0jDFXEfWPB2Y5UU8KiyXQnaUzzulVOfHC2U6szuirxSfjDshaPBJRDJ1S7i3cWwuozD7Mb5J7pKbW8RSmqGSYN/KiS28qk8B1k/jvo9OhvWp4jDh9gx2vNfy4HGcvjBKW4YksBsdBu+oZg9l4xa2SbQVJ8X8wphgiXtTKxDlc6/umSqwUs+lu9KgYc9UZ8W/rSDTeM3bMV2WjHK8mPU6Cb83//cpycMnRZpmgdRcvkvl72GUcLSdRkQ9HJCedgrRPQMnhlwmRAdE9/3Sy47AaVhIVwlzigSsNR7qQLw6dvaFyzcHWStB4bFY4LdjDS2Q+1I85ajbzSWt+/zuCUSlAZ2EV3IXqL1lkxJxZJN6xVlyAJhMR0BbyMRKX5mx1VfGs/XYGrSWy6m01cyNvB75K91y5chaOwL0hH/gEVtJ73/6UOX6SYsQAHJwHO7ttQmX4Us/4mAz7gRcvlkVCabZGHp3scemr+hFzU/c zjZJOaoZ jnhw9n4haAfh9AXjsunH59n2TrZ0WQd1ZMO4o/suYgoWA9qAT8CMbWJLIOBTPxYyV4pyOxllsBvhztsOnm+29jJYu9PbKf/FFyPKkjV4lmmkh4xNDpiGGU9OXC067A0zQ4OlNjmMoNxLIitfPpq3UfA6DiSsswAAj+jUKiCbtd+f57IZBognF7XwrCGquckmc/gtznDBMS6twrm93+w65hW3BL8TVNHuvIQ0j4eE8LPXMNlS06TQ40cYjMp3nhIMtHRHZwTjZtfTiG5pnV4ygMsvl3PBNeWO6nJpQHYEJsMvy+DT77bFVh7b6LRq44k5P3b4fraq515EqwuNZLSdakR+Zb+zapEgaNcaFcXUHhO048PtLSBuSHYVmzUC3zZfBdrQnhPNSr+LT1Fws5Mwewro2PJkzcx9GhpTk9KwJOmfOcDBIRCovGdXp8iCVJDF/2TxAzya2Y09zzdJVOqeJvUm9kqLFUTAtQsfvgdA1hBvoUcQWawZnGANHNQ== 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: Fix invalid access to pgdat during hot-remove operation: ndctl users reported a GPF when trying to destroy a namespace: $ ndctl destroy-namespace all -r all -f Segmentation fault dmesg: Oops: general protection fault, probably for non-canonical address 0xdffffc0000005650: 0000 [#1] PREEMPT SMP KASAN PTI KASAN: probably user-memory-access in range [0x000000000002b280-0x000000000002b287] CPU: 26 UID: 0 PID: 1868 Comm: ndctl Not tainted 6.11.0-rc1 #1 Hardware name: Dell Inc. PowerEdge R640/08HT8T, BIOS 2.20.1 09/13/2023 RIP: 0010:mod_node_page_state+0x2a/0x110 cxl-test users report a GPF when trying to unload the test module: $ modrpobe -r cxl-test dmesg BUG: unable to handle page fault for address: 0000000000004200 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: Oops: 0000 [#1] PREEMPT SMP PTI CPU: 0 UID: 0 PID: 1076 Comm: modprobe Tainted: G O N 6.11.0-rc1 #197 Tainted: [O]=OOT_MODULE, [N]=TEST Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/15 RIP: 0010:mod_node_page_state+0x6/0x90 Currently, when memory is hot-plugged or hot-removed the accounting is done based on the assumption that memmap is allocated from the same node as the hot-plugged/hot-removed memory, which is not always the case. In addition, there are challenges with keeping the node id of the memory that is being remove to the time when memmap accounting is actually performed: since this is done after remove_pfn_range_from_zone(), and also after remove_memory_block_devices(). Meaning that we cannot use pgdat nor walking though memblocks to get the nid. Given all of that, account the memmap overhead system wide instead. For this we are going to be using global atomic counters, but given that memmap size is rarely modified, and normally is only modified either during early boot when there is only one CPU, or under a hotplug global mutex lock, therefore there is no need for per-cpu optimizations. Also, while we are here rename nr_memmap to nr_memmap_pages, and nr_memmap_boot to nr_memmap_boot_pages to be self explanatory that the units are in page count. Reported-by: Yi Zhang Closes: https://lore.kernel.org/linux-cxl/CAHj4cs9Ax1=CoJkgBGP_+sNu6-6=6v=_L-ZBZY0bVLD3wUWZQg@mail.gmail.com Reported-by: Alison Schofield Closes: https://lore.kernel.org/linux-mm/Zq0tPd2h6alFz8XF@aschofie-mobl2/#t Fixes: 15995a352474 ("mm: report per-page metadata information") Signed-off-by: Pasha Tatashin Tested-by: Dan Williams Tested-by: Alison Schofield Acked-by: David Hildenbrand Acked-by: David Rientjes Tested-by: Yi Zhang --- include/linux/mmzone.h | 2 -- include/linux/vmstat.h | 7 ++++--- mm/hugetlb_vmemmap.c | 8 ++++---- mm/mm_init.c | 3 +-- mm/page_alloc.c | 1 - mm/page_ext.c | 18 ++++------------- mm/sparse-vmemmap.c | 11 ++++------ mm/sparse.c | 5 ++--- mm/vmstat.c | 46 ++++++++++++++++++++---------------------- 9 files changed, 41 insertions(+), 60 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 41458892bc8a..1dc6248feb83 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -220,8 +220,6 @@ enum node_stat_item { PGDEMOTE_KSWAPD, PGDEMOTE_DIRECT, PGDEMOTE_KHUGEPAGED, - NR_MEMMAP, /* page metadata allocated through buddy allocator */ - NR_MEMMAP_BOOT, /* page metadata allocated through boot allocator */ NR_VM_NODE_STAT_ITEMS }; diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 9ab4fa5e09b5..9eb77c9007e6 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -38,6 +38,8 @@ struct reclaim_stat { enum vm_stat_item { NR_DIRTY_THRESHOLD, NR_DIRTY_BG_THRESHOLD, + NR_MEMMAP_PAGES, /* page metadata allocated through buddy allocator */ + NR_MEMMAP_BOOT_PAGES, /* page metadata allocated through boot allocator */ NR_VM_STAT_ITEMS, }; @@ -618,7 +620,6 @@ static inline void lruvec_stat_sub_folio(struct folio *folio, lruvec_stat_mod_folio(folio, idx, -folio_nr_pages(folio)); } -void __meminit mod_node_early_perpage_metadata(int nid, long delta); -void __meminit store_early_perpage_metadata(void); - +void memmap_boot_pages_add(long delta); +void memmap_pages_add(long delta); #endif /* _LINUX_VMSTAT_H */ diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 4f51e0596197..0c3f56b3578e 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -185,11 +185,11 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, static inline void free_vmemmap_page(struct page *page) { if (PageReserved(page)) { + memmap_boot_pages_add(-1); free_bootmem_page(page); - mod_node_page_state(page_pgdat(page), NR_MEMMAP_BOOT, -1); } else { + memmap_pages_add(-1); __free_page(page); - mod_node_page_state(page_pgdat(page), NR_MEMMAP, -1); } } @@ -341,7 +341,7 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, copy_page(page_to_virt(walk.reuse_page), (void *)walk.reuse_addr); list_add(&walk.reuse_page->lru, vmemmap_pages); - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, 1); + memmap_pages_add(1); } /* @@ -396,7 +396,7 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end, goto out; list_add(&page->lru, list); } - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, nr_pages); + memmap_pages_add(nr_pages); return 0; out: diff --git a/mm/mm_init.c b/mm/mm_init.c index 75c3bd42799b..f9a60ffc5532 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1623,8 +1623,7 @@ static void __init alloc_node_mem_map(struct pglist_data *pgdat) panic("Failed to allocate %ld bytes for node %d memory map\n", size, pgdat->node_id); pgdat->node_mem_map = map + offset; - mod_node_early_perpage_metadata(pgdat->node_id, - DIV_ROUND_UP(size, PAGE_SIZE)); + memmap_boot_pages_add(DIV_ROUND_UP(size, PAGE_SIZE)); pr_debug("%s: node %d, pgdat %08lx, node_mem_map %08lx\n", __func__, pgdat->node_id, (unsigned long)pgdat, (unsigned long)pgdat->node_mem_map); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 28f80daf5c04..875d76e8684a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5755,7 +5755,6 @@ void __init setup_per_cpu_pageset(void) for_each_online_pgdat(pgdat) pgdat->per_cpu_nodestats = alloc_percpu(struct per_cpu_nodestat); - store_early_perpage_metadata(); } __meminit void zone_pcp_init(struct zone *zone) diff --git a/mm/page_ext.c b/mm/page_ext.c index c191e490c401..641d93f6af4c 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -214,8 +214,7 @@ static int __init alloc_node_page_ext(int nid) return -ENOMEM; NODE_DATA(nid)->node_page_ext = base; total_usage += table_size; - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP_BOOT, - DIV_ROUND_UP(table_size, PAGE_SIZE)); + memmap_boot_pages_add(DIV_ROUND_UP(table_size, PAGE_SIZE)); return 0; } @@ -275,10 +274,8 @@ static void *__meminit alloc_page_ext(size_t size, int nid) else addr = vzalloc_node(size, nid); - if (addr) { - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, - DIV_ROUND_UP(size, PAGE_SIZE)); - } + if (addr) + memmap_pages_add(DIV_ROUND_UP(size, PAGE_SIZE)); return addr; } @@ -323,25 +320,18 @@ static void free_page_ext(void *addr) { size_t table_size; struct page *page; - struct pglist_data *pgdat; table_size = page_ext_size * PAGES_PER_SECTION; + memmap_pages_add(-1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); if (is_vmalloc_addr(addr)) { - page = vmalloc_to_page(addr); - pgdat = page_pgdat(page); vfree(addr); } else { page = virt_to_page(addr); - pgdat = page_pgdat(page); BUG_ON(PageReserved(page)); kmemleak_free(addr); free_pages_exact(addr, table_size); } - - mod_node_page_state(pgdat, NR_MEMMAP, - -1L * (DIV_ROUND_UP(table_size, PAGE_SIZE))); - } static void __free_page_ext(unsigned long pfn) diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 1dda6c53370b..edcc7a6b0f6f 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -469,13 +469,10 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn, if (r < 0) return NULL; - if (system_state == SYSTEM_BOOTING) { - mod_node_early_perpage_metadata(nid, DIV_ROUND_UP(end - start, - PAGE_SIZE)); - } else { - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP, - DIV_ROUND_UP(end - start, PAGE_SIZE)); - } + if (system_state == SYSTEM_BOOTING) + memmap_boot_pages_add(DIV_ROUND_UP(end - start, PAGE_SIZE)); + else + memmap_pages_add(DIV_ROUND_UP(end - start, PAGE_SIZE)); return pfn_to_page(pfn); } diff --git a/mm/sparse.c b/mm/sparse.c index e4b830091d13..0f018c6f9ec5 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -463,7 +463,7 @@ static void __init sparse_buffer_init(unsigned long size, int nid) sparsemap_buf = memmap_alloc(size, section_map_size(), addr, nid, true); sparsemap_buf_end = sparsemap_buf + size; #ifndef CONFIG_SPARSEMEM_VMEMMAP - mod_node_early_perpage_metadata(nid, DIV_ROUND_UP(size, PAGE_SIZE)); + memmap_boot_pages_add(DIV_ROUND_UP(size, PAGE_SIZE)); #endif } @@ -643,8 +643,7 @@ static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages, unsigned long start = (unsigned long) pfn_to_page(pfn); unsigned long end = start + nr_pages * sizeof(struct page); - mod_node_page_state(page_pgdat(pfn_to_page(pfn)), NR_MEMMAP, - -1L * (DIV_ROUND_UP(end - start, PAGE_SIZE))); + memmap_pages_add(-1L * (DIV_ROUND_UP(end - start, PAGE_SIZE))); vmemmap_free(start, end, altmap); } static void free_map_bootmem(struct page *memmap) diff --git a/mm/vmstat.c b/mm/vmstat.c index 6f8aa4766f16..e875f2a4915f 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1033,6 +1033,24 @@ unsigned long node_page_state(struct pglist_data *pgdat, } #endif +/* + * Count number of pages "struct page" and "struct page_ext" consume. + * nr_memmap_boot_pages: # of pages allocated by boot allocator + * nr_memmap_pages: # of pages that were allocated by buddy allocator + */ +static atomic_long_t nr_memmap_boot_pages = ATOMIC_LONG_INIT(0); +static atomic_long_t nr_memmap_pages = ATOMIC_LONG_INIT(0); + +void memmap_boot_pages_add(long delta) +{ + atomic_long_add(delta, &nr_memmap_boot_pages); +} + +void memmap_pages_add(long delta) +{ + atomic_long_add(delta, &nr_memmap_pages); +} + #ifdef CONFIG_COMPACTION struct contig_page_info { @@ -1255,11 +1273,11 @@ const char * const vmstat_text[] = { "pgdemote_kswapd", "pgdemote_direct", "pgdemote_khugepaged", - "nr_memmap", - "nr_memmap_boot", /* system-wide enum vm_stat_item counters */ "nr_dirty_threshold", "nr_dirty_background_threshold", + "nr_memmap_pages", + "nr_memmap_boot_pages", #if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG) /* enum vm_event_item counters */ @@ -1827,6 +1845,8 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos) global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD, v + NR_DIRTY_THRESHOLD); + v[NR_MEMMAP_PAGES] = atomic_long_read(&nr_memmap_pages); + v[NR_MEMMAP_BOOT_PAGES] = atomic_long_read(&nr_memmap_boot_pages); v += NR_VM_STAT_ITEMS; #ifdef CONFIG_VM_EVENT_COUNTERS @@ -2285,25 +2305,3 @@ static int __init extfrag_debug_init(void) module_init(extfrag_debug_init); #endif - -/* - * Page metadata size (struct page and page_ext) in pages - */ -static unsigned long early_perpage_metadata[MAX_NUMNODES] __meminitdata; - -void __meminit mod_node_early_perpage_metadata(int nid, long delta) -{ - early_perpage_metadata[nid] += delta; -} - -void __meminit store_early_perpage_metadata(void) -{ - int nid; - struct pglist_data *pgdat; - - for_each_online_pgdat(pgdat) { - nid = pgdat->node_id; - mod_node_page_state(NODE_DATA(nid), NR_MEMMAP_BOOT, - early_perpage_metadata[nid]); - } -}