From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5F3E21578D for ; Fri, 20 Feb 2026 19:10:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771614640; cv=none; b=r/1sLTcqT9qt3ji+U23vMvQ0VsasgTloNmkL8k4jkxz0dlLwz0Te8GHR18tL2vBHi1DBNOfiXRSmdtUxiW3JSzhRDD+Cs1cJX3o2atu7oybQNLj95ij0fEMzC1Y/lbSvEHW8L3AucO8tO4NpVDNA9S1bkV3I+4X1TVte/cHoYwA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771614640; c=relaxed/simple; bh=sjzHicn/XuRN/ik3PoytqdDZ7F4UK/PXCnsncIr2GLA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=b60ETOtEohc+cG8EWOTqvOVmitIX7+2qIFH813Y8wuzTevaM92pOo8+IswylT5E1fKOGw9VWJ/pFDKfaAz3cvtTrkpibJ0nVn7VeubhYKV2AFWTS78AqXKJpezx/Yt48xVVlms96WglylG1UEtBy1QVIua0MRPMph3NxjdG6qmg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=enLx39iW; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="enLx39iW" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-8cb38e6d164so266723085a.3 for ; Fri, 20 Feb 2026 11:10:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1771614637; x=1772219437; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OWO7RKWgQr+7ICFBB9SCVBLs7NDhlsurdO9niRwwF2Q=; b=enLx39iW0sohtWkqbOpmLyaTh02votxP6EQDyMg8gPBWp+oowZb4q0cSxDrUEQkOD1 dok7vIWs5DKRobWbspv+h38Y71K3ApX9GKFI/NdrKGbyU9DBqM3OtYi370k1xKz/v5SV nIAD0HKZVtsLjE+8iatoNkvG87so5OCFdRdR5WI1PNFK4X3OewiBxGeolaO3mXcAaWep qV6BztasJaDP+HYn8nqGWViNaUKCjB4RZHVNUKmthurfAXGcer/UxqCZJ2tPxZGDA1df zlSdHbtB5mwLvfJxcf7aqFJ6OH270UXy7Lw45+VDP0WV/10N6uRAFLZ9Ra3KZvYV4fK6 xM8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771614637; x=1772219437; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OWO7RKWgQr+7ICFBB9SCVBLs7NDhlsurdO9niRwwF2Q=; b=F1/wt2WwZvlQo02Xz6YzMKWsf1h///egMIf3Cnssc3Kj1i+nmJgHCa28Oc595TNdZl 96BUGLKaVGJz2d1tjqvCrstr7WfywnrbBQUmjOXUGc7+oi1/l66N8xdeeSRo2lyKqZuJ TpKVByfOALejH3Q3+W65LGcB4LWe/gBrxisw8vFAVqLc73PRyUZ8m8XlOQQlhIoOVbDs VmZ0AS/zSrJ76E4VgBtQFTDjPey+Sc53ESsUaqyi96eY2uZkM0Gvo7kNoMT71OrFFfqd HAbVBcLGR3QSvqWGkztGL0OZo5jILouJ6934T/D0Wwl5HuXWmeaWXihqr3lUAJHzrxfE 22gw== X-Forwarded-Encrypted: i=1; AJvYcCUw5Ue86Uc58vOn2pAY583pxQ77NBqswjtQr1gXmS8ONuqxL8rzJ7hphkAZ6PCk/sbusc7/aeDwQZlJNa4=@vger.kernel.org X-Gm-Message-State: AOJu0YygOGpuFVP4ZKYms7BsRHMOlBP9Mbafh4LPyDv5mqTc2OFrVEV5 TSgFOw3yXLaeMjlJWxmZSwP1GZIGJmj6UxR5Ll+rVRJXWzYEaL6AH2I5fmlfcc8EU54= X-Gm-Gg: AZuq6aL7OS8ZtsNxOTX87+pEN7f2Ua0ch8/wGo7musMtA3zAIjwyAinSukMCoZoHTPk kLIfFZZzmU0eYfLEN47U0B9CNuC6rr08beHN62bNDDzrIIScqgnRw1KuSRUC1s65T3LPY20Btq7 L4MPLUNmGdPzK8O9PTogrDgKVGF7CHmawFCePDyV1KDYvLcuIbSinkA7oZ0xV254FEpEaMWh4Xm 0vb9ECc2kjeHMJZeX1v0FzkGCoVVQaUM3Pl009PQJLQqrdGS5XNoJks4yCKadVjJEOEGKwdHWsg Sw9AEx8tH3UDFWMDKJ3hdC69PMcCeihFUxgmv5Uep0nnxeU4RdePReWuBn8MjmDsWFl+9fCM6L0 +qS2U3RTnkVjHinY1vGRNSMa2CiosgwvAvRIxn2Zw0lLwKWYCGHw8I6h0q7dcHpCDkdyHdUpcug 0rjL8KRjz4ilPsCC5rSP67bnV7siusGP3W X-Received: by 2002:a05:620a:d8d:b0:8c6:a5bc:8a90 with SMTP id af79cd13be357-8cb8c9e0086mr82079585a.14.1771614636634; Fri, 20 Feb 2026 11:10:36 -0800 (PST) Received: from localhost ([2603:7000:c00:3a00:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cb8d0ebcd0sm22196885a.28.2026.02.20.11.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 11:10:36 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Uladzislau Rezki , Joshua Hahn , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: vmalloc: streamline vmalloc memory accounting Date: Fri, 20 Feb 2026 14:10:34 -0500 Message-ID: <20260220191035.3703800-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use a vmstat counter instead of a custom, open-coded atomic. This has the added benefit of making the data available per-node, and prepares for cleaning up the memcg accounting as well. Signed-off-by: Johannes Weiner --- fs/proc/meminfo.c | 3 ++- include/linux/mmzone.h | 1 + include/linux/vmalloc.h | 3 --- mm/vmalloc.c | 19 ++++++++++--------- mm/vmstat.c | 1 + 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index a458f1e112fd..549793f44726 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -126,7 +126,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v) show_val_kb(m, "Committed_AS: ", committed); seq_printf(m, "VmallocTotal: %8lu kB\n", (unsigned long)VMALLOC_TOTAL >> 10); - show_val_kb(m, "VmallocUsed: ", vmalloc_nr_pages()); + show_val_kb(m, "VmallocUsed: ", + global_node_page_state(NR_VMALLOC)); show_val_kb(m, "VmallocChunk: ", 0ul); show_val_kb(m, "Percpu: ", pcpu_nr_pages()); diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index fc5d6c88d2f0..64df797d45c6 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -220,6 +220,7 @@ enum node_stat_item { NR_KERNEL_MISC_RECLAIMABLE, /* reclaimable non-slab kernel pages */ NR_FOLL_PIN_ACQUIRED, /* via: pin_user_page(), gup flag: FOLL_PIN */ NR_FOLL_PIN_RELEASED, /* pages returned via unpin_user_page() */ + NR_VMALLOC, NR_KERNEL_STACK_KB, /* measured in KiB */ #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK) NR_KERNEL_SCS_KB, /* measured in KiB */ diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index e8e94f90d686..3b02c0c6b371 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -286,8 +286,6 @@ int unregister_vmap_purge_notifier(struct notifier_block *nb); #ifdef CONFIG_MMU #define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START) -unsigned long vmalloc_nr_pages(void); - int vm_area_map_pages(struct vm_struct *area, unsigned long start, unsigned long end, struct page **pages); void vm_area_unmap_pages(struct vm_struct *area, unsigned long start, @@ -304,7 +302,6 @@ static inline void set_vm_flush_reset_perms(void *addr) #else /* !CONFIG_MMU */ #define VMALLOC_TOTAL 0UL -static inline unsigned long vmalloc_nr_pages(void) { return 0; } static inline void set_vm_flush_reset_perms(void *addr) {} #endif /* CONFIG_MMU */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index e286c2d2068c..a49a46de9c4f 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1063,14 +1063,8 @@ static BLOCKING_NOTIFIER_HEAD(vmap_notify_list); static void drain_vmap_area_work(struct work_struct *work); static DECLARE_WORK(drain_vmap_work, drain_vmap_area_work); -static __cacheline_aligned_in_smp atomic_long_t nr_vmalloc_pages; static __cacheline_aligned_in_smp atomic_long_t vmap_lazy_nr; -unsigned long vmalloc_nr_pages(void) -{ - return atomic_long_read(&nr_vmalloc_pages); -} - static struct vmap_area *__find_vmap_area(unsigned long addr, struct rb_root *root) { struct rb_node *n = root->rb_node; @@ -3463,11 +3457,11 @@ void vfree(const void *addr) * High-order allocs for huge vmallocs are split, so * can be freed as an array of order-0 allocations */ + if (!(vm->flags & VM_MAP_PUT_PAGES)) + dec_node_page_state(page, NR_VMALLOC); __free_page(page); cond_resched(); } - if (!(vm->flags & VM_MAP_PUT_PAGES)) - atomic_long_sub(vm->nr_pages, &nr_vmalloc_pages); kvfree(vm->pages); kfree(vm); } @@ -3655,6 +3649,8 @@ vm_area_alloc_pages(gfp_t gfp, int nid, continue; } + mod_node_page_state(page, NR_VMALLOC, 1 << large_order); + split_page(page, large_order); for (i = 0; i < (1U << large_order); i++) pages[nr_allocated + i] = page + i; @@ -3675,6 +3671,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid, if (!order) { while (nr_allocated < nr_pages) { unsigned int nr, nr_pages_request; + int i; /* * A maximum allowed request is hard-coded and is 100 @@ -3698,6 +3695,9 @@ vm_area_alloc_pages(gfp_t gfp, int nid, nr_pages_request, pages + nr_allocated); + for (i = nr_allocated; i < nr_allocated + nr; i++) + inc_node_page_state(pages[i], NR_VMALLOC); + nr_allocated += nr; /* @@ -3722,6 +3722,8 @@ vm_area_alloc_pages(gfp_t gfp, int nid, if (unlikely(!page)) break; + mod_node_page_state(page, NR_VMALLOC, 1 << order); + /* * High-order allocations must be able to be treated as * independent small pages by callers (as they can with @@ -3864,7 +3866,6 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, vmalloc_gfp_adjust(gfp_mask, page_order), node, page_order, nr_small_pages, area->pages); - atomic_long_add(area->nr_pages, &nr_vmalloc_pages); /* All pages of vm should be charged to same memcg, so use first one. */ if (gfp_mask & __GFP_ACCOUNT && area->nr_pages) mod_memcg_page_state(area->pages[0], MEMCG_VMALLOC, diff --git a/mm/vmstat.c b/mm/vmstat.c index d6e814c82952..bc199c7cd07b 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1270,6 +1270,7 @@ const char * const vmstat_text[] = { [I(NR_KERNEL_MISC_RECLAIMABLE)] = "nr_kernel_misc_reclaimable", [I(NR_FOLL_PIN_ACQUIRED)] = "nr_foll_pin_acquired", [I(NR_FOLL_PIN_RELEASED)] = "nr_foll_pin_released", + [I(NR_VMALLOC)] = "nr_vmalloc", [I(NR_KERNEL_STACK_KB)] = "nr_kernel_stack", #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK) [I(NR_KERNEL_SCS_KB)] = "nr_shadow_call_stack", -- 2.53.0