From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F7FBD44D7E for ; Wed, 6 Nov 2024 15:06:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE0E56B00C4; Wed, 6 Nov 2024 10:06:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D907F6B00C5; Wed, 6 Nov 2024 10:06:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C32506B00C6; Wed, 6 Nov 2024 10:06:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A49136B00C4 for ; Wed, 6 Nov 2024 10:06:40 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1685A40405 for ; Wed, 6 Nov 2024 15:06:40 +0000 (UTC) X-FDA: 82755996624.29.4DFE68C Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by imf25.hostedemail.com (Postfix) with ESMTP id CD8DFA000F for ; Wed, 6 Nov 2024 15:06:12 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=cIG5xMei; spf=pass (imf25.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.46 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730905374; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RKSO4lUtMQl4Y5LRJdMnzIr2/DYRxLVMU8drEAtphZ8=; b=TiTDCFOnazmAj8LwsGyjC6mCjtu5lywb8Qrhm1mBVb64zhafkugnUebr45nls7ATt9lZbF 93JhqJiMAQrLwN9+8CZBOpFO8fJbsvRe41UDCiClt1QwR7lhajuR+z2gtZXn+qgf0RMRUH aGIHffevSzdkXa3Roy4OjKOJEP22TBA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=cIG5xMei; spf=pass (imf25.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.46 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730905374; a=rsa-sha256; cv=none; b=biqoRrLWTkNC4bea0778iMp/9mEL6woCG35XFdef0mTSR1rishv9pznYZfVvgRp6lIxVRe +JaHYPHWuLP8cviozxZ9B1ZbN7F0DN20QfMGWaDoKhQZ5cgzQf4bT66+OpVIFlPejyJkYY XHAGKCQzXfwOKB+x4R6pfCQUZH3Esus= Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6cbcd49b833so44074206d6.3 for ; Wed, 06 Nov 2024 07:06:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1730905596; x=1731510396; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=RKSO4lUtMQl4Y5LRJdMnzIr2/DYRxLVMU8drEAtphZ8=; b=cIG5xMei8mQ516iWyvsY+Jl5by7AjrLJ4TtcgMnUgbJFSde7IDFYSmFSNnNPhhRwZ0 /e6JYoRABN+P+GQBjdJuPTepFF56CaYXOJRw82uch4Ot/tLUfduw7soFEwAP/crsxbaS /ndrDmtZlOFgWP6zf66Pqdj5bh9ZjsNfj/fTilZR9FKizLEnfdIk5Rph/wDt/ExmS8zf KAuyfWBXy3UEgbKnGLgJKS0rbG4Gk4opcCPH9GxDp0Z53Edn/cVXV0fm5EdqHPI35Nnb DbwICSun/NFDhsO56mrpwadUDNIU/Fb/tn0QCLIZq6UmVG8XG73Sko/wQEk5kakO9LIK WNqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730905596; x=1731510396; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RKSO4lUtMQl4Y5LRJdMnzIr2/DYRxLVMU8drEAtphZ8=; b=twgmcbdGGPOrYFgMKJdzzT1I31zGidVmPYZCZLs0q/Ju6Kn8bT/W2hkNujt6gDzxoC Ibrg1PQl6bA09N14iQx78ik0hFnBczjdEbYmfi823X6sKjmQc/eap6AqTVlX15QZbjIy 1UxLZ0ucsHL1yxdRW39jcpkoY0J2ZQSD6pBO9huVdEf68aozLQ3btM75AXx589xXT/89 08xhkdr6dvYAbldcSWLgyYGPh3Fre/36a3Lndjg3EQ1xk7GcltCZqCtDt21mhG2KZok5 8UwSPqxSSFBbHVD49dHvE7F+TI/mQSyKOxddPxpAk3EiIg/+G02aVvmOY1b5k7Ga810B Nc3g== X-Forwarded-Encrypted: i=1; AJvYcCW1qscjy32wB4tNc4RSUPFv9QiI2LDbT5HVUpi0iLKo48ceshCHNOph5rUkL86JUdEQ8wlWSZ1+XQ==@kvack.org X-Gm-Message-State: AOJu0YxGP8frNMZFBV10YZ+aZ6WLSZV59W69OcPk5e/GwmLhxcwM7OL1 HItONZ2mUjghUS6f9ASh3x177SYzn7liINYDB7FRO0E38jqmqTQ+gl90RyXw3Nk= X-Google-Smtp-Source: AGHT+IEnTA+3Pm5zFU2s+8Nc6MKNep1IYwxKPkBsZx1q5uHLuvMKwOML7P3MUMkRXZwnjOmhxDW/Cg== X-Received: by 2002:a05:6214:2f82:b0:6d1:8346:9dbf with SMTP id 6a1803df08f44-6d35c19a037mr311901416d6.42.1730905596209; Wed, 06 Nov 2024 07:06:36 -0800 (PST) Received: from localhost ([2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc636asm73086316d6.51.2024.11.06.07.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 07:06:35 -0800 (PST) Date: Wed, 6 Nov 2024 10:06:31 -0500 From: Johannes Weiner To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Nhat Pham , Usama Arif , Chengming Zhou , Yosry Ahmed , Hailong Liu , David Hildenbrand , Hugh Dickins , Matthew Wilcox , Shakeel Butt , Andi Kleen , Baolin Wang , Chris Li , "Huang, Ying" , Kairui Song , Ryan Roberts Subject: Re: [PATCH v3] mm: count zeromap read and set for swapout and swapin Message-ID: <20241106150631.GA1172372@cmpxchg.org> References: <20241105211934.5083-1-21cnbao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20241105211934.5083-1-21cnbao@gmail.com> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CD8DFA000F X-Stat-Signature: 3q7bjhz4kzzho9gxmrmjxhaookk4rumc X-Rspam-User: X-HE-Tag: 1730905572-214726 X-HE-Meta: U2FsdGVkX1/TH9WAWYoYT8ugqpTiTaPQoekW2Q6qYprrn/ulGJyzA/OHwcy20nJAxmaJLXdmu7D+yjeVP5R7bQC7/BIhJPqri3Nwa2cHTI3/jgUPQFv5EHiSw3vZVM0q0y1sF2oRRig6lDET9MWuHvEfxHMN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6AxJvESe0Wp2cnlmg5mk/q1q7Icxo12ckQgMdnvcvZj1GHZF+xYeAKxm/0a0xkpJW7U8hHoS9rYL8aO/khem6IH9GikrX9ZlYrF4qSA7rv3LWimKbvMKrKqNNXEibtWHguRz+nD1cjVSWO1CSxItqXmqavnagRr5PxuBkn5P+naP3scZF8dWNVsUVM2tqbG8IKz0ScjKcD+HX/H8mqw4wn8VFAsTzo8Kph6ZCAlGXvjXQQ8roeq0fI++BbYeE/AITICmBUg0wyWeKeG49FsiflgWtan6dQcaG9JGQ3KfE9+3ptKGESzOp9MwH5Cg2aBZiINBF544JyuKNk3enkfapiVWoT+IR/As9u+EYpkOee5ok1pUxrv3F21pMVQNklqTYErWnCZNAYM7ddMnF+ADAb01EfAli4EvQn1Yuz20d/UMpD+CZjcbbF13MIBYaVzXgY7yfM29uoj0+po3Mh2iPXroMJXVYvHlq6H62eNyYcnimknwihrgRIVRfLhamW/HnUK1zuzSqR+29D37hqCZRQci6CFSxANI1j8Xs/NhyWpyPdmm/P0od3lIXy85gxZSEDeKXDiFqw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Nov 06, 2024 at 10:19:34AM +1300, Barry Song wrote: > From: Barry Song > > When the proportion of folios from the zeromap is small, missing their > accounting may not significantly impact profiling. However, it’s easy > to construct a scenario where this becomes an issue—for example, > allocating 1 GB of memory, writing zeros from userspace, followed by > MADV_PAGEOUT, and then swapping it back in. In this case, the swap-out > and swap-in counts seem to vanish into a black hole, potentially > causing semantic ambiguity. > > On the other hand, Usama reported that zero-filled pages can exceed 10% in > workloads utilizing zswap, while Hailong noted that some app in Android > have more than 6% zero-filled pages. Before commit 0ca0c24e3211 ("mm: store > zero pages to be swapped out in a bitmap"), both zswap and zRAM implemented > similar optimizations, leading to these optimized-out pages being counted > in either zswap or zRAM counters (with pswpin/pswpout also increasing for > zRAM). With zeromap functioning prior to both zswap and zRAM, userspace > will no longer detect these swap-out and swap-in actions. > > We have three ways to address this: > > 1. Introduce a dedicated counter specifically for the zeromap. > 2. Use pswpin/pswpout accounting, treating the zero map as a standard > backend. This approach aligns with zRAM's current handling of > same-page fills at the device level. However, it would mean losing > the optimized-out page counters previously available in zRAM and > would not align with systems using zswap. Additionally, as noted by > Nhat Pham, pswpin/pswpout counters apply only to I/O done directly > to the backend device. > 3. Count zeromap pages under zswap, aligning with system behavior when > zswap is enabled. However, this would not be consistent with zRAM, > nor would it align with systems lacking both zswap and zRAM. > > Given the complications with options 2 and 3, this patch selects > option 1. > > We can find these counters from /proc/vmstat (counters for the whole > system) and memcg's memory.stat (counters for the interested memcg). > > For example: > > $ grep -E 'swpin_zero|swpout_zero' /proc/vmstat > swpin_zero 1648 > swpout_zero 33536 > > $ grep -E 'swpin_zero|swpout_zero' /sys/fs/cgroup/system.slice/memory.stat > swpin_zero 3905 > swpout_zero 3985 > > This patch does not address any specific zeromap bug, but the missing > swpout and swpin counts for zero-filled pages can be highly confusing > and may mislead user-space agents that rely on changes in these counters > as indicators. Therefore, we add a Fixes tag to encourage the inclusion > of this counter in any kernel versions with zeromap. > > Fixes: 0ca0c24e3211 ("mm: store zero pages to be swapped out in a bitmap") > Reviewed-by: Nhat Pham > Cc: Usama Arif > Cc: Chengming Zhou > Cc: Yosry Ahmed > Cc: Hailong Liu > Cc: Johannes Weiner > Cc: David Hildenbrand > Cc: Hugh Dickins > Cc: Matthew Wilcox (Oracle) > Cc: Shakeel Butt > Cc: Andi Kleen > Cc: Baolin Wang > Cc: Chris Li > Cc: "Huang, Ying" > Cc: Kairui Song > Cc: Ryan Roberts > Signed-off-by: Barry Song Acked-by: Johannes Weiner