Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1312797lqp; Fri, 22 Mar 2024 11:03:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU5N+CULBif/9LYWlo0M0rsFjjmD/l4uXg/9THf+j3EK2Z2Adgyk2XNkBL1f/+vuIWgEYL9AaR0HTOEPafKOF2v0bR0jbay2RhnR/ti5A== X-Google-Smtp-Source: AGHT+IHNVM26n8SEkdvs/9urVS4P7H/TSfOyUZkR20Rr1T6UvxV56XOYNAhnyr62VbC9bQvRs66d X-Received: by 2002:a17:90b:400d:b0:29e:460:47a3 with SMTP id ie13-20020a17090b400d00b0029e046047a3mr354685pjb.12.1711130630901; Fri, 22 Mar 2024 11:03:50 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c33-20020a17090a492400b0029f74696c79si6052261pjh.53.2024.03.22.11.03.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 11:03:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111900-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=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=WKLQsoOf; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-111900-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 08166B2328E for ; Fri, 22 Mar 2024 17:57:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2DCD660DF5; Fri, 22 Mar 2024 17:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WKLQsoOf" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 338B060DDE for ; Fri, 22 Mar 2024 17:57:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711130236; cv=none; b=u263L0BQnlHthBloVuST5Erf8ECdq+X2F8qG2oGMtm2SmVbyU99SLGz37MXm6H5Mnq5Na8TSRhUWFgNNMBCGWaQH3pjDwFYhR+NJ89MBJBftazrVtNGuhZTN4Xg2uKSb+59ATbEZGkKLUEKg9rMi2qCmdGNV0boY4nbYZikH9cI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711130236; c=relaxed/simple; bh=mM7NWhSY6z5TddPTSw8WVC1hSX82LYfXMQln00iystk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ghEui9QXm6yNTGJB7XQL0+WgRORigBKzUzV9lnEbbVgNOpvQ0F91abfz5fWL2psJPpHBnvxmVJX4JMWPcWcUMEA53msUwVCOYXcNbBPjgL00t7egazRKp/Ee7raUxSw6Ee6SqsicL4RVzKu0TbSDrkt/GalTqd1qsyKkpbEuKaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WKLQsoOf; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13560C43399 for ; Fri, 22 Mar 2024 17:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711130236; bh=mM7NWhSY6z5TddPTSw8WVC1hSX82LYfXMQln00iystk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=WKLQsoOfLM84nHZsCNIBwYx5ELFGnsaCFTZySFMjn7ya3HaXdINPhqWzPiPlhL1uu cN7q28v7TRcPG3NUPGNK5W//Nnf85jIKTExiNeRvN4QZIZkmHUVh/ZSUVw1Fujv4Ca hpCELeIybKK6TWXcpNjV3/vY8+VGzURkBXqbcgvuFZTN/xY8Nb8KNsMjIiCib3KCJi ES+f/kcGGcFLly0khLRW/U5PaKq5E8PtJ9aFclh/HlKT/1HR8cSyOylp8aDOFz3uJl ZaDkZllTlNzOHokcZ1sBsJW6OC07QfkyRAc9iiMdE+GnkORGdFIRwBgq2tpsQ0HMfP HCsuQBPUnHzag== Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2d485886545so45361321fa.2 for ; Fri, 22 Mar 2024 10:57:16 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUo/yz2WdYrajtMimE+/8n4St6cgKedUPPJ7fEON9XtQeJahbWXvdUiCGpyRiUxt2Yp8u1i/kwf7JbX+tCe0ZEVTrdxr2syUMxkz1bU X-Gm-Message-State: AOJu0YxBBtkrotcU2tDpOahGIxu6JmMbHgu5emM36B/gcVWa6LqftXv1 ozPfbrXfZJQwOt8lzURZnTYQjU7b+AtRpHrK/dqkSGi9g0Sjdf+zQGOYglLbVfgZYCwBc8p1CsF MXvkNznAMVSM2G2i7WAo91X9hIA== X-Received: by 2002:a2e:80d9:0:b0:2d4:8bfe:69b7 with SMTP id r25-20020a2e80d9000000b002d48bfe69b7mr209193ljg.46.1711130234650; Fri, 22 Mar 2024 10:57:14 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240321-zswap-fill-v1-1-b6180dbf7c27@kernel.org> <20240322031907.GA237176@cmpxchg.org> <20240322171156.GC237176@cmpxchg.org> In-Reply-To: <20240322171156.GC237176@cmpxchg.org> From: Chris Li Date: Fri, 22 Mar 2024 10:57:01 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] zswap: initialize entry->pool on same filled entry To: Johannes Weiner Cc: Yosry Ahmed , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Nhat Pham , Chengming Zhou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 22, 2024 at 10:12=E2=80=AFAM Johannes Weiner wrote: > > On Fri, Mar 22, 2024 at 06:35:43AM -0700, Chris Li wrote: > > On Thu, Mar 21, 2024 at 8:19=E2=80=AFPM Johannes Weiner wrote: > > > > > > On Thu, Mar 21, 2024 at 04:56:05PM -0700, Yosry Ahmed wrote: > > > > On Thu, Mar 21, 2024 at 4:53=E2=80=AFPM Chris Li wrote: > > > > > > > > > > Current zswap will leave the entry->pool uninitialized if > > > > > the page is same filled. The entry->pool pointer can > > > > > contain data written by previous usage. > > > > > > > > > > Initialize entry->pool to zero for the same filled zswap entry. > > > > > > > > > > Signed-off-by: Chris Li > > > > > --- > > > > > Per Yosry's suggestion to split out this clean up > > > > > from the zxwap rb tree to xarray patch. > > > > > > > > > > https://lore.kernel.org/all/ZemDuW25YxjqAjm-@google.com/ > > > > > --- > > > > > mm/zswap.c | 1 + > > > > > 1 file changed, 1 insertion(+) > > > > > > > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > > > > index b31c977f53e9..f04a75a36236 100644 > > > > > --- a/mm/zswap.c > > > > > +++ b/mm/zswap.c > > > > > @@ -1527,6 +1527,7 @@ bool zswap_store(struct folio *folio) > > > > > kunmap_local(src); > > > > > entry->length =3D 0; > > > > > entry->value =3D value; > > > > > + entry->pool =3D 0; > > > > > > > > This should be NULL. > > > > > > > > That being said, I am working on a series that should make non-fill= ed > > > > entries not use a zswap_entry at all. So I think this cleanup is > > > > unnecessary, especially that it is documented in the definition of > > > > struct zswap_entry that entry->pool is invalid for same-filled > > > > entries. > > > > > > Yeah I don't think it's necessary to initialize. The field isn't vali= d > > > when it's a same-filled entry, just like `handle` would contain > > > nonsense as it's unionized with value. > > > > > > What would actually be safer is to make the two subtypes explicit, an= d > > > not have unused/ambiguous/overloaded members at all: > > > > > > struct zswap_entry { > > > unsigned int length; > > > struct obj_cgroup *objcg; > > > }; > > > > > > struct zswap_compressed_entry { > > > struct zswap_entry entry; > > > struct zswap_pool *pool; > > > unsigned long handle; > > > struct list_head lru; > > > swp_entry_t swpentry; > > > }; > > > > > > struct zswap_samefilled_entry { > > > struct zswap_entry entry; > > > unsigned long value; > > > }; > > > > I think the 3 struct with embedded and container of is a bit complex, > > because the state breaks into different struct members > > That's kind of the point. They're different types that have their own > rules and code paths. The code as it is right now makes it seem like > they're almost the same. From the above you can see that they have > actually almost nothing in common (the bits in struct zswap_entry). Not sure about how you envision the different code paths look like. > This would force the code to show the difference as well. > > Depending on how Yosry's patches work out, this may or may not be > worth doing. It's just an idea that could help make it easier. Agree, would need to see the actual code to reason about the minor differen= ce. > > > How about: > > > > struct zswap_entry { > > unsigned int length; > > struct obj_cgroup *objcg; > > union { > > struct /* compressed */ { > > struct zswap_pool *pool; > > unsigned long handle; > > swp_entry_t swpentry; > > struct list_head lru; > > }; > > struct /* same filled */ { > > unsigned long value; > > }; > > }; > > }; > > > > That should have the same effect of the above three structures. Easier > > to visualize the containing structure. > > I suppose it makes the struct a bit clearer when you directly look at > it, but I don't see how it would help with code clarity. Just curious, would changing the anonymous struct to the named struct helps to address code clarity you have in mind? It would go through entry->compressed.pool for example. Chris