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 3DA1FCD11DD for ; Thu, 28 Mar 2024 19:38:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2A896B009E; Thu, 28 Mar 2024 15:38:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB3E96B009F; Thu, 28 Mar 2024 15:38:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2D426B00A0; Thu, 28 Mar 2024 15:38:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 811746B009E for ; Thu, 28 Mar 2024 15:38:58 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 477E3A0278 for ; Thu, 28 Mar 2024 19:38:58 +0000 (UTC) X-FDA: 81947460756.19.280781F Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf28.hostedemail.com (Postfix) with ESMTP id 27A28C0015 for ; Thu, 28 Mar 2024 19:38:55 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=ybMecj99; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf28.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.178 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711654736; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XCiQo1MAtcR26ctf6PaMfsaO2b9Y5boPDvEB8BEdvaw=; b=vsV7iBs0XQpG2pfzjTdwapOiO+ONsv1ZTrW6ng5UjhmYIKSkBcPN739zxl3L/iTC5D2Z+f 9QUrb9XO9AYtwGi3QjOSpX5gt59Y2BucxoaIWIH7e8QOSOEdR4XIw5bDu7S3bHN1aGgqYW G1qs4cngvYprm92B15xgLBpzN5KhLFI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=ybMecj99; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf28.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.178 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711654736; a=rsa-sha256; cv=none; b=D435ne7gYUEAR6MOJQDUA77wO8427ClKzDzP9LjTg2/du+isn5tJ2r46lq3kS1MeUpBJO+ W4lRJLzMebIy79PrvJEFJbq5mqNCxlwizKuvurLeDjDWPO5OjaaXxtnLkF9UyRvoxDE21C mcQI4uwFlfusZAQX38WglhtEo4k3Xag= Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78a2093cd44so87682585a.0 for ; Thu, 28 Mar 2024 12:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1711654735; x=1712259535; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XCiQo1MAtcR26ctf6PaMfsaO2b9Y5boPDvEB8BEdvaw=; b=ybMecj99f3MZDZfAdpw7tD0O4VG/zvpyrkNQhp0B1Xq+C096/zZs/v3UzmqIqiU+8g baPRnfxbFZNxHYKgvD2bZkrCb1773elXdYpkN4wIISX5HV5p+7U4zjKqRm+FDZvRLm1s RLAKf+87kgKbJMbWNtXd6caVyF2C+JU9EShoYj0UUSeKZX9XfzFK5+qQKnjalsnaxy+N hwiCBkjd21kjx6m7LIvro+WUC9sqvWhtkI1lg19624Dd+OH5zdTtCNvmGVqEGjS5wIkb RyHmtoEHr86bq0cgSmLGTnva6ZdcbLniExSN8lV5b3hpXtwpB+LRlPM109nyGDWtgR4V vlJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711654735; x=1712259535; h=in-reply-to: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=XCiQo1MAtcR26ctf6PaMfsaO2b9Y5boPDvEB8BEdvaw=; b=QmQT+9sStnsODFsXSOGKoJcG0DZDw8KqpbHCwel/0/UERriC3XU/XfWZeM2EM4B+Cr tLgIUVoWyj+HQP57ZIjlz8zKhzq8fJpZRRsgI2hiCxUaoPKEDHZSpGmLtjkUWFDEJZ9s P4Zq+O/NoBVfuyCpZp7tOMCjC+V5HefxUBGj+02NC9EVbC9k8AXbsO0OY4cL9xTsMzyH MFHEb7EG5yNf7Sm7bkE8HOWKQlXJ6yVemmAqM0uALUVlXJxsWh42GlpAKk620qosnGel Hw681et1dNrk6R2fvS7oPJ40+2RhGwDkJ1ps9gLW0rUm4uLidEUULLHxWjABoaIgUsPz bQwA== X-Forwarded-Encrypted: i=1; AJvYcCV/a34aZ6cAEg7IFrZKT474k1SnaTNXMq7j6I97Vwi649FgZX6ydj9W7lE0YUWAaLJA6DvFnfYu6PyBkQecwkEQ+2U= X-Gm-Message-State: AOJu0YwxSXo+HCPZ2C0tvBS+FEKfMD8MP/e5e31RmMo4/x67ZpOF8ZHb DPxydz1sBNB7BXrO1UipSAS8+0U0lcZwTiyUn5ZMhIUpZKLR1GClQnFmTp8S/0c= X-Google-Smtp-Source: AGHT+IHS2fTAhR7/2bFnaQsf9xIhswTUUUgW/mbm1wT+yk0UQqtu+X9Q7joZO8+Jr3iYQwrNMIJvWQ== X-Received: by 2002:a05:620a:450d:b0:78b:c549:c3bc with SMTP id t13-20020a05620a450d00b0078bc549c3bcmr431043qkp.54.1711654734966; Thu, 28 Mar 2024 12:38:54 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:bb1f]) by smtp.gmail.com with ESMTPSA id wx37-20020a05620a5a6500b00788402160besm770464qkn.128.2024.03.28.12.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 12:38:54 -0700 (PDT) Date: Thu, 28 Mar 2024 15:38:53 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Andrew Morton , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 7/9] mm: zswap: store zero-filled pages without a zswap_entry Message-ID: <20240328193853.GG7597@cmpxchg.org> References: <20240325235018.2028408-1-yosryahmed@google.com> <20240325235018.2028408-8-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240325235018.2028408-8-yosryahmed@google.com> X-Rspamd-Queue-Id: 27A28C0015 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: eegp153gmbpm3uiixceotuop7y9fsryj X-HE-Tag: 1711654735-140339 X-HE-Meta: U2FsdGVkX19laNa6yjdx15jz3Ag4V3pWzMPKrB67A0fgjdaBYZe1aSrjvd/MS+TE4koFUSNdsGG9PnohFZ/XtYKQv7spmyNcLeEyFoEs9my2EnlcCWaX0p8NhlezNF3H70uzx4lGYPcg6Z1uSfbLmmLkDICEdUMkiosF2v1YHlABFug3XPLwwbVUPj61i/y+LmmWpyFOMMqB3V1zgmhTdsgY92rFi85lbBeQ7pkG6oQV1fs8032VO+Hhn9ImNqBRpEwoLoh6ss1jfHcxkhx/WVJb/qeI5++ZkSzB1jOj5auMlFht0jzBha32xJ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CDXaZUD2O08vaK1Sen7DIEuaFiDC+9sLWwubL8oDmjrq+kt5rx+7cSX5dSj4chbURND+Fsd5MlM9JxS8J13ASgj9rhhBkt2sdly1Og+UO5FbPm5GWEILHgtUxP36v63uoLzQjoFfAirxDKm9q8fRbKPYPeCwgZu3q0ClD9EQ1mp/QGK0l1/UiwSOtVdV34xwZran3BMrI2v4xdT075Irfs/y6XbR+3EXKgcftS6jR6hFis7jWFodLECw= 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 Mon, Mar 25, 2024 at 11:50:15PM +0000, Yosry Ahmed wrote: > After the rbtree to xarray conversion, and dropping zswap_entry.refcount > 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 skylake > 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 should > 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 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.