From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 A26BE34D39B for ; Wed, 8 Apr 2026 03:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775619630; cv=none; b=iLhJtxyOkUzGJcq9w9u1oDepNA2VYSgzLlh++gnBH0x8Z2XwJScdJdmMNbXU0RzR+/+TYO9mMBz3CyRADxrUSVjSOrQYO4/jmHWDvu7OcVoTT1UpKa1BoTgnSx8M4FK2zVjb4vt6HGSCDXpPZNb6lnd+CTKZeiW6OC/4y/ZWPV0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775619630; c=relaxed/simple; bh=FAyaFLd89C3vKZnxSy4E7CWfgiELeM+2id1WIOxVxUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KnI1diF8o5kJKPpgx6PRv/MNyFUiOkvu5B2bxEHa0IJrf1wO2GUMSxgOKwnLxNvoBMpRC0LFerQ0URbf+LaWD0spE/sXXMJ6wTjEvnGC4EEnmXtkcN2wsppEjANZDKnkjPQe2wYVZIuXDGRH4xow1W5ztbZ6UZ+Hx8u2s/RIAS8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YHQpQSC6; arc=none smtp.client-ip=209.85.210.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YHQpQSC6" Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-7dbd23bc684so1984692a34.2 for ; Tue, 07 Apr 2026 20:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775619627; x=1776224427; 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=c8Ds3pHng15kKOEJE0OjDpk2jM6or+3GmYgHlHYpLlk=; b=YHQpQSC6Y40ZByY5Fo9t14dus7r+tlir7qJnwG6ZfzfXuWczXhL6/6q2RQKiWqq9y6 Hel2v8PeO9dgXLK+dnfRWeN1MUKHzxyLx0kFJRgBpQ6NYukxQpOJmxWk44M3KrimELkj HO005gqUlNcd/Qa3kI2eYS1GeSUQxmCpLrePrVuBBfhFwbwuYV4BgOD7l2L4yK5YLjsz aOXfUTiMRWwqxe+AY9VAh3q5LkK/QjZMpPxK1SjK4weeSYK1lBWl9OIHI/A6zgWBe16p OFBLbri5uSK994/Uk5RENDSGg3444b9TIfzsfNK9UDnKMkK45J4PuFIZNGd8TbMjpeLP LCpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775619627; x=1776224427; 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=c8Ds3pHng15kKOEJE0OjDpk2jM6or+3GmYgHlHYpLlk=; b=VRHdoJmdmTAjaGFPCx+8HiubSZuJXUWrlOpcGTYW4ovAepRR+UNOwvYhhMJfWLzx5j zYXgy5B8/NFEATHeIdZdNdqbdaYYu6sLDQVZ2lfnZ7Rx0oMi/EmrYsRtmB08QdSzCo2S bdL9tJ0i3JPXaLJdDdoERVh9QiKLSPO7fptOYDm8+wv66Z7qFp1vXfKryPwx/v0kgQMC TwLUYkVKA9EvUFwMjHmkKKFWi4xsS4FxygA2qkxEOvLXV2/Dv5QrOWS7i7jL038cptlN f9WPCgn9neqbD29khgyeLh2ZrDllM3723D7bPy1Xpt2ESvlkrCU11esBjeuuBTzZaOHR OqFg== X-Forwarded-Encrypted: i=1; AJvYcCWqadT8Xv5jWjfo2QeSX5M33SuTswWT+cv2U+qHyI6LluC88VIYuQjV6DNCg5RayS32tPk4b1nSy+7Shos=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2xTtxND+n4oyaDEeiAX+Nzk3Uj07d8PKBIPGJwUh1pOz5AZXR XtzqDC5vZ8WI0zMj9PFW8k/NlJGwxs+CoGbAReYahHdL03ekwaSgsm+H X-Gm-Gg: AeBDietb2XamnvMqbidguj3S/iYMUtFOexFt9+ZnzZyTiv9bPuSryymbWoCEOoTD5C2 1eWogCl+jkugCEsKWn/FGz7Zk8aFm7bwXrCqvlkJ+ri3qnfZTd2ZxAsoVyHdcAQUsAgkq147RFQ 0lBN3VrxTiqouwlzj3wlTK2TXjz8ILZga1twtwDDkxi2sRjgVl92g59X57TCzAexq8izUsV+aEs P5I9yZNjskKYmU1lhJnSGOGSBGl3RisvrAGsFDA4/1+p2boN8gpL/EPB3KZoJ5zApSvrGfumOwF L6I28WV/Cot7yWaOsrFsxzqEB69anCDfw55TLlUQ8UzYGa22cztDYpwwU67thbrQo/JFpWGkgD5 RxwHHdOgsGmu4A1jFrvxz0ewR8BEwOMBRKXK91UxpYYaObcOpF0CCWkzLFFttsdxg2UdQ8uhg4c Rz/8qlH5bfRt0eyCUjHIpIWQ== X-Received: by 2002:a05:6830:391c:b0:7d7:419a:7ac8 with SMTP id 46e09a7af769-7dbb7517e0cmr11694018a34.15.1775619627529; Tue, 07 Apr 2026 20:40:27 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:4a::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7dbed6c3512sm3988912a34.4.2026.04.07.20.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 20:40:26 -0700 (PDT) From: Joshua Hahn To: "Harry Yoo (Oracle)" Cc: Johannes Weiner , Andrew Morton , Michal Hocko , Yosry Ahmed , Roman Gushchin , Shakeel Butt , Muchun Song , David Hildenbrand , Lorenzo Stoakes , Vlastimil Babka , Dennis Zhou , Tejun Heo , Christoph Lameter , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH v2] mm/percpu, memcontrol: Per-memcg-lruvec percpu accounting Date: Tue, 7 Apr 2026 20:40:24 -0700 Message-ID: <20260408034025.3317937-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Wed, 8 Apr 2026 11:40:27 +0900 "Harry Yoo (Oracle)" wrote: > On Fri, Apr 03, 2026 at 08:38:43PM -0700, Joshua Hahn wrote: > > enum memcg_stat_item includes memory that is tracked on a per-memcg > > level, but not at a per-node (and per-lruvec) level. Diagnosing > > memory pressure for memcgs in multi-NUMA systems can be difficult, > > since not all of the memory accounted in memcg can be traced back > > to a node. In scenarios where numa nodes in an memcg are asymmetrically > > stressed, this difference can be invisible to the user. > > > > Convert MEMCG_PERCPU_B from a memcg_stat_item to a memcg_node_stat_item > > to give visibility into per-node breakdowns for percpu allocations. > > > > This will get us closer to being able to know the memcg and physical > > association of all memory on the system. Specifically for percpu, this > > granularity will help demonstrate footprint differences on systems with > > asymmetric NUMA nodes. > > > > Because percpu memory is accounted at a sub-PAGE_SIZE level, we must > > account node level statistics (accounted in PAGE_SIZE units) and > > memcg-lruvec statistics separately. Account node statistics when the pcpu > > pages are allocated, and account memcg-lruvec statistics when pcpu > > objects are handed out. > > > > To do account these separately, expose mod_memcg_lruvec_state to be > > used outside of memcontrol. > > > > The memory overhead of this patch is small; it adds 16 bytes > > per-cgroup-node-cpu. For an example machine with 200 CPUs split across > > 2 nodes and 50 cgroups in the system, we see a 312.5 kB increase. Note > > that this is the same cost as any other item in memcg_node_stat_item. > > > > Performance impact is also negligible. These are results from a kernel > > module which performs 100k percpu allocations via __alloc_percpu_gfp > > with GFP_KERNEL | __GFP_ACCOUNT in a cgroup, across 20 trials. > > Batched performs 100k allocations followed by 100k frees, while > > interleaved performs allocation --> free --> allocation ... > > > > +-------------+----------------+--------------+--------------+ > > | Test | linus-upstream | patch | diff | > > +-------------+----------------+--------------+--------------+ > > | Batched | 6586 +/- 51 | 6595 +/- 35 | +9 (0.13%) | > > | Interleaved | 1053 +/- 126 | 1085 +/- 113 | +32 (+0.85%) | > > +-------------+----------------+--------------+--------------+ > > > > One functional change is that there can be a tiny inconsistency between > > the size of the allocation used for memcg limit checking and what is > > charged to each lruvec due to dropping fractional charges when rounding. > > In reality this value is very very small and always lies on the side of > > memory checking at a higher threshold, so there is no behavioral change > > from userspace. > > > > Signed-off-by: Joshua Hahn > > --- > > include/linux/memcontrol.h | 4 +++- > > include/linux/mmzone.h | 4 +++- > > mm/memcontrol.c | 12 +++++----- > > mm/percpu-vm.c | 14 ++++++++++-- > > mm/percpu.c | 45 ++++++++++++++++++++++++++++++++++---- > > mm/vmstat.c | 1 + > > 6 files changed, 66 insertions(+), 14 deletions(-) > > > > diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c > > index 4f5937090590d..e36b639f521dd 100644 > > --- a/mm/percpu-vm.c > > +++ b/mm/percpu-vm.c > > @@ -65,6 +66,10 @@ static void pcpu_free_pages(struct pcpu_chunk *chunk, > > __free_page(page); > > } > > } > > + > > + for_each_node(nid) > > + mod_node_page_state(NODE_DATA(nid), NR_PERCPU_B, > > + -1L * nr_pages * nr_cpus_node(nid) * PAGE_SIZE); > > Can this end up with mis-accounting due to CPU hotplug? Hey Harry, thanks for giving this patch a look! Yes, definitely. I think the solution is just to charge based on possible CPUs, even if that might lead to some inaccuracy (by however many CPUs aren't online at that moment). Seems like that's what already happens in memcg anyways, so I think this discrepancy is OK to tolerate. Will spin up a v3! Thanks a lot, Harry! Have a great day : -) Joshua