Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1022437rwd; Wed, 7 Jun 2023 09:53:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SO2B14EMr7X+tPhYCiNRJZC1ZOf71ij2ZEsA8XhUPSYlu9a7TzzzkqoLby/1/Rh129tAN X-Received: by 2002:a05:6a21:118f:b0:10f:3fa0:fd78 with SMTP id oj15-20020a056a21118f00b0010f3fa0fd78mr3884004pzb.24.1686156839372; Wed, 07 Jun 2023 09:53:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686156839; cv=none; d=google.com; s=arc-20160816; b=KPsdJ+uhgnZLdAqrldgws2KqKTsqkBTzkT4dIocB5wAPGbQnK8TNmG6yXA0/4FnODA F5AzVh9gPVynEhSDzC84g4uA0d3oWS6L3uU2nxOdx2fZX1IKeZQPZ/o/5e0QUurMI4Qk KRC1G5FZ2ynPsVDa9F9vFLSiPkLirbhySfvPPIRrDbfmF0hzQkPYyZkYWapK5SVntsbj WzH/4KAaYt6qDfcB2PH65Macr1m8RPj0b+H6Q2G6s/DCVSWT38aQtasuX1rQCl6JFYY/ xLEsqCLLuerrvcSYOwz+5QT9mxaDfxwbyMx52fg//g2CZFaCDpISqyoXpK+58sLyIWe5 ZmfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=nST2Md/+Z3od5CZcws3W9bn9v93QD0AgAvtu6ztY8xg=; b=s3DVymf4Rp+zJlcrbTWcYd/rFxwOdDhRRux+qqpWmpBMj5erJJTcXJNuuYadXShnX1 XI/z9fQpjBt99D/FfRX3bB697N35LmIxoZ07p0XIQ+d69EYqnxVemwcEVn83Tew5VPLs UoArmKtbpoeB0TtD20Sdgs+2uJNYPTDTD2om3OJLwsYFILRVD63mgO5N1Y66VVq1SoDo +wKhIUJ9VeWBuOCIv7k+Rd5Dg2QYvW0un6lVUjBRTuvyOzAhStjttq8f1ZeEpiYamPr7 2t4QhQO7nipvZwLOdHsPBDZowaym3F3qcVarwhOru7K1p7DJLV8i2uvFgpNclmEggf3x Nfcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=UegRLrvz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a198-20020a621acf000000b0064cf289a2d8si8983036pfa.127.2023.06.07.09.53.47; Wed, 07 Jun 2023 09:53:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=UegRLrvz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbjFGQeP (ORCPT + 99 others); Wed, 7 Jun 2023 12:34:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjFGQeO (ORCPT ); Wed, 7 Jun 2023 12:34:14 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08240196 for ; Wed, 7 Jun 2023 09:34:13 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-51458e3af68so1785853a12.2 for ; Wed, 07 Jun 2023 09:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686155651; x=1688747651; 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=nST2Md/+Z3od5CZcws3W9bn9v93QD0AgAvtu6ztY8xg=; b=UegRLrvz05yeGz6eWmz77+FqJutZvBeIx1d8R4Akm/4pOMNflRnR59fho+CdTVWuMu 4DRnzeaxtLloI8NJy0SrLVsbgAEoq3PCs7WdwcCbRZ5zeoxg8VdieX/WN2SP3qO+7qnO grQeVqgqDBajpLERfIWSVSXaNKMOtJXK5V2al4qRVbbDz7UK0yoaK9l24aXxh/u8+3Vp XXW1GPpj8vziNQ6o8hf9nVVRxxbC1tXWz1g/Mk3AOCRy6NSmMR/EoR5DPEuLBU0otqFk /2ABQI64lxmWOIH18Vt22Vz2LLBc/wA5+/k/8Gxz4DGS5XRApcgwHZ79RS1ZozpLz/nJ Jp1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686155651; x=1688747651; 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=nST2Md/+Z3od5CZcws3W9bn9v93QD0AgAvtu6ztY8xg=; b=huYx0WeRBBTBqU4PhcVaEsNeZYVcB38q3czxuqp5P0p5+nLtyjbfZsYrTlTLp24rRr xuECPzo7EGjuNQqyd3dzP0/p1JkluwBy0wwgi+hGprTLLG7HSGi2voohceyLK+gZAp03 6ZKsMO7MHG9pV2eDdaueE1+VGTYaf9itapBll3bcysHZSQO3tjudk56Y3UQtKZH3pezO 9jFSNyl2Jqz0RpRDNBVl1KBXiJmIwsbQWJo0Zr+nxhLUy2W0QCV09+kpwzUOfKxhEmDj 6EAbafHwaNoIEJzwuymPPCKiFMCaD53p78oRPX6TJeRfDrPw7eMWuawgdEiGXB1QL7cu bolQ== X-Gm-Message-State: AC+VfDw0VOb00Bl4mEhtHPFZhr6/mwFtHeIzrbK+0HPm3Zs0ZZ6Pq5QZ wUbNRJ2nbPDUd0qkIVwns9ezeLI3QzTksx+GLaG5PA== X-Received: by 2002:a17:907:6e25:b0:94f:2d5f:6949 with SMTP id sd37-20020a1709076e2500b0094f2d5f6949mr6223367ejc.42.1686155651187; Wed, 07 Jun 2023 09:34:11 -0700 (PDT) MIME-Version: 1.0 References: <20230530210251.493194-1-yosryahmed@google.com> <20230607141357.GA338934@cmpxchg.org> In-Reply-To: <20230607141357.GA338934@cmpxchg.org> From: Yosry Ahmed Date: Wed, 7 Jun 2023 09:33:34 -0700 Message-ID: Subject: Re: [PATCH] mm: zswap: support exclusive loads To: Johannes Weiner Cc: Konrad Rzeszutek Wilk , Andrew Morton , Seth Jennings , Dan Streetman , Vitaly Wool , Nhat Pham , Domenico Cerasuolo , Yu Zhao , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 7, 2023 at 7:13=E2=80=AFAM Johannes Weiner = wrote: > > On Tue, May 30, 2023 at 09:02:51PM +0000, Yosry Ahmed wrote: > > @@ -46,6 +46,19 @@ config ZSWAP_DEFAULT_ON > > The selection made here can be overridden by using the kernel > > command line 'zswap.enabled=3D' option. > > > > +config ZSWAP_EXCLUSIVE_LOADS > > + bool "Invalidate zswap entries when pages are loaded" > > + depends on ZSWAP > > + help > > + If selected, when a page is loaded from zswap, the zswap entry = is > > + invalidated at once, as opposed to leaving it in zswap until th= e > > + swap entry is freed. > > + > > + This avoids having two copies of the same page in memory > > + (compressed and uncompressed) after faulting in a page from zsw= ap. > > + The cost is that if the page was never dirtied and needs to be > > + swapped out again, it will be re-compressed. > > + > > choice > > prompt "Default compressor" > > depends on ZSWAP > > diff --git a/mm/frontswap.c b/mm/frontswap.c > > index 279e55b4ed87..e5d6825110f4 100644 > > --- a/mm/frontswap.c > > +++ b/mm/frontswap.c > > @@ -216,8 +216,13 @@ int __frontswap_load(struct page *page) > > > > /* Try loading from each implementation, until one succeeds. */ > > ret =3D frontswap_ops->load(type, offset, page); > > - if (ret =3D=3D 0) > > + if (ret =3D=3D 0) { > > inc_frontswap_loads(); > > + if (frontswap_ops->exclusive_loads) { > > + SetPageDirty(page); > > + __frontswap_clear(sis, offset); > > + } > > + } > > return ret; > > This would be a much more accessible feature (distro kernels, > experimenting, adapting to different workloads) if it were runtime > switchable. > > That should be possible, right? As long as frontswap and zswap are > coordinated, this can be done on a per-entry basis: > > exclusive =3D READ_ONCE(frontswap_ops->exclusive_loads); > ret =3D frontswap_ops->load(type, offset, page, exclusive); > if (ret =3D=3D 0) { > if (exclusive) { > SetPageDirty(page); > __frontswap_clear(sis, offset); > } > } Sure, I can do that. My thought was that this isn't something that someone usually wants to change at runtime, but at least for experimentation, it does make things a lot easier. I can add a zswap module parameter. I am guessing for consistency with other zswap settings and for convenience, I can leave the config option to set the default value with, aka CONFIG_ZSWAP_EXCLUSIVE_LOADS_DEFAULT_ON or something. Does this make sense?