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 80E86C54E58 for ; Wed, 20 Mar 2024 21:14:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3FDE6B0087; Wed, 20 Mar 2024 17:14:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F01A6B0088; Wed, 20 Mar 2024 17:14:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B7F86B008A; Wed, 20 Mar 2024 17:14:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7ADD56B0087 for ; Wed, 20 Mar 2024 17:14:56 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 17F461606DA for ; Wed, 20 Mar 2024 21:14:56 +0000 (UTC) X-FDA: 81918672192.26.EEEC58A Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf07.hostedemail.com (Postfix) with ESMTP id 10C5E4001C for ; Wed, 20 Mar 2024 21:14:53 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PG4XKOMr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710969294; 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=xX9oR0yOAlJu5AjULoVW599QhTlzvmJ+WtVVYRHaP4Q=; b=ujZhO8bjdo+c+DxGn1ZNPelhQoITAUH0sF+pvO9uOIL0ekg/b1MWXYqwOvTM6HXtaAPxoW oT6gZAsY0blUD5dmgHVOYengkb0cpCF12juMRzDwxEOwE6Y7LTW7IMgNJa8ab8sVCP+Uu9 yx/HACsbCKtu0ljewp3wrrOHVj012Ts= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PG4XKOMr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710969294; a=rsa-sha256; cv=none; b=TvhowxoKwFmRRARW5kTWHkGxyUgpe3OX8MujVP43rDqDjGZ2OO7Oqozbf+o2CWmcCZoMLM huLFMAc0ADGgr6QNPlmxr4Sfcrd+B6WiyXcSQAQD6UC0v2ssuBW8Ub1Qbgqm8rjXC+N+2c pmMttskqKNkw4LG6fn8QDxZ1f7hZsL4= Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a46d0a8399aso238648866b.1 for ; Wed, 20 Mar 2024 14:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710969292; x=1711574092; 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=xX9oR0yOAlJu5AjULoVW599QhTlzvmJ+WtVVYRHaP4Q=; b=PG4XKOMrJkrACWbthuvvLBTSGS3gdzp7lhMwAACwPct31r0uR7Mk7DKs7UpLs6tCin 7QLvM/qtuCLBjy00TkUYJvFW29GckIjQFUNsZkrmDKcw4AzA4kOlfQjgicX1G4KX/6zl L044SLzbX3x3le7Sgj7nkygtAY08Gg193D8RdZY3FldTUfAZrCwSyJNXwc2rjhLyqBXx l55GVZX5ISk8CUZrwRpl3l2Ubxi3EnnrczYTXvyHaxZAfx5udgV5GCDwKZ0vZKS3v5hL mOhX1INFZIkA7jUoeTGf0A3hBHTYzQmRDbYwq+kA4Hyl2VZCS48jjUn94y0IDN4yOS7X 3yeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710969292; x=1711574092; 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=xX9oR0yOAlJu5AjULoVW599QhTlzvmJ+WtVVYRHaP4Q=; b=arDTrMbFuifaKDp+ANZ2r9ekEzuySWqLH/nDYy5CBvCORVRGB24Qg/79bISEZ/d0x1 MMQ+Ggr00UsriMTNPBAWX1m0l14Ng0VaJq9GEBBIjcXlnAKowkj50BnMRe1Aobm6PHu2 UeWIceNamtQFdm52pHQ/AcdIAq8f3n81JPWRq70pKEwO9A+9seSksxMYaqapuQiQ7z+H P1xIsTl1zxAWweV9op+P9oXgVpdtyqbWM00WBTnsicVZKgw3X5iMZPOpSVptW3hAh9Uq U6YxSxcxUyxbcNh7dw5LZCYPLGpBMVjy13DI43rbUhTWDMHOPCz1JbPuIKk1XvImSa46 5Elg== X-Forwarded-Encrypted: i=1; AJvYcCUgMjRUrFbdnjA6a3mcWFSMFw5jv0UKp1ttSQsUn513qhOZei35belOgK95yNsevZhiqr80gGCQsiYzUvtEEEu2UaU= X-Gm-Message-State: AOJu0Ywm/2r3BojdkTrotPzf7G/ClKL3mHiV3eywlJ2eP09yFREv9fzn QDmx/Ui+elVMC+QmKq444VclETwGVPttt/ayvwbkZfpNpC1OsCfatomHOcfKlNg2OwYV5pbhBYV KENKm/+9QsM8j2n934WkZyJZV8YW8c+ZLTlf+8vsGxuVHXgRU0A== X-Google-Smtp-Source: AGHT+IFxM401Z3Na0tqYmHJL/wi1dfvIWHmUlJbamIiwuVHhpHh/tkobH7mRI0iBj+14JLfLVf89T8xIenYzWRuWu6Q= X-Received: by 2002:a17:906:891:b0:a46:511c:ffcb with SMTP id n17-20020a170906089100b00a46511cffcbmr681071eje.38.1710969292258; Wed, 20 Mar 2024 14:14:52 -0700 (PDT) MIME-Version: 1.0 References: <20240320210716.GH294822@cmpxchg.org> In-Reply-To: <20240320210716.GH294822@cmpxchg.org> From: Yosry Ahmed Date: Wed, 20 Mar 2024 14:14:16 -0700 Message-ID: Subject: Re: [RFC] Storing same-filled pages without a zswap_entry To: Johannes Weiner Cc: Nhat Pham , Chengming Zhou , Chris Li , Linux-MM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 10C5E4001C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: s5hiqqse55m8jdf49brnqrfg7xssn1zu X-HE-Tag: 1710969293-999002 X-HE-Meta: U2FsdGVkX1+E/OIMPm/oiq18TtUNGAuU4myeoOMA6YDB3jPpzHYkA26lHL1eC0FZHboq3xl+EL5xXFaEC+0MAs3Z8TExKRAJHfnwRCVhL7wFEULw4MlXolvV/4RAbqLfk+z/VdoFjkict4T9WdcuNdgy0QL+ewwTEze96ZvJeyaN79OfGqLw+zt4zWS80fskzX4asnb0R7nNTTS+lm/BTkGDKj1dNHzip063CNbTSiWxkO0OTOQyv/xAkLQigyK+xfEUTt/E2NObnIsBPEiec3oQ0pTSAzX9QbxfSZKGKKAunOzKnqOTju5+Vm0GkiirIoF5K29//PCSDPBpkSkOOEklewPwyMQmKMAd4ujbIGEKL4DHdaUoGQScbNq+NE9szXSICTJaEq23pmqGuBKe/L7l1Q8AbM9rIRAa7iE1et5XwyP1LKyJksHa0gNBEAyBSsvAUQb47jfrRembZ+3QomJZOi4KnmvV2W/UcsRCJocyrDbm8s+LlhnofEXZ+y0VAIOlc5ysH7p6zZmAh7O15+zWwuuXUxglEcb3ntc5gsKaAMYMVxM77yUBWORkSvOxIQDUYPde+C0PyfsYt0EU7MBeFV6DwRMInshWjNrHXKWsvYAyfnuEI7o0jzZ/SFATMfWchT8lT/xJ3zsgbaJVP2bOe3eAbdwnHqvvunel7/UBZHaJZmMgXIHUNMhcgv22l4pxZ61unJHX4+ukx6mzvdNu1kC9fwWRH6e3xHCFflNWz6ichY8w4lMbYOUpWGgnodQKKkEjjLChWDpH+vB/DjJHN47XSlFjguiN2x86Y6BS1At2xoqquXIFwdH4fXcS56uZiN1t9EOVeFLA/ip+J1/8Og23ffUdO3LGc9hcfL7ftSOzchIEwqAe1FzU+Pe5lYlta8q9+fY5YbeJCBbZxUt9arrJWasBChLOFrfXF7nXvON7CRFmqL20rCRTGZfxcBiWjaRlSDbS9yB5BQM ay8qQcWn 6Pb0Tffjrj2HJrppjlrnIzK1VbFPIzlK49R9scdlHnDjO2SzXYDVvMfHA1iq1UMtqAnNEZeX+akzH4Z5x2PJqst/KAcHNqfQLQg8pb1wPQzPW8ytGVxa+mha9ezraMwmpcHU62kkq1jlZHSKHQbuJepZhxG+cebkwjdSBDcDzfF7eGAnJDQ1WDxyj1OG2XAorZ0cIXbm1q6l2LLASDhlFJnrnZb/GJ7UAGXUwEiAQcpQrKO12/f4tTmOz3MzSx7vqW6c7RwYS+ysfG+94zgGp3Em2YdslWUMHU80sfAlskkQUfSiSxiPTmhAYi02GyESrh6K0ht+0bkTcg/o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000031, 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, Mar 20, 2024 at 2:07=E2=80=AFPM Johannes Weiner wrote: > > On Wed, Mar 20, 2024 at 01:49:17PM -0700, Yosry Ahmed wrote: > > Hey folks, > > > > I was looking at cleaning up the same-filled handling code in zswap, > > when it hit me that after the xarray conversion, the only member of > > struct zwap_entry that is relevant to same-filled pages is now the > > objcg pointer. > > > > The xarray allows a pointer to be tagged by up to two tags (1 and 3), > > so we can completely avoid allocating a zswap_entry for same-filled > > pages by storing a tagged objcg pointer directly in the xarray > > instead. > > > > Basically the xarray would then either have a pointer to struct > > zswap_entry or struct obj_cgroup, where the latter is tagged as > > SAME_FILLED_ONE or SAME_FILLED_ZERO. > > > > There are two benefits of this: > > - Saving some memory (precisely 64 bytes per same-filled entry). > > - Further separating handling of same-filled pages from compressed > > pages, which results in some nice cleanups (especially in > > zswap_store()). It also makes further improvements easier (e.g. > > skipping limit checking for same-filled entries). > > This sounds interesting. > > Where would you store the byte value it's filled with? Or would you > limit it to zero-filled only? Oh yeah I should have explicitly stated this, it would be limited to pages filled with the same bit (all 0s or all 1s), assuming that most same-filled entries would be zero-filled anyway. > > > The disadvantage is obviously the complexity needed to handle two > > different types of pointers in the xarray, although I think with the > > correct abstractions this is not a big deal. > > > > I have some untested patches that implement this that I plan on > > testing and sending out at some point, the reason I am sending this > > RFC now is to gauge interest. I am not sure how common same-filled > > pages are. Unfortunately, this data is not easy to collect from our > > fleet (still working on it), so if someone has data from actual > > workloads that would be helpful. > > > > Running the kernel build test only shows a small amount of same-filled > > pages landing in zswap, but I am thinking maybe actual workloads have > > more zerod pages lying around. > > In our fleet, same-filled pages seem to average pretty consistently at > 10% of total stored entries. > > I'd assume they're mostly zero-filled instead of other patterns, but I > don't have any data on that. I think this would be key to know if this is doable. If most same-filled pages are zero pages, we can limit zswap's same-filled feature for those and do the optimization. Otherwise we cannot do it, as we actually store an entire word now as the same-filled "value". Alternatively, we can have a separate struct that only has objcg and value for same-filled pages. This means we still use 16 bytes (on x86_64) per same-filled entry. I think we can still get the code cleanups by separating handling for same-filled pages though? > > The savings from the entry would be a few megabytes per host, probably > not an argument by itself. But the code simplifications and shaving a > few cycles of the fast paths do sound promising.