From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from flow-b3-smtp.messagingengine.com (flow-b3-smtp.messagingengine.com [202.12.124.138]) (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 6C95321257F for ; Mon, 16 Feb 2026 16:54:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771260851; cv=none; b=ZJEF5k9/jVlOzZxy0GGrkgvkQoYNoam37lMdWS+g4UWo5pCr+hfOYhTk4ePgNkscxiG7ZkcHvgNnrdErDwybRY66xlb5m3sADmkHUpP3rJ+CTsNgS0tC6J7vOM6gWh15/YjS8QS9T4GKRMvB11vQ6zmotRCBB8nhP5aPWiklbls= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771260851; c=relaxed/simple; bh=0zUYaPrP3/jBoi7kbCCLPljc+pJVy4j/gcWBWQFEik0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iWFQRlA/jbuICuRgvkLeDPg4D41iqZIsBcBsIenKp6dAwFWbTuuVxwQcomkI3/1TOL98dIf1GUY6tejPK8sidinw3bxkiyASbX5t910xS06itw9I+4rcSDiJFTF3+7GGNZinV9PC39HbC5V8eFkQuVISMByWfFISVSJIXAig7Uw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name; spf=pass smtp.mailfrom=shutemov.name; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b=gLh+ibj2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lKisXEYn; arc=none smtp.client-ip=202.12.124.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shutemov.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b="gLh+ibj2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lKisXEYn" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailflow.stl.internal (Postfix) with ESMTP id D7B4E1301155; Mon, 16 Feb 2026 11:54:07 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Mon, 16 Feb 2026 11:54:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm1; t=1771260847; x=1771268047; bh=lgcVi/rFDf4TxsQzdelMFD7oqZc+4jLK nia57UoynYg=; b=gLh+ibj2a/9XhKLVwXuz0MYjgX1nwswsHVM0iGyARSCdYavE ehBnyPJPx72THvXREempnZYxbPx/xyu+tP+1hXHqGJWvkA2ebJVRpQETf3X9T5He YP41xSRq9ZekvhGOqXEdYbTLdeBFNFWg3qeKsWPfKvYafqe2J2RKKN4SR5ENM4Ls SW1KVXcNIp7AsZ/Ic0gw9KmGLFlxtUd59S6pPJcJVPSSUkG4xFoDuCE1z5hB/36Z 3K6R/E9H6NczxIkeqQw6YXUaV5uODmEODhpFTZaH1jyBhfSefm2q1pCPtxcuChTl B6cH1vFvi/vbaxrPyqieOy0dxornv7TQ0GiKbg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1771260847; x= 1771268047; bh=lgcVi/rFDf4TxsQzdelMFD7oqZc+4jLKnia57UoynYg=; b=l KisXEYnSRuXGKov/hsqgcdwWXakp1g+cq1/Pr/hiGMPZ88l7Sz7rEUL4jxuSu+8f PfnfVqs4mrguzhTFjKPRolIfvzQSaw5Ge2/Z2TZTTb2bjH8UryIBPLPk4N/RfmG6 yzm7pacBmUXgJd6pqYisl+ehDmW3TQBSI7F8m/1mOOHvat1VahckduLeKzI3U5vz DrXAfT+I1HQCwd5hqyqOk0U35b3sFBsOOtxtKagx9KNSCm01gCIA+TFZRNZu7Wkt gv0HQzSCWYOmUXUH5i1YNgjZwNrqODAfquOqWX7D+bUuIzoqMD/LKYr0a79d/C+c e40rTf35EaVYvE4LyucMA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvudejgedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpefmihhrhihl ucfuhhhuthhsvghmrghuuceokhhirhhilhhlsehshhhuthgvmhhovhdrnhgrmhgvqeenuc ggtffrrghtthgvrhhnpeeltdefvedvteeuuefhvdeutdetheefueethefgheegteeihfev jefgvddujeeileenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehkihhrihhllhesshhhuhhtvghmohhvrdhnrghmvgdpnhgspghrtghpthhtohep vddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehhrghofigvnhgthhgrohdvvd esghhmrghilhdrtghomhdprhgtphhtthhopegurghvihgusehkvghrnhgvlhdrohhrghdp rhgtphhtthhopegrkhhpmheslhhinhhugidqfhhouhhnuggrthhiohhnrdhorhhgpdhrtg hpthhtoheplhhorhgvnhiiohdrshhtohgrkhgvshesohhrrggtlhgvrdgtohhmpdhrtghp thhtoheplhhirghmrdhhohiflhgvthhtsehorhgrtghlvgdrtghomhdprhgtphhtthhope hvsggrsghkrgesshhushgvrdgtiidprhgtphhtthhopehrphhptheskhgvrhhnvghlrdho rhhgpdhrtghpthhtohepshhurhgvnhgssehgohhoghhlvgdrtghomhdprhgtphhtthhope hmhhhotghkohesshhushgvrdgtohhm X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 16 Feb 2026 11:54:06 -0500 (EST) Date: Mon, 16 Feb 2026 16:54:05 +0000 From: Kiryl Shutsemau To: Wenchao Hao Cc: "David Hildenbrand (Arm)" , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: Add AnonZero accounting for zero-filled anonymous pages Message-ID: References: <20260214084514.2842745-1-haowenchao22@gmail.com> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Feb 16, 2026 at 11:59:50PM +0800, Wenchao Hao wrote: > On Mon, Feb 16, 2026 at 7:58 PM Kiryl Shutsemau wrote: > > > > On Mon, Feb 16, 2026 at 12:45:13PM +0100, David Hildenbrand (Arm) wrote: > > > On 2/16/26 12:34, Kiryl Shutsemau wrote: > > > > On Sat, Feb 14, 2026 at 04:45:14PM +0800, Wenchao Hao wrote: > > > > > Add kernel command line option "count_zero_page" to track anonymous pages > > > > > have been allocated and mapped to userspace but zero-filled. > > > > > > > > > > This feature is mainly used to debug large folio mechanism, which > > > > > pre-allocates and map more pages than actually needed, leading to memory > > > > > waste from unaccessed pages. > > > > > > > > > > Export the result in /proc/pid/smaps as "AnonZero" field. > > > > > > > > I expect it to slowdown /proc/pid/smaps read substantially. I don't > > > > think this line in smaps worth it. > > > > > > > > > > That's why it's enabled through a command line parameter. > > > > One users want the stat and all users on the machine pay the price? > > That's a poor trade off. > > > > In general, smaps scales poorly. It collects a lot of stats and most of > > them are ignored by user. We need something like statx(2) where user can > > declare what he is interested in, so kernel won't waste cycles. > > > > I initially considered two approaches: > > First, exposing the needed information via smaps. This does incur some > performance cost but is the simplest to implement. The new feature can be > dynamically toggled via a command-line parameter. When disabled, the > overhead is negligible—only a minor if check, which is insignificant compared > to the full smaps cost. > > Second, adding a new system call or extending madvise with a new command > like MADV_GET_ZEROANON. Userspace tools can then use it to measure > memory waste from zero-filled anonymous huge pages. > > This is slightly more complex but minimizes system impact: environments that > don’t care about zero-filled anonymous pages pay zero overhead when the > command is not used. > > The exact implementation approach can be discussed after we confirm whether > the upstream kernel needs this debugging feature. What I would like to see in the kernel is a syscall that return the memory stats in binary form. Something like size_t memstat(int pidfd, struct memstat memstatbuf[], size_t n, unsigned long flags, unsigned long start, unsigned long end); The syscall will fill up to n memstatbufs, one per-VMA. What exactly filled there defined by flags. The return value is how many memstatbuf is populated. The caller can call it multiple times to walk address space it is interested in. We also can have a flag that mirrors smaps_rollup behaviour and collect all the data into a single memstatbuf. Internally, the kernel can use the infrastructure built for this syscall to provide /proc//{maps,smaps,smaps_rollup}. This way we will not duplicate the code. -- Kiryl Shutsemau / Kirill A. Shutemov