From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 14B8E1862A for ; Fri, 20 Feb 2026 19:10:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771614640; cv=none; b=GDDthgWPLUgjM1ai3d71w6xugOZ8/TG+aOaThWocTEIHmdmiHo/IdUediHh6FDWD0vJioNjaYYdvX0O8q0mVL9k1obi8uHd8BCWJLt84gm/qg24htNPDImlEurCBhHDBQe4CNrAfk8flRAy9e6WYhTNiPHHMenu+bSMJlkj0GbQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771614640; c=relaxed/simple; bh=utJESbMjuYKt520hS9qyPp85rEhDO7vmzpqGJ8Lrwno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZnT48jSFA5lpbEHGer4yS0XcNh3GZbsESU7kBfqsRh1jmrgOxHxytWzNltxzhZmYOBwcISniR3NFUoBOv6QjWZdKQ7Q3cOpAhyeHBwwypqjyLLzoYE7WgtFuQRBL774dbjK0nGuE/IYsfoQIUpA8EZX0PSm26HAAzEJH2sb6tD8= 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=TmnfVjnI; arc=none smtp.client-ip=209.85.219.44 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="TmnfVjnI" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-8954c9daaeaso29775676d6.1 for ; Fri, 20 Feb 2026 11:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1771614638; x=1772219438; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zRgCQhFlEEQQz8iVKpR/+XrwMVRXcKNbXIMlR69ixQE=; b=TmnfVjnIZhLDXV3cs5Pg0CEBeFf10iPC7u5atUalRV09oU+/sJrJfsNeKocLjoxI15 YKH95ixb796wOFaiHY8E0dasqQvYXrCej1R1SnQ9s5tM97OiEiH/nO29si5ZOtO6Efy0 1vW+ORiXD1KUYGHtc/tJqvK2Tvwuxsdkgo2w0tHjTDgGmGw8vvwQYOkOtuOwDWE2rXmt k2a5xyZfJJBtZtwODU0emXcQjVxGwX+WBOcKDaNth/aKA5LJ19fQ+crHGiqsk03VTOpE wAVXPfLDZsp/g2uFW73cjP+F9GO/GR6gH3n5AazPFe1issJiOjwOOvBj66CWQEEnNMCO ZseQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771614638; x=1772219438; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zRgCQhFlEEQQz8iVKpR/+XrwMVRXcKNbXIMlR69ixQE=; b=s6k72TTOpy9/ni+MLm6JSdU+9/u8/6/bAJIoKp0/7iQA4V/CKpd0fKVHneLOt16tsT 3RW6ruqSzf+8i7wyaO3ShjuVJisQXv0pIFw6+Agjlw43xCrRHnfCk9pahg/2LotYth4P X6VqkXikePvoiVUxjl6phVQexcUURGxmOlPVzw0Z6mNY9ztOGUmDD2BzoIVQ7X9NR5Rs jG8F+Kw0uF7bKE9LgNG58cFTy8R4Vb3xzM7W4REBsFMP+cvvElAuBubOcR3cIkzp1fbY 1DnkJmeK0wSR2c/QyK5pJ+VzMq4uqOeliSZDmTL4vVoxtUlTV8UTML/XCjDbXJ4kxpX6 ayLQ== X-Forwarded-Encrypted: i=1; AJvYcCWnAzjzAJMc1mL5Sr43Mg2bjDq0REuHUSynf7C1eKHgldLqiZpiD6SsRKLN/NTmJ03TjNNd6B412XPlU94=@vger.kernel.org X-Gm-Message-State: AOJu0YxLGo+QOGczFkHX18isSn5cNkq5fKHk7Tm2EHWSGj8SHpS+b3zM uZZVxe/L4Vm8nhyzfqUcSdlvjMF+mcIZZh7bw8tYDYtvKqowcZHfI278sHv2QA7N+co= X-Gm-Gg: AZuq6aLmJ72OVzfXnrro6nE2j45DP3Lt4Gw5FMbgI0f40V6VB5SmiXkbprgqALYQWUa Rf5vfiSckR7K95iuueUfCZG6o/3Hr+VZIoqxgCwpPvD1Ur6X9eGksvoXAp4Bs/kLCTLwFcLZRSt NKMqVCnRpAuBCvE7V2DOjm1FHS2y6BqvXceqyjyYYSloFgQ7fLFwTovgrhkDZTgEiZSybEUQ7uI NO0UfE11Hu1+NggZqeRfTz3f8kZtWpGaef5sBrPsd6MDmx2AN7u7NahYqvVpodHr2IBsGyGgtK6 LpwsdLeatVA7rKe54wDclzU8MLVkEo3Ha1PPxJfdTyMP/oQsAQPhfabSOZ8jYzQKMHUnxOkJurx 7TXFe9lGo+f6/C+VWanGB0VVcQaw4+NagsxAMIzG7REhxu8ykrS8XAaqVzLsGdWO5/4OjuUXrVU y9QoqQGwXgohr5YiNiCBZdRA== X-Received: by 2002:ad4:5c6e:0:b0:894:562d:c0b9 with SMTP id 6a1803df08f44-89979d45c79mr15844316d6.0.1771614638028; Fri, 20 Feb 2026 11:10:38 -0800 (PST) Received: from localhost ([2603:7000:c00:3a00:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cb8d1013fesm18977785a.36.2026.02.20.11.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 11:10:37 -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 2/2] mm: memcontrol: switch to native NR_VMALLOC vmstat counter Date: Fri, 20 Feb 2026 14:10:35 -0500 Message-ID: <20260220191035.3703800-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260220191035.3703800-1-hannes@cmpxchg.org> References: <20260220191035.3703800-1-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Eliminates the custom memcg counter and results in a single, consolidated accounting call in vmalloc code. Signed-off-by: Johannes Weiner --- include/linux/memcontrol.h | 1 - mm/memcontrol.c | 4 ++-- mm/vmalloc.c | 16 ++++------------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 67f154de10bc..c7cc4e50e59a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -35,7 +35,6 @@ enum memcg_stat_item { MEMCG_SWAP = NR_VM_NODE_STAT_ITEMS, MEMCG_SOCK, MEMCG_PERCPU_B, - MEMCG_VMALLOC, MEMCG_KMEM, MEMCG_ZSWAP_B, MEMCG_ZSWAPPED, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 129eed3ff5bb..fef5bdd887e0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -317,6 +317,7 @@ static const unsigned int memcg_node_stat_items[] = { NR_SHMEM_THPS, NR_FILE_THPS, NR_ANON_THPS, + NR_VMALLOC, NR_KERNEL_STACK_KB, NR_PAGETABLE, NR_SECONDARY_PAGETABLE, @@ -339,7 +340,6 @@ static const unsigned int memcg_stat_items[] = { MEMCG_SWAP, MEMCG_SOCK, MEMCG_PERCPU_B, - MEMCG_VMALLOC, MEMCG_KMEM, MEMCG_ZSWAP_B, MEMCG_ZSWAPPED, @@ -1359,7 +1359,7 @@ static const struct memory_stat memory_stats[] = { { "sec_pagetables", NR_SECONDARY_PAGETABLE }, { "percpu", MEMCG_PERCPU_B }, { "sock", MEMCG_SOCK }, - { "vmalloc", MEMCG_VMALLOC }, + { "vmalloc", NR_VMALLOC }, { "shmem", NR_SHMEM }, #ifdef CONFIG_ZSWAP { "zswap", MEMCG_ZSWAP_B }, diff --git a/mm/vmalloc.c b/mm/vmalloc.c index a49a46de9c4f..8773bc0c4734 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3446,9 +3446,6 @@ void vfree(const void *addr) if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS)) vm_reset_perms(vm); - /* All pages of vm should be charged to same memcg, so use first one. */ - if (vm->nr_pages && !(vm->flags & VM_MAP_PUT_PAGES)) - mod_memcg_page_state(vm->pages[0], MEMCG_VMALLOC, -vm->nr_pages); for (i = 0; i < vm->nr_pages; i++) { struct page *page = vm->pages[i]; @@ -3458,7 +3455,7 @@ void vfree(const void *addr) * can be freed as an array of order-0 allocations */ if (!(vm->flags & VM_MAP_PUT_PAGES)) - dec_node_page_state(page, NR_VMALLOC); + mod_lruvec_page_state(page, NR_VMALLOC, -1); __free_page(page); cond_resched(); } @@ -3649,7 +3646,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid, continue; } - mod_node_page_state(page, NR_VMALLOC, 1 << large_order); + mod_lruvec_page_state(page, NR_VMALLOC, 1 << large_order); split_page(page, large_order); for (i = 0; i < (1U << large_order); i++) @@ -3696,7 +3693,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid, pages + nr_allocated); for (i = nr_allocated; i < nr_allocated + nr; i++) - inc_node_page_state(pages[i], NR_VMALLOC); + mod_lruvec_page_state(pages[i], NR_VMALLOC, 1); nr_allocated += nr; @@ -3722,7 +3719,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid, if (unlikely(!page)) break; - mod_node_page_state(page, NR_VMALLOC, 1 << order); + mod_lruvec_page_state(page, NR_VMALLOC, 1 << order); /* * High-order allocations must be able to be treated as @@ -3866,11 +3863,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); - /* 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, - area->nr_pages); - /* * If not enough pages were obtained to accomplish an * allocation request, free them via vfree() if any. -- 2.53.0