From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796063805; b=iQT5hseLtySLZ5Wrn6frPsvgznfKlwmwE5Wwb6zMyexA7nkrvhp6QIWR9U2cFR1yHq2Y HANUp4j7EtanlxgrhGUnAs8iL3LyoMrgTWdvbpcsTV/0XMZ7papxhmXkiT0kpMW2UaQ6Y ibyI12nw+yQLNK70bywgwblZP2GaDY2udBw9qNpn09xxD2FE7/308LJGhLLf8p8hTMd7/ d9F1KEa+4ppiRg5aXOzHIkFeaFKxoU1mrjqqE4JNFnysUTtkUOm+TuE9NzWnv3p8+LMIq 07sd+TXu7MUtO+cim/2n7cDd3vVv990bR+rtEnV8oWrFuTPU0HZVFl9Rc/DEwfOLZMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796063805; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=8a0gmYOJFJwxERemNIvjy28wDQTUxXViDetkXjYI7hc=; b=HmBMrtFIAAKF8JQgARd+ezZ6z70Dd3Kn+mC204pCSHQwEPZlr+ZgiWQ5Bsr0s06rd4pw XFpLJeQpWUcomyVUnrhiMovl46BIuoi1I8ePbTW96V4HpUX5he4AIdqFDeJu1DeQIkTeG UDFiwywum3aCs5dbLQNJKY/MVc8EWJAHjyocmJUHE+6wnOmMqKtqgA98HPNQs7IZ1Ynud mMfkt/9gldzqwtD+b3dcFTIK31OmJ7adj5jraglLS/G+DjPJ7V9UmR2qaTV8rO6n8EHKN +sjyz9SyotNW2Z+DPgGtkUkEbB0lhIH4anzCZ8andt7vUlmO3FvuA/rA4rxrx00hHQA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ViEKIYU1; arc=none smtp.remote-ip=209.85.161.42 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE634606A31C for ; Mon, 30 Nov 2026 18:36:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE634606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ViEKIYU1 Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-716c0217635so12858629eaf.0 for ; Mon, 30 Nov 2026 10:36:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796063804; x=1796668604; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8a0gmYOJFJwxERemNIvjy28wDQTUxXViDetkXjYI7hc=; b=ViEKIYU1V8I2q2HPdouVyVbjQhv62PX9cqIgPd0XDG7mjyvIH3UOPqfDbJ9EcMq9us g0uqVDq8lRgQkYqHCHiQ8+k04uC4aPXErvwPDAXs1qh3Z2IkI+JqFTXXv9OgrqkgXgR7 SiBrJZtpLpSCaONFTTDbisG0zqtQRL81HkCDzJ6F2+JWLf9BgCdV1NjL4KssVfC3TdZ+ IHO8JDf/Ze0AO4z4uqsIp2uBdoC3cg7YChji4SzcU/H4nofhpdh+SXrCgV4/Yhq4XdBm sDwYrcQWwbUBGOasfRlrvnuwu/12Xy9tc8AMDTMIfwxyOIfMkVyb5/J9FXrD9mPCb4H+ 5LxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796063804; x=1796668604; h=in-reply-to:content-disposition:content-type:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=8a0gmYOJFJwxERemNIvjy28wDQTUxXViDetkXjYI7hc=; b=u9ld/sKLwd28Xolw7k/bsa/zRqHlVVO8Sy3tVgwr7Z1xidqvGHQ3JEo9JaQvUmJe6s TEPwQZajHYCU+F5gDZDpkZVZFsgEByJBmB+hxUsLM2UTTipjdEi2beAgqD59vmOusAc1 uZo5nYJwYzAKH17zj3gutrXOporhhnNQzUgUMoM9xRanmbevbqp2lAWfGyeDGB+p7tY8 +hFga3RsHNXx/m4xH14TUx9fz8FARUY6kXtsLOorBJVEKe7/v8r3mmOnPtAW8wekvm3H /TWw/zwIFdIFtoSo5H72ftL84vqlZKnBDxiBDqwrodN2BLUUw49tfjg39kB88/DJBWAH QHMg== X-Forwarded-Encrypted: i=1; AL+hErGXFkkDnCXVvJOEoLDGeZ+GBjcVLwWvxdTzocHsJcy17Dk78uCdtZkb3TVD4UpHvDZAjV0qPEEum67bsXA=@vger.kernel.org X-Gm-Message-State: APuU4Z8Weyud2AKFgXRmNb6et87JX7E80vidMcotWRQXTVwD2RNJnV70 ooeXfd8cHBvOXqX9EnOgG+j3MkJtSHe60csIBjSwhAFCauwahkbI3UWr X-Gm-Gg: AZFdTZc51XKju6Iym2wBHKFmtOsQjW0yiWdhe2pOHkynOxTAkwGMWSvd1ghX3BXRny0 wVk9hjVU44DFQtmoz2QA7PwHsnmXfOmDcGQt1qll1bRW1z7kFLdedUHxfPwlTiCgMq/8sMGbhZT iFUojHIcEgH2eXZxi6E7NgoVjeVOLQsOZBZHdMJSGB1GwzNBX1tlXt3WYxkaunWD604t+k+JZrg nkRrogrLFYBJXGxIjzZ75ICMWFPY0J06vGZdAZyfJZuBD23mimZX5xhmiQ2jYN8wojDQoRisTcy lxE9CoP3sY6VCrAzm66ZJNKY1I0ZF6HbEq/f6vEFXnRf0LFvz2sd04okWolXjbwq1hBciknJVfo PXdUYTSOOkYaXgUtGZOJBLPe83A7/y0hNd0hJkUCQ7bB4MeQgRS0ZTMlpnhHFZvJ/QL3yM9ai+A xYo+o8bwXzKavruRakH5NkbQ2Lfno/7xLaLlUZdxQs/SXZm2Vpk7S5yDWW0Dgf+D3F7Zqr6uUm2 tc28M+sydiciQQjy2UslPv5Ssh73x1jd5cMD9+uVf6CRlhUCoeV2cGkvYApvGRK0ROdL7qux5fd COCHAsFwjKvJenqKmt5+vjkLt5o831w4ZWYXxIzSdNC/u6M+5UksYsEoGegz0Q== X-Received: by 2002:a05:6820:8583:20b0:71a:e761:698e with SMTP id 006d021491bc7-71b39468c2emr14204160eaf.12.1796063803583; Mon, 30 Nov 2026 10:36:43 -0800 (PST) Received: from localhost ([2a03:2880:10ff:59::]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b6b680b66sm16212773eaf.9.2026.11.30.10.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 10:36:43 -0800 (PST) Date: Mon, 30 Nov 2026 10:36:42 -0800 From: Joshua Hahn To: Alexandre Ghiti Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , David Hildenbrand , Kairui Song , Chris Li , Nhat Pham , Johannes Weiner , Yosry Ahmed , Chengming Zhou , Baoquan He , Kemeng Shi , Youngjun Park , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko Subject: Re: [PATCH v2] mm: free the swap slot of a dirty swapin folio Message-ID: Mail-Followup-To: Alexandre Ghiti , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , David Hildenbrand , Kairui Song , Chris Li , Nhat Pham , Johannes Weiner , Yosry Ahmed , Chengming Zhou , Baoquan He , Kemeng Shi , Youngjun Park , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko References: <20261127142357.1112193-1-alex@ghiti.fr> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261127142357.1112193-1-alex@ghiti.fr> On Fri, Nov 27, 2026 at 03:23:27PM +0100, Alexandre Ghiti wrote: > do_swap_page() frees the swap cache of an exclusive folio on a write > fault only. But when the folio is already dirty, the copy in its swap > slot is stale: the slot only reserves swap space until the folio is > reclaimed again or its owner exits, and the folio has to be written out > again anyway. [... snip ...] > base patched > exit time 989 +- 24 ms 502 +- 28 ms (-49%) > > The cost is paid by folios that keep cycling between zswap and memory: > each reclaim allocates a new slot and adds the folio to the swap cache > again. On a kernel build in a 600 MiB memcg (-j4, defconfig), this is > not measurable (mean +- stddev of 5 runs on bare metal): > > base patched > time (s) 592.4 +- 1.1 592.4 +- 0.9 (+0.0%) > sys (s) 256.6 +- 1.5 257.5 +- 1.4 (+0.3%) > > In the worst case, random reads over 4 GiB of anonymous memory in a > 3 GiB memcg, so that about half the reads are zswap read faults and the > task spends all its time in the kernel, throughput drops by 1.1-1.4% > (mean +- stddev of 5 runs on bare metal): > > base patched > reads/s, 1 thread 37310 +- 182 36889 +- 77 (-1.1%) > reads/s, 8 threads 291937 +- 802 287954 +- 373 (-1.4%) > > Signed-off-by: Alexandre Ghiti Hi Alex, Thank you for the patch! This patch makes sense and looks good to me. The numbers are also really great! Sorry to do this, but I just have one nit below... > --- > > Changes in v2: > - Free the swap cache of a dirty folio even when not exclusive (David) > - Make the comment and the changelog generic, zswap being the common > case (David, Nhat) > > v1: https://lore.kernel.org/all/20261126094318.244973-1-alex@ghiti.fr/ > > mm/memory.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index d477a4f986bc..c83c67cb759b 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4711,9 +4711,12 @@ static inline bool should_try_to_free_swap(struct swap_info_struct *si, > return true; > > /* > - * Free the swapcache only if we are the exclusive user and > - * this is a write fault. > + * Free the swapcache if the folio is already dirty, or if we will dirty it > + * immediately afterwards by writing to it. > */ I'm not sure this comment really helps explain why being dirty matters here, which I think is the interesting insight captured by your commit message. The idea is that dirty folio == swap slot is stale, right? What about: /* * Free the swapcache if the folio is dirty (it has diverged from its * swap slot) or if an exclusive write will make it diverge. */ Let me know what you think. Regardless I think the change is good, so please feel free to add: Reviewed-by: Joshua Hahn Thanks again Alex! Have a great day, Joshua > + if (folio_test_dirty(folio)) > + return true; > + > return (fault_flags & FAULT_FLAG_WRITE) && exclusive; > } > > -- > 2.53.1-Meta > >