From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13EDE41F5D9; Fri, 7 Aug 2026 15:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786115156; cv=none; b=uqeC/vTBWYIT85ZlbyYAQ6QhV03NPQ0orHCt1JS04B4D6M8KCg+1D4dYxrn1D+0uUrnINMv3Mke9fmhBcudB8tznrtEoQeshxXvpTUE84MDDKHHoPMVE194y9KNQOH+uLT+2/wMtNGavJuoBQQnUzD6SmnnsGgvLkBIMAkqaMvk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786115156; c=relaxed/simple; bh=lHcwaisxCsANyDfT1tjxsMa4iwLRFSmIuCjdNrfL+EY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hghp+r8axcuLwgLU+gEBt8R7L5kiw/HMVoYWq1eWNKVZAJcUtdt2G4XcbRc2ATQt1zaktE9t5KHxOxNHoZl012eQbeJSfPknwlkooAyoFn0FBdB74owwNLPJLro/zucXa0tnrnyCLJ6DK3ezvK98EQwxJnqmhhCx9pyknvY4S20= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Wo0UGIHO; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Wo0UGIHO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E724E1F000E9; Fri, 7 Aug 2026 15:05:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786115152; bh=5tOZs4igA77iRXrqfLpJnCgymhie1LoYTCJt2MQ6Qyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Wo0UGIHOFOsJCq1QNh7JfMgyDvHCjKydytnD/m2w2AFMOERkndw7szBEUzPocmqv4 1L+lSibgzwQITvlnSS2oTGFO2xNs19qc8hjWfoRUq3GW8Xb7gBOua6NWD0/ivvDI31 HqthQNzkhxrKC4ftlTsK25mkpGORP8xim7iTH0Gc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Gregory Price , Johannes Weiner , Mel Gorman , Mike Rapoport , Vlastimil Babka , Andrew Morton Subject: [PATCH 6.18 175/396] mm/vmstat: fold stranded per-cpu node stats when a node comes online Date: Fri, 7 Aug 2026 16:35:35 +0200 Message-ID: <20260807143428.074309275@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143424.272339768@linuxfoundation.org> References: <20260807143424.272339768@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gregory Price commit ea3034b2b00fa50c8d2518d0804c9d427bbafa86 upstream. A per-node vmstat counter is pgdat->vm_stat[] plus per-cpu deltas. A balanced counter can sit split as global=+N / per-cpu=-N. The folds reconciling the split only walk online nodes, so when try_offline_node() marks a node offline the per-cpu deltas are stranded. A subsequent online resets the per-cpu area but not pgdat->vm_stat[], orphaning the +N permanently. All NR_VM_NODE_STAT_ITEMS are affected. The existing code zeroes the per-cpu counters and causes a permanent skew. Fold the stranded deltas instead, before the node rejoins the online set. The node is not online yet and the hotplug lock is held, so the remote access to per-cpu values is safe. Discovered when node compaction hung for a nearly empty node, as the math to determine throttling broke. Reproduced by repeated memory hotplug/unplug cycles on a node under pressure: NR_ISOLATED_ANON ratchets up and never returns to zero. Link: https://lore.kernel.org/20260627202243.758289-1-gourry@gourry.net Fixes: 75ef71840539 ("mm, vmstat: add infrastructure for per-node vmstats") Signed-off-by: Gregory Price Cc: Johannes Weiner Cc: Mel Gorman Cc: Mike Rapoport Cc: Vlastimil Babka Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/mm_init.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1565,7 +1565,7 @@ void __ref free_area_init_core_hotplug(s { int nid = pgdat->node_id; enum zone_type z; - int cpu; + int cpu, i; pgdat_init_internals(pgdat); @@ -1583,10 +1583,17 @@ void __ref free_area_init_core_hotplug(s pgdat->node_start_pfn = 0; pgdat->node_present_pages = 0; - for_each_online_cpu(cpu) { - struct per_cpu_nodestat *p; + /* + * Hot-unplug can leave per-cpu vmstat deltas unfolded (folders skip + * offline nodes) - reconcile this at online. Foreign access to counters + * is safe: the node is not online yet and we hold the hotplug lock. + */ + for_each_possible_cpu(cpu) { + struct per_cpu_nodestat *p = per_cpu_ptr(pgdat->per_cpu_nodestats, cpu); - p = per_cpu_ptr(pgdat->per_cpu_nodestats, cpu); + for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) + if (p->vm_node_stat_diff[i]) + node_page_state_add(p->vm_node_stat_diff[i], pgdat, i); memset(p, 0, sizeof(*p)); }