From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.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 211A231ED8B for ; Tue, 14 Apr 2026 20:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776198396; cv=none; b=jKS5axBQSV4rwIgdfZz2aHkuw4gRJ72D0oqZ5CaQrr9NXNHpaJub0eYNRGV+zz3LxISgWC17npZ8hfGGXORFGR8oMy1T1e4BQ/xAPC93LnrXmUxE17EFt4+QENo58D5OhO2r9EmH0EP/QBrTq/UIcE4F5O2JOnnKSa8GwShy9BQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776198396; c=relaxed/simple; bh=xiknWtZMkiU4Zkytv6RrDHEpBhs3dGZHdhPAOQp9tBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZT+v6fO3sxpLHuEmAwbGQS+jh+jeow00nqrEuA7RClW9w7sjfl2Yu+BoQMz8akdKOAw0HheDu7crtszN0UbhcclejgIP6kO+H5AoY5P4Gqiau7OVZsguu8y1StWI8J4ZVlYAthFt+xtKE9vwore8S13C6bpnoqY1Sf9Syt6Hk48= 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=DXBQZCMJ; arc=none smtp.client-ip=209.85.167.174 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="DXBQZCMJ" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-47938ef848cso1393009b6e.0 for ; Tue, 14 Apr 2026 13:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776198394; x=1776803194; 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=/UR4m3dl9VK+BroM75Hxq4WeXIJgGbxy3Rl4ETefDxA=; b=DXBQZCMJmGrDA4vI8ZSorRNw3V36/jAClsDxnE1mvmNYmYPo2pg/g8k3ZAXmUFIScz wznwujbmMmYXCwbTSF/XpSBPrVjXw8vqqIV1WdT8g6R4pt8qL34A8zsOOjZD7KIrsfbX uyvmov8QwTT0qkas+PjGsN1eYB5cj3lLxlQDB0fk2Gydt7QzULD8Dwq0tIVxjZx+aJ18 kRjhNIqu+9DeemlzXDKRz5T0UxegxOSuedFmfRafFZtjpjcBCoBvoecFdGTU3a4OKioY ZFzcKpV3tmspXwlfKrWXgbtZGhED3ZbLRi1oj7Zl82hbdWA+RW4cUhxs25/vC4hUq5Zt gKGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776198394; x=1776803194; 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=/UR4m3dl9VK+BroM75Hxq4WeXIJgGbxy3Rl4ETefDxA=; b=f+4wUjQRIQum8IToTx/CSDN6YvVmyR8mATk0RyWBTRbZJzyphB/JPHg7nJUrDVs4X/ Jjeuf3mSmxE88Mcwh1KjE8hDKrhv2UixY8bfLLYzyeA+tKDdmOnUwAHEWHf+7d3FTWJa 4RuiQiYGdCcPjR6ZHnBHSNtbyvPcgkJ/irtQJmZytX/5ggZdVj5MwR5BBDv8l727Rrfi Jx9IFvTmQWj2ZzOrhKaEPpwUka9QMP/g4o//hDelOheC5N7vQmOk5AlUjX3U5V63dKK4 +SLArNkvyUybjPY171FvsBLhKa0f/hhz+oBJ4IibaCDsNPhCUYoWEfs7mdFXijfl0ynS WJDQ== X-Forwarded-Encrypted: i=1; AFNElJ/rcUfWTPAzqRS8hTP43Rdl+T00O0uTKnLZxHCRh85VbwTio6YrbB57Eky9gyGZFpo3y5lcmLdhnLhTHio=@vger.kernel.org X-Gm-Message-State: AOJu0Yzqnf9NTCkqIluhgeJlxsho0gW0nBy+sSrWgHSeTFCYEBFlUHc1 Gebs14wDrWqlf83an7s6NJVboJ+51WLxk7Kr/9TNa3dMWawSM6zpbmni X-Gm-Gg: AeBDieu0sMV1FAO3UbqGW0xG1KU+iI3Nd+yYPyVuYwYAR6HEnl40DTIV6qWZa/sCr4B qDzzgCxuS8JUf6dhrZ7GvvdFh87BogFQl1eg2mvZgVGaBq0Sos9AzfUgbKyFwl4+gBuuJ8Dl5// Toq3YO/wYz5VsAze1cEIerkNYY18ARpMZACZ1kYCshs62WM8Hwu26OoH3ATq2z+dmqwGph0REq6 WSrXpQOuChUk6Cu+C2dq8r1h4NqIaNuhb+J9sKPf6mvu4ItKk+DBo/Y7YrkFEwfvLIZcoi9kNLV Di4aB+J34T4XoWTctPZ4HKR9xv8DPHnc8L1O8n3Qv4SJhy8+DE71xUM45PjXykR0iS/8ldp19mR D8FZGQDKmFVxS0a3nu8xBRhFkd4pnOgEZ8RodaOWWN4/ZhmzFb3txvVaYhNgT7PLOlF7hZlSIro xvqs4bgVqaLWMqPBmFvJPLIQ== X-Received: by 2002:a54:4383:0:b0:45f:13ad:83c1 with SMTP id 5614622812f47-478a19124cbmr7485767b6e.51.1776198393796; Tue, 14 Apr 2026 13:26:33 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:44::]) by smtp.gmail.com with ESMTPSA id 5614622812f47-478a0f1e841sm8167402b6e.5.2026.04.14.13.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 13:26:33 -0700 (PDT) From: Joshua Hahn To: Joshua Hahn 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, Harry Yoo Subject: Re: [PATCH v2] mm/percpu, memcontrol: Per-memcg-lruvec percpu accounting Date: Tue, 14 Apr 2026 13:26:31 -0700 Message-ID: <20260414202631.2753640-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260404033844.1892595-1-joshua.hahnjy@gmail.com> 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 Fri, 3 Apr 2026 20:38:43 -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. [...snip...] > @@ -55,7 +55,8 @@ static void pcpu_free_pages(struct pcpu_chunk *chunk, > struct page **pages, int page_start, int page_end) > { > unsigned int cpu; > - int i; > + int nr_pages = page_end - page_start; > + int i, nid; > > for_each_possible_cpu(cpu) { > for (i = page_start; i < page_end; i++) { > @@ -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); > } > > /** > @@ -84,7 +89,8 @@ static int pcpu_alloc_pages(struct pcpu_chunk *chunk, > gfp_t gfp) > { > unsigned int cpu, tcpu; > - int i; > + int nr_pages = page_end - page_start; > + int i, nid; > > gfp |= __GFP_HIGHMEM; > > @@ -97,6 +103,10 @@ static int pcpu_alloc_pages(struct pcpu_chunk *chunk, > goto err; > } > } > + > + for_each_node(nid) > + mod_node_page_state(NODE_DATA(nid), NR_PERCPU_B, > + nr_pages * nr_cpus_node(nid) * PAGE_SIZE); > return 0; Hello reviewers, Since I submitted this, I have been thinking about the feedback that Sashiko has given this patch [1]. Harry has already pointed out the points about drifting due to CPU hotplug, but one there is one particular concern that I have been trying to tackle with no avail. The issue is, pcpu allocations for CPUs on node A may actually fall back to node B, if node A is out of space and under pressure. This design seems to be intentional, to prevent memory pressure from failing these allocations. However, this means that we cannot charge percpu memory based on the number of CPUs present on a node, because although the memory "belongs" to the node (since the CPU it actually belongs to is on the node), the memory can be serviced from elsewhere. To handle this, I've tried several approaches. All of them were either too expensive (iterating through all pages at allocation / free time) or introduces new drift (I thought of managing per-chunk statistics as well). To be honest, I think I'm out of ideas at this point :/ So I wanted to see what others thought about how to track physical locations for pcpu allocations that were allocated via fallback. Are these rare enough that we are OK with the misattributing here? Should we eat the cost of iterating through all pages to find out where it is physically? Or is this patch not worth pursuing at the moment? ; -) I hope this all makes sense. Thank you all in advance! Joshua [1] https://sashiko.dev/#/patchset/20260404033844.1892595-1-joshua.hahnjy%40gmail.com