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 4C867C54E67 for ; Wed, 20 Mar 2024 21:32:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B6B66B0082; Wed, 20 Mar 2024 17:31:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7663B6B0083; Wed, 20 Mar 2024 17:31:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62DED6B0085; Wed, 20 Mar 2024 17:31:59 -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 5500E6B0082 for ; Wed, 20 Mar 2024 17:31:59 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1973FA1A06 for ; Wed, 20 Mar 2024 21:31:59 +0000 (UTC) X-FDA: 81918715158.22.B20E07A Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by imf02.hostedemail.com (Postfix) with ESMTP id 3A9368000D for ; Wed, 20 Mar 2024 21:31:56 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dqf0INIw; spf=pass (imf02.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.50 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=1710970317; 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=7rXA3q5zMt2mcJ0NrmVnz+PZZfLlnOdp/sKLijhc34U=; b=xDK88CRECCNVLsxcUW2w1Jquf69ubH7PzvRAInHicBe30rzho5YFGsOGOkNKJy0P1pD8xp lm69ZJsKdSk5/A6Obi4ZSm3pC/aK1NX4ivS1ly0kUJiOkvgTkEZJPMlbeYZ2eM/Ffzec1J l5AANWrP20pHkjpiPhHNTGWo/9JZgeE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710970317; a=rsa-sha256; cv=none; b=FnP/3MeVbnFx85GpfUsHV8Rj2ay3RN6lCi1aaig4trddT8KSGV5te93UVVC4e1W9pFrbbL j2bes8huobWr5uvyM3LKnePDRQKQcFKus2bfkMM8wiwHrWo3lT/HkP1XEK0513wDSG0qSW eaqcOqjva4JKx6+oowRDB7AOEpnTO/s= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dqf0INIw; spf=pass (imf02.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.50 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56829f41f81so358480a12.2 for ; Wed, 20 Mar 2024 14:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710970315; x=1711575115; 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=7rXA3q5zMt2mcJ0NrmVnz+PZZfLlnOdp/sKLijhc34U=; b=dqf0INIwKUU0a/ZNewmr0kHQJkivNmVjHVWaTyMJ+s/van6LNnGPBAfuMilxWwFLj8 N2hpj5uG9+Q+xwzSAoSUM5ypBwYlNttpOR3sX/HFySEcDOm/hDYgSTnNDGa9TLgLq+YP coyNHB3a9YBgR75WFCEZGhfNeQSLyg2rd8+nvnsHfn2X3EZdRkFwxzAAN/TBBv2VqRY4 1It8XwejIj4CJhvAZWd6squHEUICdZVC3FD+ZW0ijT7wZsGJCz2t7/O5rGFFlWf6OUWS x4BJ96mfVcVFtEZzwESUGpqDLpuID9fAFdpLaVQoTNOOP0PO56tx9lUR3er2aM78ezEf jNAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710970315; x=1711575115; 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=7rXA3q5zMt2mcJ0NrmVnz+PZZfLlnOdp/sKLijhc34U=; b=vxGxUqlbeGAUjKQzE8wfjpfIocln0thtZoLNCF8SMiShU+Ilc8y8JYYsCLHnD8HhJx GfC0IZnenKHIWwdJuprMZbj6xwAGTAph9shg1ktbyhjpOm4Ti+0MgHdiCyVMBtZUSjlP z+me9xejHk6Hn/LKBY/lBHwru30w9jS8k7a+SOPEkMzGzS58k988CNgfuACcrh7sfX9D wc77VYIHLOiqQ/jZ78PzgcmEmTYXua31L3Q2U1iozsV1EFxM5rY9MbqU1FoCq8WzMOb2 Z6hGz3hfIiW+0aW04mJFUosalxUpLnSz2hQ6Yarksh+z8l+uwZBujjel9dnVmyUNQnU2 IPbw== X-Forwarded-Encrypted: i=1; AJvYcCUmlKWA2gBIYp3OdKmZI7A2ocXEW7OXBCOeexP/KZSND9DS7qKFUke4BQHpXgkTrjaWASkK9maBQM4PcVtjXFTwETk= X-Gm-Message-State: AOJu0YzNi62LqlkQdPFQB+wSPi7bfbEmky92VNblMZctd8Zfvk3ny6BH XLC42nke+vNkoCvXB85iGXUF9BtoO3aaFT6rIARB90NT5VWwS6ynNm5aN4/uoJya45V/WW5UxWw yqBH1PKAVvLn1svmls3xI8xjLNFXLezkQvzlCSfb5Jg16TpJCOA== X-Google-Smtp-Source: AGHT+IHRl7enRiXjT6vReqfA5+fVPOMzS4dnziDcr/Eo8QHrY+UD65AqRi03EPTHgxC423S/f4gGseR5dvq6hL/4I5Y= X-Received: by 2002:a17:906:a415:b0:a46:a61b:1bc9 with SMTP id l21-20020a170906a41500b00a46a61b1bc9mr1928544ejz.18.1710970315407; Wed, 20 Mar 2024 14:31:55 -0700 (PDT) MIME-Version: 1.0 References: <20240320210716.GH294822@cmpxchg.org> <20240320211945.GI294822@cmpxchg.org> In-Reply-To: <20240320211945.GI294822@cmpxchg.org> From: Yosry Ahmed Date: Wed, 20 Mar 2024 14:31:17 -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-Stat-Signature: uuby6j8pdmcdgwyp73u6ccudrpwh8459 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3A9368000D X-Rspam-User: X-HE-Tag: 1710970316-642115 X-HE-Meta: U2FsdGVkX1+Zfc2bxGzbuNCshkurWgUaf7iZ/6GWAdCgfCvnImPIt6LarpPGmuukvrbPJrCvgEIsxyEAZkeTspzJa5D7QDFFBTW95f2pl27I7X2UkHaFBlszdzC416DW9s5BAC2GFyfoslL76lKWccoXjXKjCqbOTDyNsNij3sG60GTh2mmkAIYcZ+q33ur/T/exDEvRlTXz7Adn+a5AOJpgddyaPl2JMwSwx7pCkrtAcn6bYB60BV6EMsrf1j3/rukDAlIv8caIebHy974P6r7EQCiDrU47JCeQtVaes1E6kY54SaCYrkmmVPjZNi7F5eD31TtREg9gYtqpwsxtMLNX25sie1RvtVGefn6xnJMQSw9qCEhGYwwZh/wAQ0hWhz5AYw3oEBO3vDnPiyhH69DVsJwR8A9sWf3pYKfbik9jHtWHk1PATst+XQRgRhjCMG60nXxjB1VfFJfdxJsLNJNFdU17oAQax+4eKrYW2ohYkhg/TM5g/Jkmq2oAoIHyT7uEDtfr2/xcYSI6lrnd3LS7kcO/2dqwR7HwFz8KI2O46MNrcqX5QvwwWTpjXtDArQGeKZ48O+TZsw32XwULFBwPYkFLCt/nY/SrZ2/Izb+fgKPhlHKoJ2ZiF3ysGx6kqvv2VYvXEZKE7lOr9h8Fy1aG2FRn54GjEfs4yKSoxU+5bxwSscn2aqa3RbQtM4rMYDolLnOrARHxM5volZ8fPZtbCg5ihooIsJgCw2W1cgFzx6xMIOo+NFsvH7J/jlkpg1O+dvit4zYlt5HXPqbOWy0plmmhRX6IOf0E1hLcpE6n4jvpbNwrc1cu5KqbrC7EUatyIS5HKE/l4V2PUmqjxGMHsFVhKSQE/DK2MD5qJZjL4OUa702yeOUKqdrnxPvyow1hgY3EKX/wkGO7Oq44nyv+HcDAUczGpDpjmVFGr96xC5KowlxdzD21EublznHMKgVmpVsqb0GmtN/Fl9U x7BQIMMm iu3BfRswxGd7MdwJYE8NTXj0QN+9UlT2boaYGaTcW3jlApOgqN22UEEOL1wUwUgxGoGCMdp2mcp+ImhU6h1QyowW8lNj+s9DBmrrmaaEElTz6EvsBp3pum/43z5zi2WFeOlU/izMPQtFLxo7+OGb4tA3wSZMwRNQ5SFYQnraCpJ7fgiJjMzD8n6n9zw/20O9H24Q9wnbjbvc+/WhCPnFQddc9exFi2SWHt7PiBkHcp92Sgj8MbwcFWnkCe0ypUMZOaIeGLTWvckMSB6Lg3UbA2PUw+75Gd1UEtpLz+uiX6lhTiUio4eUyCoNHo1zApivKRKVNktPZi2AqkU8= 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 Wed, Mar 20, 2024 at 2:19=E2=80=AFPM Johannes Weiner wrote: > > On Wed, Mar 20, 2024 at 05:07:21PM -0400, 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? > > The dumb thing about objcg is that for same-filled entries we really > only need it for bumping ZSWPIN. Nothing else. entry->length is 0 for > them, so even though we call the charge function, it doesn't actually > do anything. > > Loading them is cheap and doesn't involve decompression. An argument > could be made to exclude them from ZSWPOUT and ZSWPIN entirely. > > Or cheat a little and bump ZSWPIN for current->objcg instead - > probably good enough to make excessive thrashing discoverable by the > workload that's directly affected. > > Then you could get rid of the objcg pointer and use the xarray slot > for whatever else you'd want. Yeah it's only useful for the stats. Using current->objcg would work, and should be ultimately pointing to the same memcg in *most* cases, I assume. We still wouldn't be able to store a full word as we do today, because the xarray needs 1 bit for its own usage. So the same-filled implementation would still need to change from repeated words (8 bytes) to something smaller -- or we can just allocate a separate struct for same-filled pages.