Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1138336lqp; Fri, 22 Mar 2024 06:46:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAVaBUDoupozQInI+WJVVxmLzNuiEdnygdsmwmOSTW9DWfoB9S4kXVQtjFger5geR90EYLClzkDY2/1klghFyZfMOEWHPD1gGERgGZEg== X-Google-Smtp-Source: AGHT+IFhOa7lszamgaUTp4bz6fznisYPJdD3LW7VH/3ODTLOCLgQ9ljqAEZ4kZXRMdEwBuhIHHzi X-Received: by 2002:a17:90a:9f86:b0:29b:c0a5:1143 with SMTP id o6-20020a17090a9f8600b0029bc0a51143mr2371057pjp.29.1711115208388; Fri, 22 Mar 2024 06:46:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711115208; cv=pass; d=google.com; s=arc-20160816; b=lp7xzX4x0ovKkvqpjDLTcGGjbN8VmBwvwQPI9zcSXxvDCb1K7jHbKJR/uZgY+K4zB1 uEUfTzJrXBLfuQdnubMCnIX1zRxPtruhmEbLcdBRXbuez3Rars06PqffEYhZPPq0hFE2 MaEy+Q3ofpfQrGhGT1+AkuSEo3oQzqQ271syOp1cT/FiK6zYMQG9D7DpzpWScFo1D3st c+MELxuvIY20MY5M8VJZxx+/xcFDuDzwYo+4BWUaDsLUYv+j/eMaRi7Rk025iynv2u5H soy+setUPaB+zb7/yqRFJWsCaamcKjj4WLoe7nAzPpvliMfIjbpUXrCdUhoPd9D58IXG 4nVg== 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=b4NGyPDpVDTT3d+LMeo1IhJ6qBpdHELPHlqxJ2QV4o0=; fh=Sl84oou4HZw4KmDte7q4C0CirmEgD+LufjEEvkTuyA4=; b=IYR5rt5mxulXUDae833QnkcfuOIeK6uWENOvp2xzbmpdFGlhAdOAyQcbsCZIv7d83G OTbH9Ja1OyU7QpZEzGBEbfIWoHoKLTze4uhhiB/Ux6qrjxgx7Cy9qCG8dOuK4kmq1ju4 TJcLaxGm9a32tmaaAnEda5OhACIA1VN+XqQ0wtT2sm0LYbtJ4OVuIdYN/22vofsvt4TK JiPhg3zIKEYCwlZu64296MsAWgHyPMa+3yp063KwPJan6ht4ePMTAiPsjQzQkeCqs4h4 kbL4vx7JUoRHGTltBQyNFS4d6/Sa5OfYAjbZixmE9TL2DBFKPqRGW6aZxPR5aY4oI3bA haSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ptLKrBtb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-111551-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111551-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cm16-20020a17090afa1000b0029de14d6ae7si2107835pjb.112.2024.03.22.06.46.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 06:46:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111551-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ptLKrBtb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-111551-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111551-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2B5ED283BC5 for ; Fri, 22 Mar 2024 13:43:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF7F55C603; Fri, 22 Mar 2024 13:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ptLKrBtb" 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 CE97045BFF for ; Fri, 22 Mar 2024 13:35:56 +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=1711114556; cv=none; b=biZ9daJDc0LBqCR5GoldGL8wiBdygLExsF1IhBcJs3iF9f7sCYOD2Esag51FI/cH0Z/6u3yOz3fbwOG/s89UWesbpiH34PSrpBLpNQINo2+3klasyVWkQ8byx176HEc4PtNuJrbOciRUfr2I+VqXheA2vfindHaSVwhYkAkVkeQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711114556; c=relaxed/simple; bh=u0PRJPH4zZcFF3xqQA9fGoW/XmvWMaMyEmDCCXX09wU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=NgzrrTMR3v7g9Ky/JABZFpHKrOweaIM+OTY27YOnCt1A6CnDpWDrMVOS64BbVq8fwRSrYGJRYx3g2MWBvf6B/hpSZ9Z7B/MwJ2OLuRRWtyRbL6mix4fb0Ln/LN29lLFE8eDGAFfmgk8CODhh68q1v2RPVkGDTH4qx9j5wgLADPI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ptLKrBtb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50DDAC433C7 for ; Fri, 22 Mar 2024 13:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711114556; bh=u0PRJPH4zZcFF3xqQA9fGoW/XmvWMaMyEmDCCXX09wU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ptLKrBtbhchtawol//pqO8ctqLfceMYNRVf2k8KlxloAAyepmU2L5ys4vO73YQbth WX6VqEXu4YaLfFdofK5Clz3eaiC3S59dYFD18zYRbY2YKxoepuxeHIDcfVN3jNrfxE Ae6ibCWeE92J4cwYF/95AjR00uM5RNqyQ5+UehyZG42j3IRMfV1wKOKvF5WD9pP5Gu q4qirbN834oFjj8uzQFJO3Yb+uwzYrtTGwKfNqPu3TxOJ+ea6aYOQXpGcBHqx7QyGA KCWsFT4caDHVxwMtKPT5/pXCJlmw3wzuqIsYBgrRwlse1dbF17d8YIzFsOgsqYijcF 8/zqAkWiQS54g== Received: by mail-il1-f172.google.com with SMTP id e9e14a558f8ab-366bed3a440so9101115ab.0 for ; Fri, 22 Mar 2024 06:35:56 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWHOPuuFpdIMC6AhSdmL5iqDBKB7cF82K5GChhO89tw2pZoDRi68mZFJP2VeL8+TJZTwWrwoFgE2RF9heH9AfywiPbDWJKa35DAqyh7 X-Gm-Message-State: AOJu0YwADSAZyK6VTICnJeeWpnCfa3EysEeAfxX7P8J13Vnbnqkv1pho oqejwymf2l36j56666Z6D7t2oRpk7tJSGhkIiKDfhwLaoDUgngre6Zb1j0pEBFm+buKUYDhgEUc wi/EzdNnuN203O4BwdE1xMjvLSBNIaT65oG/K X-Received: by 2002:a05:6e02:1252:b0:368:727e:ec71 with SMTP id j18-20020a056e02125200b00368727eec71mr1486400ilq.21.1711114555719; Fri, 22 Mar 2024 06:35:55 -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> In-Reply-To: <20240322031907.GA237176@cmpxchg.org> From: Chris Li Date: Fri, 22 Mar 2024 06:35:43 -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 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 wr= ote: > > > > > > 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-filled > > 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 valid > 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, and > 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 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. What do you say? Chris > > Then put zswap_entry pointers in the tree and use the appropriate > container_of() calls in just a handful of central places. This would > limit the the points where mistakes can be made, and suggests how the > code paths to handle them should split naturally. > > Might be useful even with your series, since it disambiguates things > first, and separates the cleanup bits from any functional changes, > instead of having to do kind of everything at once... >