Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp697339lqh; Thu, 28 Mar 2024 13:30:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHTHqeJLCQM0YV+PYY4tJovvVs9KpwULjPQwQhaowG+D027glrnmR0heEhmuYdEajKojN9fZdQ3y+7Yxslj87Gz0WCyI1g7NBO2XqAPA== X-Google-Smtp-Source: AGHT+IFOVVhLXYEciygw9kFZ8TookgR2Rfi6OnuPFmouqcbWIR6lXvXnh8/U9entVBrKn2zCBhrw X-Received: by 2002:a05:6358:3399:b0:17e:8e7f:59f9 with SMTP id i25-20020a056358339900b0017e8e7f59f9mr453450rwd.26.1711657823551; Thu, 28 Mar 2024 13:30:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711657823; cv=pass; d=google.com; s=arc-20160816; b=QAtx1RHlEYo9fzjlw14wUH0zzpqq6+k1508denYV1o+fackINL/6Jtrp+oUoxSOdd5 1+8HzCWpaj0D2vEYvH1q+Odbgeum0npE+njTIs+HDMu+W8GXZtVtL1oA5mpj98FGhe+n i3C9AbZDFmq69ziq02BW+7ZtZBNK32Utf9cEOq3GSanXkbYgWD+rumRd9Kuvg8BTE8PZ LPJUAGyXPN1Kn5TeSoOsglpySDez4JR8utnpUyP1UAmjB5Q6h2/SatQnXEZy8e3WUwjE qR1PcPTenD6eiOV/YLkYFIQAZElQFwkIotjRLvb1x3Dv6tnu479NZK+XHYy9LZbNXWJK gPJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=IjVUquLiWCNblxyiLjuM34vhuxWsmaQ8B9F++hiYL2w=; fh=/7FbvJeI1u67sJ56vXjq2+qjVL1loS3EOBon1TmKglE=; b=eOyPdJC0SGOqehStHaqiVQoPqe29GVTv7n1vbwNK2qDYfinvDIGcSqxSK46KK0Wv2Y SL9FEaBv8O3E6tGShlhYdvSEpktF55esi/kyPl7mFW3KU1KYSqL3PrpuJ6M3Mjw+R1DS SUbSBfxAHORH2i+Tf9mCzELUCzpIiWFVp+bl2778Lwo7w9n+LlMUd02YmUAomp5wfUwz pFv2VFkuls9jISmIyKYyIl81V+IfV4Tgj1pFYqO1FR0qcKFpEKrHkbTdnRxHHy1f0gjN AJym+lRsHhqhBqLV7JFy2z0gmWb54Cz5MTwpaYV643bTlzJwlwzydZtTf1LXLq8a/md2 YX7g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0zbu9ctp; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-123583-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m23-20020a637117000000b005b95ee3edc6si2174608pgc.628.2024.03.28.13.30.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 13:30:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123583-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0zbu9ctp; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-123583-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 3CD39B20C0B for ; Thu, 28 Mar 2024 20:30:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF29512FB36; Thu, 28 Mar 2024 20:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0zbu9ctp" Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 4EAA62EAE9 for ; Thu, 28 Mar 2024 20:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711657816; cv=none; b=iso6D2mtiRd2RbeRP457dFU8lJVPATNj23Iyzpg9EsHMrFbUlNAYa6JQlOhGVOcvX8kwXd1a/NsAmxvv+waFbZBc1w2xGN23XL8Dmkww14oh6fzmPkp9Oy+t+1+zLq4MbmzmaJnHmUNGsofiluqrwH5PfCgCg884Bp1Yg+sQPkE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711657816; c=relaxed/simple; bh=nIh7elDIyrZjmFM7UiM8LPKOv43kC25hurdSiLWjFt0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=puQbiibTElQBex3mX8nZ+0N82f/9orEkz7a2AdlHbNOwTJz8JNDuAf+msJxZW44/iX/AZCTk9AocsaDi8GanY7ACk+OCEpXKOKGOMkqDQIn56UC3CvZqejSck6G7Eo88Rxb3YsWpF1HM9FmYxz4dRzxdE4Kauu0/LqV76+bghuY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0zbu9ctp; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-515a97846b5so1455354e87.2 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=vger.kernel.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=0zbu9ctpX42WhNJx1hbCGJeTxpRenWOa684Vyap32aHT2NMPCF60PuaD1Sjr3KkOcQ 29MNpfoDY7Pfmo2tRqvg/nDrkasY7aNqyVuOP8G6UWBWleHwNd2Tb9f6yiRvMz6XFlBy kd1+62G3zBwzCjK/wRAj9xVJzG0dJjtFa0DOH2OAALZzYtkQDPLq2NDwBfvgewj2rEPM ypWsJ6P53g8oGIqmg47z3m5BDEBd1XA6dCyEsy0U0IfEbL9nBnFpnO5TWVN3kHFka/Sj bTQYARSV6Yemjk0h+gqyV8S5e6ilYUYbUz9PScFXhiDNUxutzwr+0o2rp15SfRni62bn FaNw== 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=N4U/Qhs86v+MRzinrMQ9Nm0z5eL7RqPtXBLHXbhtiYlXMRYdW7nZ+qcA3UXNGXO7pY xszKsbQVt21zhN3a4/YtkMzAXfVebaO2uM91JfLkmyNBGgkdEZQDJUKuWzg4eXCrjvHe JNJCP/nrcxuKsudLXdBAtD/pWA9yu8yb0mn5lDCytKv4ZUG7n7gEPm+Bue9E1JykzUy3 AaTMNOkUJ1LQ1Oy9DO2aoG6Q/9gKYB2f2k3xWnsEVF3ycCZgYVursWJS7Nme3NL+k4lq jaFK01BklLBPjFVTe0vMtzCPeP+8oJQg17ZkybGN0JPnEt1K77YoUClX5OuToDuieqib Tokw== X-Forwarded-Encrypted: i=1; AJvYcCVdX1QINPmuZf9HgPTpWZAMahJUSRAJY02L8jCMw+pQhqW2hboYJ8YIaFrImoYnzq7BR0LzdSrAkvIft/tm9MRHETWHYh+WYvsvNC/4 X-Gm-Message-State: AOJu0YyDzXM0MQ0bQwJXVEadXAQYJg0hoEZFRW/Hg+T5p/8KvSqXj6ry ibVstThEIZEoLaFAxkv2iw6fmQ7qdr0hpZnNfJPBsoGi2fZaIooHztcnp/EidUVpahAwV3wDjbj JDcKmbAzM3ynGrsQHzMeiQxPAl3B4R2BBntwz 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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?