Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp106942rdh; Tue, 6 Feb 2024 21:53:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGudLV5LSw/LN6FehNkZUlxaNfCOP2MyNCJ17iEHHTul015N2MVze8jLUdXk6i5cl4Ru2xb X-Received: by 2002:a17:90b:1256:b0:296:8e4b:bd50 with SMTP id gx22-20020a17090b125600b002968e4bbd50mr1619439pjb.13.1707285222039; Tue, 06 Feb 2024 21:53:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707285222; cv=pass; d=google.com; s=arc-20160816; b=dGw/evVQhjpTECb5jdSRLXNjtWiJ/9gDIit4aVGNzjx251t+t5e6jKOZANqDVd6EMB ascO50b5gr/dPxwSe+KNvrPKrDkc3kUXjThU66RLw+VqdHRnJzSCUa0pFwFMSKQdX1kJ H/bFLS7bR1liZmJ1hAzxPcHHcDuiXs+FqViMXtPKPk8oLSJM3Nc6hkeC1YArhPW0FftT 6mKZPnwbhkiY5eTpPMELQgKbzek7ZWx2j6EOKFWzK0yOufmu+jpivU2Jb1yYPk9Qv8Ma 1/RX0wgy/aF1OYB9uy268G0ljWNmznFdoQLPOaLFVrqve4fEHI7g0rveoveHewXqJMnV 4/dg== 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=mn8gXq14XAZBLuWVrxGUeNd5QV8jGsHpQPbsz7ocwiU=; fh=EofWKlSDBSOAXiPwQAen9ann41y6czYA32+Q7xbslRs=; b=B/GoLCS+cgUrJvpSQpDrTEHYgt/3WulQj6TlGgf5n9iRma1MGi9CYpxfLHUilUNj0W XnZl7EFg4uyH4gGD5YM6JXLfJKxS5DemIBUtBMKMuuPxU8CyqQFETNnX0pZgGSn+b1ia eHFkE7sPLAjnphA48FoFrsNZhknR7AdVaRTAGsSfinQ3N1j1HrLYeHtZq1rHCiEoQay8 YBBgFNy6snLtIvM6Ezula8NEjGcdi2XVPQja+OSw3zyZepW3axyQqF2FLRJSHiXK0b1X AsSJtnYmmFZO91p2I+oXtpEkMPX9UvtDZMq/8C76h9UIlDzJZtx2AAs9ii6AIkK9C8e8 223g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VWuRugET; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55988-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55988-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVoUk01+Oy+G00FJgTbSIn8tmw4mKCLZWsb0rFpgm/LmAyk5x6UpehwS/4a8+Fs/0OFf5c7/gXo0f7N713JesROz6Z9xywrFrB5XbqE9g== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id mv20-20020a17090b199400b00295c66c65a3si798968pjb.119.2024.02.06.21.53.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 21:53:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55988-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=pass header.i=@kernel.org header.s=k20201202 header.b=VWuRugET; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55988-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55988-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 0AD7BB2417D for ; Wed, 7 Feb 2024 05:53:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A9F117736; Wed, 7 Feb 2024 05:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VWuRugET" 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 21C371CD1E for ; Wed, 7 Feb 2024 05:53:06 +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=1707285187; cv=none; b=oMOLdV10HeEtgmnLbNM6efOu3lMGtH2SaVc3Pvx5V5fb/Yxeb7fTIeKic4DD5fRHDuDu+bBSi5kZUeu7B2DaxIuZeTMYvh9KmMJRfNyZuGO+3/m8HzHmfQgI50omSRrS3Z2/pQ6R8FrTGdj7hul2X864iOOtpSC2TAJeLPDkFrM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707285187; c=relaxed/simple; bh=TByPXr7dTrWn79s6knx+N7D+PQY5JFNqw/lbqQ/BLu8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=idfckvNERy9xiT9f70qG8HA0aipd4Tgz+0jYAZgNaDO8/Yo0s2pvvNASO2U1X59i5agJqM7F6wP3WFaePLfWbvypu8VmMoRxWA7dhKmOZ/atPGUg5T7gi21atw7rABnSsENJ6NniDcXWkLCJpHwxWlkFiwFjCd0mKPhXqXS+J8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VWuRugET; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95342C433B2 for ; Wed, 7 Feb 2024 05:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707285186; bh=TByPXr7dTrWn79s6knx+N7D+PQY5JFNqw/lbqQ/BLu8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VWuRugET//9iAp/Ke71ta5Mw+Tv2qJhWf15UxvbSj0TSVqxTEBbPmHLgEQ+JVkSIM kUFxfCxYrI1riZdm8Ly6YT6Y1s3tC52RZ+8Mlad9bVxVVk/l/31zDlUvC6Rv15MqMf e3ShULMeNqWM2QtQc3gUnQlWIZiiGGuS3/aG5GVbUznOQonCUGf3Gb4EAZmwQZ6L0F fPFqddC1SEczggTj5W5P0Isu67iSGaZf5mR4INZoiAO/4AKlWP9fH9twJzpQK8R/Ya dJYJpvo3qwHPmRT6miGDDhZ7dcQ2pX/yDGuUvNKPa/7sV+XAYFxIIT7J1g4vWO7p3d yyrRvl2OKUOsQ== Received: by mail-il1-f172.google.com with SMTP id e9e14a558f8ab-363b2cc9372so652185ab.1 for ; Tue, 06 Feb 2024 21:53:06 -0800 (PST) X-Gm-Message-State: AOJu0YwxJlLaCZ43jgTa5oyD58MhZBQeOXxs1+ocwd0WbHTQ/RwuUFYl RiIvN4bJs0GKhHEPNRlwsogUe+NNpojDlWM4GC3u1fHK2TUJtJ6226njlsISCDGBwu+mZ10UxAN tI8gTcC9cd+WD9GBlGI8qppI+o+J9ZJ4LWCjY X-Received: by 2002:a05:6e02:1d04:b0:363:b0fb:322 with SMTP id i4-20020a056e021d0400b00363b0fb0322mr6273507ila.0.1707285185861; Tue, 06 Feb 2024 21:53:05 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240207033857.3820921-1-chengming.zhou@linux.dev> In-Reply-To: From: Chris Li Date: Tue, 6 Feb 2024 21:52:54 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] mm/zswap: invalidate old entry when store fail or !zswap_enabled To: Yosry Ahmed Cc: chengming.zhou@linux.dev, hannes@cmpxchg.org, nphamcs@gmail.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chengming Zhou , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 6, 2024 at 9:46=E2=80=AFPM Yosry Ahmed = wrote: > > > > @@ -1608,14 +1598,12 @@ bool zswap_store(struct folio *folio) > > > /* map */ > > > spin_lock(&tree->lock); > > > /* > > > - * A duplicate entry should have been removed at the beginnin= g of this > > > - * function. Since the swap entry should be pinned, if a dupl= icate is > > > - * found again here it means that something went wrong in the= swap > > > - * cache. > > > + * The folio may have been dirtied again, invalidate the > > > + * possibly stale entry before inserting the new entry. > > > */ > > > - while (zswap_rb_insert(&tree->rbroot, entry, &dupentry) =3D= =3D -EEXIST) { > > > - WARN_ON(1); > > > + if (zswap_rb_insert(&tree->rbroot, entry, &dupentry) =3D=3D -= EEXIST) { > > > zswap_invalidate_entry(tree, dupentry); > > > + VM_WARN_ON(zswap_rb_insert(&tree->rbroot, entry, &dup= entry)); > > > > It seems there is only one path called zswap_rb_insert() and there is > > no loop to repeat the insert any more. Can we have the > > zswap_rb_insert() install the entry and return the dupentry? We can > > still just call zswap_invalidate_entry() on the duplicate. The mapping > > of the dupentry has been removed when zswap_rb_insert() returns. That > > will save a repeat lookup on the duplicate case. > > After this change, the zswap_rb_insert() will map to the xarray > > xa_store() pretty nicely. > > I brought this up in v1 [1]. We agreed to leave it as-is for now since > we expect the xarray conversion soon-ish. No need to update > zswap_rb_insert() only to replace it with xa_store() later anyway. > > [1] https://lore.kernel.org/lkml/ZcFne336KJdbrvvS@google.com/ > Ah, thanks for the pointer. I miss your earlier reply. Acked-by: Chris Li Chris