From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (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 09BAF341660 for ; Fri, 30 Jan 2026 16:13:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.193 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769789590; cv=none; b=A+gvbbUv4uwdneM7NUcXCeBVr/IzjJVC1fCcnBvbmvaRyWuN111jpFMYdko4LS+t++s+IETY3615Fs7KMmCS5z8TxEFVB+rPg+SixjfL5bafN0301W4LojZpe3AqUjyD3sKxgWgTwuaYTkoRnXjs777ZZ9LTeGjeId0kivcmR4s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769789590; c=relaxed/simple; bh=1zch/1ZkNKibJGzl/KXh3eNSniKdCPTOoWWscqay4XI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GfhDxE9o/fBQAGzj8Ff27sEexilWELIrfKESHM2ipAt23hxlAGeKwA3TuRS+OMlEG9L99lZlzZrajCnd1aOmeNCGyvj07IyUSg9MVv9eKeOqkGhPhPL9VxQTy/4zfhVb2X7ow+AZ7EO+Vp4AQJbIwTzALoMjEDGw8e8mFSwwNMc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=IIUoQdfX; arc=none smtp.client-ip=209.85.222.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="IIUoQdfX" Received: by mail-qk1-f193.google.com with SMTP id af79cd13be357-8c710439535so182643185a.1 for ; Fri, 30 Jan 2026 08:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1769789587; x=1770394387; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=QG90dLm8lMXI0BfNfS8WSlG5utZKp+E9ek/YEYpHTH0=; b=IIUoQdfXpzqDGlDeV+THJ6919SVX5x/xjzIAwemJrw9sPUA0pkZhPkY3H++2RfwfZx YKI4wsqKFP6hUZGspp0dWMs6IzZC+hvp2JIHu6ufMUepnKsMbc9A43mZTOB+7IQFpvYr x3oMGXUKiWsTorsoNoZty+rn3emJOX4sf0MdEl87cU4L3eBck9dh26/uKaoLJ7QNlMJQ 1yOiwDOErEWVqJXwGkbKo5ruWNqqmyxc8aP87bec/e71qvQ36F3uVH0LmnNnv/ZGiyHo y9XEr/hZKsDZPquC0KTrMHGDklGnVZ6BNxMSuUFg58wXTPibSe58UtyFbyIOKqs0bs/M fs+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769789587; x=1770394387; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QG90dLm8lMXI0BfNfS8WSlG5utZKp+E9ek/YEYpHTH0=; b=eoZQWrTG+lPWUM7+cWXB5yD145BY8w0w5xaPagLrTN5MLSAjOJMDp5yghPHj26G5cg aBezPdUN7ETRJV3s6sL9FV9iZp8WRtmol0xdS6ljM2h6N5djxYh7J1kjhyZ5ma2p4LK2 OyvA5osD0aza4bUE2VakkQCaMtpn49obFLcNeSIXx4/2F0GJNkYXnx45AjEB33xwFbRZ RgALQvL2+/oALxwzeCZQ827dBz6ne4N1gn8jerdYmhJsdqZDCskSNu6pWhuK6gxP3I4i HRomaSHNBZgIZI97uDK+12+I5lCuVBN02lT2L2H4wTdTGsVBkwHF4TASoJP5VxjPH+Oo H0MQ== X-Forwarded-Encrypted: i=1; AJvYcCUpRmWsX5NcfHPZQ+aZI4EwR6schaQf7BqW2r5YbUiGRaJ0G8+6sj9tvGE1PoW5U6QTp0VD6sAHC7Q6fro=@vger.kernel.org X-Gm-Message-State: AOJu0YxjuIyRLdLmtZeKDbVmvJswhe8h9KU0dCliG1ezAwzbOEnidWDs J0CgByY0h+GZeqblBIcXsEfu8KySpWMHGHdOYeY3I3XevHaR01qowINrj17FHvBzBzM= X-Gm-Gg: AZuq6aIsgXRq7OWKYkNDrxXtzZBzMMiFg8hX8atep5vtdwOoipkddF8598p+r2bXeso 2iWXxZStpSziVuEAfRjtO3v5pmICHc/QrGSOqj1Xd+HAg98ZTNIDMSos7TDhfIMQ2k61BMBxoKX QdKWz4/Sv7/g8vB1841TA+szojM9KRtpuyi0lvtLrMwYjv2B34cjrymdrxX/lU2JGnlRrsbGXJF rdJ0On490Aocypzzbe72xEaEEkCSSqqANad6YHnAVqi25Dbj5ZxEsC6yxQvYxOBy8vx9TJMXZlo VaWp+C8Tjd2wFCFra8rWCPCi5V8etOfSerHqdRHq0YsfL1A5B6NOfxDZY0Vcg26ai+iyDo3CKYA lF3X8Wi/lkoX7dNWcUDficNQ8FLhWuWkUdQjQ+60cY8S7X49ruHHWONtAWMx4NL7+TOp9HZDJzh oW4T69OL1Avg== X-Received: by 2002:a05:620a:4103:b0:8c6:e37f:ec2c with SMTP id af79cd13be357-8c9eb227cf2mr476327685a.1.1769789586691; Fri, 30 Jan 2026 08:13:06 -0800 (PST) Received: from localhost ([2603:7000:c01:2716:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-894d3740c86sm59598226d6.34.2026.01.30.08.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 08:13:05 -0800 (PST) Date: Fri, 30 Jan 2026 11:13:05 -0500 From: Johannes Weiner To: Shakeel Butt Cc: Andrew Morton , Rik van Riel , Song Liu , Kiryl Shutsemau , 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") > Signed-off-by: Shakeel Butt Acked-by: Johannes Weiner