From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 89CB72D46B2; Fri, 30 Jan 2026 17:15:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769793329; cv=none; b=F55enGW9vshVwMpLdEfVw7h1KPL1DB9lQSdOZhMJiwf2s5goBciVbQWggP9TPioXqcTgF72oTpUqB3wYbi5Mtp9qNiJMcAl2eGqCfDjXcP+qlgElgiWSU0K11cuNxmsN/HmIzPWOeZLGDuLtL4cHk47tOjoOufJDmmpVflY2pZc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769793329; c=relaxed/simple; bh=jxXn6m945TBmC6BfrDwQWKtLI1+Q7FkOv1CrhidxGy4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oqmnwEyUijE4CmeErXCqP6AkJZywmHFgEYRp1V1nBuIA2bbpR3pImd2BM5sNYDItbQ8qAdWB0R1Z2nHxfhYvdOzulg2tiNyq/AIkI9ytaXicjur3xl80uTevJ0tuncVBfGEYCc+9D1sjLa/xKSUMay5+e61B4Ex0Qb0I5EIMdNc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C2ubaMuB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C2ubaMuB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77291C116C6; Fri, 30 Jan 2026 17:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769793329; bh=jxXn6m945TBmC6BfrDwQWKtLI1+Q7FkOv1CrhidxGy4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=C2ubaMuBK0Dul617ENOHK6lixnYelJ+XGt8YfOvx6lZfWK184M4bTZ5ti9AaJ5WIp +ZGmCRoApw+C+018u39fflu5gGkx+Zcws2tkKY0NCW27ac/KVfceSQ3oKFPGLvbR78 95H7rV6UAtsVdzHvz/nfrjfc5bYEmxZqGnsI2tQWcRQBVTFc3sREWy8oMa7KLuhCqm CVKZRSHMlyBjzeXFqfVzU0crCqE2ZWbGDzytpm6U7TKFi5NAWc/b5AZVkVqd/R9tH7 YRdgOB6h9Y+Fu/k1Em4+mAkAqxA4hCJZUMQtXGeG6Jfz2IAibqotkMUIF6NIHFjXTO erSrVRk67HFdA== Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfauth.phl.internal (Postfix) with ESMTP id 7277AF4007E; Fri, 30 Jan 2026 12:15:27 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Fri, 30 Jan 2026 12:15:27 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduieelieduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepmfhirhihlhcu ufhhuhhtshgvmhgruhcuoehkrghssehkvghrnhgvlhdrohhrgheqnecuggftrfgrthhtvg hrnhepueeijeeiffekheeffffftdekleefleehhfefhfduheejhedvffeluedvudefgfek necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepkhhirh hilhhlodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduieduudeivdeiheeh qddvkeeggeegjedvkedqkhgrsheppehkvghrnhgvlhdrohhrghesshhhuhhtvghmohhvrd hnrghmvgdpnhgspghrtghpthhtohepgedvpdhmohguvgepshhmthhpohhuthdprhgtphht thhopehshhgrkhgvvghlrdgsuhhttheslhhinhhugidruggvvhdprhgtphhtthhopegrkh hpmheslhhinhhugidqfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtohephhgrnhhn vghssegtmhhpgigthhhgrdhorhhgpdhrtghpthhtoheprhhivghlsehsuhhrrhhivghlrd gtohhmpdhrtghpthhtohepshhonhhglhhiuhgsrhgrvhhinhhgsehfsgdrtghomhdprhgt phhtthhopehushgrmhgrrghrihhfieegvdesghhmrghilhdrtghomhdprhgtphhtthhope gurghvihgusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlohhrvghniihordhsthho rghkvghssehorhgrtghlvgdrtghomhdprhgtphhtthhopeiiihihsehnvhhiughirgdrtg homh X-ME-Proxy: Feedback-ID: i10464835:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jan 2026 12:15:25 -0500 (EST) Date: Fri, 30 Jan 2026 17:15:20 +0000 From: Kiryl Shutsemau To: Shakeel Butt Cc: Andrew Morton , Johannes Weiner , Rik van Riel , Song Liu , Usama Arif , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Matthew Wilcox , Meta kernel team , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: khugepaged: fix NR_FILE_PAGES and NR_SHMEM in collapse_file() Message-ID: References: <20260130042925.2797946-1-shakeel.butt@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260130042925.2797946-1-shakeel.butt@linux.dev> On Thu, Jan 29, 2026 at 08:29:25PM -0800, Shakeel Butt wrote: > In META's fleet, we observed high-level cgroups showing zero file memcg > stats while their descendants had non-zero values. Investigation using > drgn revealed that these parent cgroups actually had negative file stats, > aggregated from their children. > > This issue became more frequent after deploying thp-always more widely, > pointing to a correlation with THP file collapsing. The root cause is > that collapse_file() assumes old folios and the new THP belong to the > same node and memcg. When this assumption breaks, stats become skewed. > The bug affects not just memcg stats but also per-numa stats, and not > just NR_FILE_PAGES but also NR_SHMEM. > > The assumption breaks in scenarios such as: > > 1. Small folios allocated on one node while the THP gets allocated on a > different node. > > 2. A package downloader running in one cgroup populates the page cache, > while a job in a different cgroup executes the downloaded binary. > > 3. A file shared between processes in different cgroups, where one > process faults in the pages and khugepaged (or madvise(COLLAPSE)) > collapses them on behalf of the other. > > Fix the accounting by explicitly incrementing stats for the new THP and > decrementing stats for the old folios being replaced. > > Fixes: f3f0e1d2150b ("khugepaged: add support of collapse for tmpfs/shmem pages") My bug survived for almost 10 years! > Signed-off-by: Shakeel Butt Reviewed-by: Kiryl Shutsemau -- Kiryl Shutsemau / Kirill A. Shutemov