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 D367534389F for ; Sat, 27 Jun 2026 20:22:51 +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=1782591773; cv=none; b=A92VkHTIiGiRKJmzRDaaFoVbgreU5NHU0lR+zEvmRGKnX7VwPlF//tOeGGAGaJ+0ciXp6WbPuZ4ymwa0XOxGEoxjb579eHkRXMdlsynd2/w/QOhwXSxyN2YuE4mtlTcZKTF8TqR4r8axE6uVuK/6y1dFSo+n3zAxQ2ktPGypjB8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782591773; c=relaxed/simple; bh=1Dx/SN13LaO4YOQJBrAbaMZKNnc5ymRZr+kDWIebbVM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=eRlBuL2dE7Yt+4FAnMMKT/1QNfluLL+yZ1bJdQzclOEeY/FWmiICrisBZyEMzzvz+EPqdW44Lf7D1GYLTRnCvCneGaxT005cd3TwNQIy9KIr2hPKP/3dR4/YIQV4d2QObd83vUov3q7xwwsOaGYAMptTmSR/fa9MsLxfgOU4avQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=hOuPGOhO; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="hOuPGOhO" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-9204711e831so267129285a.2 for ; Sat, 27 Jun 2026 13:22:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1782591771; x=1783196571; 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=WwSxUHfK3Ujh5X+1LGpk4GjnutPBz0h9+pc9vXkph2E=; b=hOuPGOhOBfrVKC6vlTM0WwPDLDOVWtYmkAYw6unoy475wmw5DvfBR8oJhmRh/fCE5A Vw0EWwAI6tg8ImbLhncfFbkjfk2ZZUzU/cR1k80hHfp+IdmA6w8a2ArLFkPEjeIpNarh tj6WyOwpSgZ1aDEjffA5oelhufouyyFl0zfQEUzGA7NKpn0Bm+SbqQipGqmVuRMg0xjG KjyqH5pjJSW1JugGAWEgW+u5yzQORSf0rq0b0v2q5MxJ9ppWmw15xoaW0N8xP4SsP/DF zRjf3Sd3cIlwnMpjT5UXFT0T6TX4Mj9+L3C4Pz2dZnF8cbYUtvvroUG6bo3+HuKRSqay KlyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782591771; x=1783196571; 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=WwSxUHfK3Ujh5X+1LGpk4GjnutPBz0h9+pc9vXkph2E=; b=OKq0eBkiHDY9J1JQzN1r46q5O1cBCwB72OsDibhbD1SCMgAbUS3xJodkyyF0khdT9E FE8H4XzAN9JJQ1GWJJmhMMde/L86eaDKHQJBHlKA8GHQZtfnB8UY5w9rNllzUbohCQdp BTDOO49Obegig5b48sDpqsSstp/51+XzYs+GWiEko4DipVsjrzXfi4sYf8DKEvQWCl// 8l8OsDWO3Bpn8LRon/UkueFP585vkRc71SlSM9WhpJBshzhI4ktdtpm4mxDIPtQwqnpV S3AfsRAUVTpCu0aQTHngDfOc+7uSlgUnofU0oYY5zJYeUP/YFrkIYeWw7HxtSQZSvvBf c23Q== X-Gm-Message-State: AOJu0YykeLsYaPv9d8C64EXtv6ToeatGMS1z2TtGKMtvPsLVYwGR5Foh 6cAIeJlZw/mLLZK0FDVR/EwKSV4nCJlP+r5uTf5Ynt11I204KwZLoeB6IOkkVGhLnOHHI/LE1cZ LIYJi X-Gm-Gg: AfdE7clBODCUb0kq3VSc2TTmGjPd72VTS7p+ijMLfOhEzNf7WUuIboIV14lelbJu60U yTfs/R4Tbgz8mOqvwLV/Hhv4CySPvh2KSoWc14tc3Zgh1DNvz/L/b3si0EGnlb3gqr+UawFvhnY lP2rfoNpoiORLXX98GgsCCtLyv3MaBdj9DHZvMdMYTerfU5cR6AbIaz4EL1wlU3ka1m1bOQXW/f EzHe94p4tfow6eWgqdk0YYgaWWVw0H9ve1jmVPmlX3v1thOgqV9fsk3chBmDb9qrmJhiX14kEod 3A0rQXmLtKiiW9sQ7kR5ginDgpH782Gh+ztMDElmFWNTGPhH8QFkEknDmQnLmeUsCB4oWC08iJb /iem3B7ZqynWlerMpJQNcWOvmcwlEk78DyjCUu81aKviuKvpQCcyJ5DPACLym7QsxjpxeszNaA2 OPk5TUOWpCbFneYNBQM87Z4k0wlh99JSykQLTqMkBHtytwSaGp0/Y8tBMnMENQRiHHV2eI9uwLM A== X-Received: by 2002:a05:620a:2892:b0:915:9fba:878b with SMTP id af79cd13be357-9293a0dc1fdmr1634247985a.9.1782591770824; Sat, 27 Jun 2026 13:22:50 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-92600c7bf55sm1540125485a.46.2026.06.27.13.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jun 2026 13:22:50 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rppt@kernel.org, akpm@linux-foundation.org, vbabka@kernel.org, mgorman@techsingularity.net, hannes@cmpxchg.org, stable@vger.kernel.org Subject: [PATCH v2] mm/vmstat: fold stranded per-cpu node stats when a node comes online Date: Sat, 27 Jun 2026 16:22:43 -0400 Message-ID: <20260627202243.758289-1-gourry@gourry.net> X-Mailer: git-send-email 2.54.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 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. Fixes: 75ef71840539 ("mm, vmstat: add infrastructure for per-node vmstats") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price --- mm/mm_init.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index f5301d4de91a..c119f6f1497d 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1536,7 +1536,7 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat) { int nid = pgdat->node_id; enum zone_type z; - int cpu; + int cpu, i; pgdat_init_internals(pgdat); @@ -1554,10 +1554,17 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat) 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)); } -- 2.53.0-Meta