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 5CB9ACD11DF for ; Thu, 28 Mar 2024 20:30:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF9946B008A; Thu, 28 Mar 2024 16:30:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA9DB6B0093; Thu, 28 Mar 2024 16:30:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A718F6B0096; Thu, 28 Mar 2024 16:30:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8858E6B008A for ; Thu, 28 Mar 2024 16:30:16 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 44E78160942 for ; Thu, 28 Mar 2024 20:30:16 +0000 (UTC) X-FDA: 81947590032.07.33496B1 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by imf14.hostedemail.com (Postfix) with ESMTP id 494DE100013 for ; Thu, 28 Mar 2024 20:30:14 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=xT4vuZEV; spf=pass (imf14.hostedemail.com: domain of yosryahmed@google.com designates 209.85.167.48 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711657814; 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=IjVUquLiWCNblxyiLjuM34vhuxWsmaQ8B9F++hiYL2w=; b=o6W3PEcDY7baObwztriSpCud3hzGegXxmxv0h/S/vwrOOVFqFqXxSi91hX/2u9TWUHHf54 uGkG7ipI59FS7RwJIs5Iil6ckggcJW2ati5/60si+gqh1wptdM/eI5R38q+EqtpfO23Kz5 61hY8fVjfEhzyMXhByzxFhVw7CsJ6WA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711657814; a=rsa-sha256; cv=none; b=YKYkeRJze7P/cywNyu7Jf+LFWAiTAr21yfSr6GKiwxNTBBaU1AdCdjWEtSv1cfbGGu8hpf WQ2lQ72QUfXK6HUUedFfMVTNLOOPS38JASHngfq+QkzDa3Lju0EUaWksjvQZK3Pkfpz85V cBfcHZguTXvmnmyyFklwSFplpWf7EjA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=xT4vuZEV; spf=pass (imf14.hostedemail.com: domain of yosryahmed@google.com designates 209.85.167.48 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-515b69e8f38so1406939e87.1 for ; Thu, 28 Mar 2024 13:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711657812; x=1712262612; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IjVUquLiWCNblxyiLjuM34vhuxWsmaQ8B9F++hiYL2w=; b=xT4vuZEVdqpbFOHEp7wiv6M5usCPR+dmRYJiMFUlv5lYi5BbjTBo5oL+gytt7YKC+N ivoEhK3aQEe8MAR+d4J8B7fTzeIgJjDP5bJWAxfEN29WngH02mfWx+bM/lwT5CLRAryA 8R2dbJ/XdYsUZ3zPM5S8jmisN1OY0ecvD7cPpUGqkuxj6HNESU85OIeOLEkJ64n+VSGa p6srfu1L9ikyhW69924qdBUd28RLVUv1gpYSZFNk/pbXnjqAVxLuWJRPOIC75XwQfk7K 5p/R5ti+Z8C4PDXWkvMCGIPt6SP2m8MlOqqNDfR1h/SSQWHV6CYjKxRhgdyssHZPZysc hGeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711657812; x=1712262612; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IjVUquLiWCNblxyiLjuM34vhuxWsmaQ8B9F++hiYL2w=; b=tkmmm8LLzXUvlEkv49nBaGLreowcCnClVXS8KQ7TpoluSr3EEEtxx2GeLYYcrugOKq 8I1QzQ8DA/F851+06I00DH6YlLVDFicj93T9qxE/disD9sv3xsvdCFwa4oktXtYp26pQ uzDV7iWbslz5O5ipa0HQDzV5dh/fiTmfRTPYaMK8n5K7oF5AW7fhEwcieJx1lMBnX/dl vC1pRvQwWg7C3W3i/DW5rqz/tI/dyLEIAEVupDla174eRISqQYNYaNEoG0p8JYP2EQgA mdUWmGxiPQfJCmUEP2YW2qM22dtkCG3nqoVo/7Qvfc7DA2vrp5APw/zn3DxEUTlp/XNa YE0Q== X-Forwarded-Encrypted: i=1; AJvYcCUt+Gn+7IIVl7KJagoEg7MjC8ZoeW1jZHDOru3iWI/8l7lCxptbGWhFMmSyuaaKDGBX4FId8ZudCprLudk3VTJqkMo= X-Gm-Message-State: AOJu0Yzsr5p1Q7uenxZYv/2Un9Z6jLZNWQrEpq3eOSsrMyxF+/0SfAT8 BjrL40lfOZ4sPyYJXIpL0gyndOaN1QR2XO5DMoEWrYhIyorIqhgaChnYNfHwpBEJ9PAhrSgcF/x XkDvInrn8QeAsJPC0fdpvJlId5248Ki2xWhHu X-Google-Smtp-Source: AGHT+IGNIY/c+G0dyBw5Hjzrx64iJgli4YK+uTJUhwFFODz261SDdi7HPJ2bpQgOg6gJW+JzOAnMdEbX0cJtre++h0U= X-Received: by 2002:a05:6512:10cd:b0:515:abc7:8b0c with SMTP id k13-20020a05651210cd00b00515abc78b0cmr369366lfg.25.1711657812050; Thu, 28 Mar 2024 13:30:12 -0700 (PDT) MIME-Version: 1.0 References: <20240325235018.2028408-1-yosryahmed@google.com> <20240325235018.2028408-8-yosryahmed@google.com> <20240328193853.GG7597@cmpxchg.org> In-Reply-To: <20240328193853.GG7597@cmpxchg.org> From: Yosry Ahmed Date: Thu, 28 Mar 2024 13:29:35 -0700 Message-ID: Subject: Re: [RFC PATCH 7/9] mm: zswap: store zero-filled pages without a zswap_entry To: Johannes Weiner Cc: Andrew Morton , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 494DE100013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: q1pe95bra5yrhcupau51yntdcddanitz X-HE-Tag: 1711657814-630792 X-HE-Meta: U2FsdGVkX1+hwf4Uvv7snruIq3XDhM7CvY7WQhy+dlMuBuIv3Ul8QUVY9KU65/+OZf6UOaD3Jpwc7OrVFyREqD0xC5qb3pURmoIWu6IY34/ElDOXIYJkoAISDFfEh6ACTS2aJJ1hZ1s/G6hsBprYFJlv3+ujWGJqfAhyXJLnqOWWBFGG3q81l3xq1RGe/570n8qE+GLrsNyJfiVEE/IYOd/bauxzf1sZu+NjDAKZeB5210o87XEmJJR4MPgLnSNnFAEjTGCqYkf7kkRI4ILC4k3E3LxVjUCtBAv4PT2EZM+Ro3YVDQ/XMD/FlFKaCiZjG3Os0wNEglT/uyvHlBvhEjBbtv5WvXhSYVzS+ctEqDWTwt/phTP9Ojgeuz/uXwDViTDzTzM0hvXOGFjIhlgAtkm031FnUjonr3635I7aPkZ90CoZoBQ06/m5ycC0uKW/YDsaevLBb3Byd57aXua8cWEoizw1aARXwqvrLrBhBJAjYXZ26t7UMMbi9ByVuNaHfCY2sccc3Nf7Pm/1xj14YL6YQdkd/MSvBx5tWRLqdkOf+LE3xBEIhKcw7x7m/lS+2h5ZoM9c0kam+8oFeCW9sgBNu45dSg0BCbM3N1XuZPPtR87QwboMZ4L87p2IL6O/gixBBzcubGrUVPu046sodNf8uo38vNrnI00miNieX4GW/z+Uvw8M0P9AzgKRgk5CALlmF6K1vpUQF4WDlt9yw8VTZ0som8+ypLKBICNSTABpwChOYb75Gd9TVU/mLhU5OCeH4SBLkfCJZIC2PZ1OnUcxr2W5FcG0XRsZobBrd4SO94+opOPaS280AEq0t19uDwwdq98/JG/fO+KFBTA5HjjJNhyxfmls6qKzYNGjGVm9lgZq4wKtRXGE8VG3T/zfiCGgw8MlR0SKYoPSGY2GN3t0vt/oFDSyEfSnGnei9U+4opHRymJnG4oGeuOd2hAZ21fdjkibpW2nAG8eXfh 4h3n4alL OMi1Eef6faaMUcW+m9rHK+HMRGAEFub5KULFD6iYoUfpKzYjlJDoXTkLiEUj7gThMykfEh5ffLJNTkIZELQ4UpUmQkcD0yTCFzRKJy2N8+IZQkInGFin6oVIDv7A0klmI9XIpmkVmdkITG7VK87WnXSws5ooQ4IZpEcNppCyKNaKryizQAE98xb4wonYup9lVM5mrnVQ8tdzfPUynmAGQrjtKHh2yQzx+t/os5cN3fwQeiaY6Cz2C56Mvue+YeKAUF3PF1BWR4Q1bOlPeS+WsohhRNncP3RWrUaExo7oBhXqaPjMEExXQbwZGygU1Ausxo3nQbC/eGzwK4FUqBvZMZx1MPeJpAJ5NdR2Meuzq/lRYPqprSaY+KgTV9iU4V/Qo4GUSvw+hKvCttCrO5vFrE4oVSJcBZVwAhXpk 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 Thu, Mar 28, 2024 at 12:38=E2=80=AFPM Johannes Weiner wrote: > > On Mon, Mar 25, 2024 at 11:50:15PM +0000, Yosry Ahmed wrote: > > After the rbtree to xarray conversion, and dropping zswap_entry.refcoun= t > > and zswap_entry.value, the only members of zswap_entry utilized by > > zero-filled pages are zswap_entry.length (always 0) and > > zswap_entry.objcg. Store the objcg pointer directly in the xarray as a > > tagged pointer and avoid allocating a zswap_entry completely for > > zero-filled pages. > > > > This simplifies the code as we no longer need to special case > > zero-length cases. We are also able to further separate the zero-filled > > pages handling logic and completely isolate them within store/load > > helpers. Handling tagged xarray pointers is handled in these two > > helpers, as well as the newly introduced helper for freeing tree > > elements, zswap_tree_free_element(). > > > > There is also a small performance improvement observed over 50 runs of > > kernel build test (kernbench) comparing the mean build time on a skylak= e > > machine when building the kernel in a cgroup v1 container with a 3G > > limit. This is on top of the improvement from dropping support for > > non-zero same-filled pages: > > > > base patched % diff > > real 69.915 69.757 -0.229% > > user 2956.147 2955.244 -0.031% > > sys 2594.718 2575.747 -0.731% > > > > This probably comes from avoiding the zswap_entry allocation and > > cleanup/freeing for zero-filled pages. Note that the percentage of > > zero-filled pages during this test was only around 1.5% on average. > > Practical workloads could have a larger proportion of such pages (e.g. > > Johannes observed around 10% [1]), so the performance improvement shoul= d > > be larger. > > > > This change also saves a small amount of memory due to less allocated > > zswap_entry's. In the kernel build test above, we save around 2M of > > slab usage when we swap out 3G to zswap. > > > > [1]https://lore.kernel.org/linux-mm/20240320210716.GH294822@cmpxchg.org= / > > > > Signed-off-by: Yosry Ahmed > > --- > > mm/zswap.c | 137 ++++++++++++++++++++++++++++++----------------------- > > 1 file changed, 78 insertions(+), 59 deletions(-) > > Tbh, I think this makes the code worse overall. Instead of increasing > type safety, it actually reduces it, and places that previously dealt > with a struct zswap_entry now deal with a void *. > > If we go ahead with this series, I think it makes more sense to either > > a) do the explicit subtyping of struct zswap_entry I had proposed, or I suspect we won't get the small performance improvements (and memory saving) with this approach. Neither are too significant, but it'd be nice if we could keep them. > > b) at least keep the specialness handling of the xarray entry as local > as possible, so that instead of a proliferating API that operates > on void *, you have explicit filtering only where the tree is > accessed, and then work on struct zswap_entry as much as possible. I was trying to go for option (b) by isolating filtering and casting to the correct type in a few functions (zswap_tree_free_element(), zswap_store_zero_filled(), and zswap_load_zero_filled()). If we open-code filtering it will be repeated in a few places. What did you have in mind?