Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1383002rdd; Wed, 10 Jan 2024 18:57:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEx54kOeEh+dHsQ6/peqACh/VwQaXVIjVolPnfd7DlUtH/bz5Wd2GwO4SV9ImjLMfXSCPYa X-Received: by 2002:a2e:3519:0:b0:2cd:660d:e481 with SMTP id z25-20020a2e3519000000b002cd660de481mr252499ljz.38.1704941863013; Wed, 10 Jan 2024 18:57:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704941862; cv=none; d=google.com; s=arc-20160816; b=0M1NYIaNV4xqAwWL6Qav94e4SpT2jxfFQ9W+TDuP4/oEkxMmq6YU4LoQJQrgwPMMQF KfcFkrQmsp4CH3YiC5J/R0AnYxbdWPf4J3K04HrYy4+cpNwO/Mjn+cq4VWSjKw8f29FD 29KxtZg7UUJHA9xq0Vqb01emNDoDeFLQm8DyswFM3Wfv/uufWyGeFa2NE7X/lJV0DU7s OQ9R23pa6fWafk5ApDnGLUa1+bAY1cHOPnd/C7y0m4vi3O49n/r3FDrFBjamCL+4O3hU lCq0qlNaGxo4r4rY1aeZ2X8NTBiHqsohPsJBAPDzHiW75XaQ2+S9aFqSHMqd2TphKAMA 2ZEg== ARC-Message-Signature: i=1; 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=OC4cmgp9pWBEGhOBagPxmTGQibwekEdPdcD5cLk/TkM=; fh=VPjeaWhTK56LdsfZXUJikOHefBMdya0wizbeYqGe8V8=; b=HJpnKKbhJ4W0QromTrnwwxMnGsGCknyK1rZsoI3NNJs+cEwk546M/U7Y1/Eei0UZt2 dwzAonsV6uCs0eOftd3uwqFwfy5tUn6zpJkv0aD0vPMACk+bmG+4HZP+eQanRLE/uRgi DLeVi07KrEZ8tW2YWcPzpqlhLxBgvjXqaJUFxGLmT8z8uOoRllVNnsGW2Fb3ibcwc1Zq c7Hz5pb2hKkH06yvzI1qCa88Bz9/CBpxClPNGXF9p7BnGlG4vcS5llDhYLz5ndURIW1H hIRoLqoXqoAVlr2/8oT/VXAM4VX8JwPRTbjxSFKNRIddtabX6Z3NfbBP5EYPMOZdsUgX d6zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=hmrDv3f+; spf=pass (google.com: domain of linux-kernel+bounces-23002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23002-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bf14-20020a0564021a4e00b0055829fda74fsi77341edb.652.2024.01.10.18.57.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 18:57:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=hmrDv3f+; spf=pass (google.com: domain of linux-kernel+bounces-23002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23002-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id BBA261F22DB9 for ; Thu, 11 Jan 2024 02:57:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 310658C0F; Thu, 11 Jan 2024 02:57:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="hmrDv3f+" Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BFF779E5 for ; Thu, 11 Jan 2024 02:57:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-50eabfac2b7so5416616e87.0 for ; Wed, 10 Jan 2024 18:57:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1704941833; x=1705546633; darn=vger.kernel.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=OC4cmgp9pWBEGhOBagPxmTGQibwekEdPdcD5cLk/TkM=; b=hmrDv3f+KJgtkmPHbLGFCU+jQAyNAYZvM7JwzCXH2jCU5yvHaTnsA5F5L/KjC09QmE g4LohI/+r7kIXG+2NwQrG6wGsRPDhTr+UQZAsCxsU/2XwAISYcV0rQlNh0pr4F20TPFN /+Y73EzQiMmWIkfjylGAUAtLEXM+SaXOSg3eDeoFGjzqiXaqr/A35bYYT0GQrk6+hV35 6GBWFRCXT/DIaauzHjhVx/MBInwi1IdXF+/Gwwjy6hXv9e+P7530AvFoBQyuuWTx7Gtt 92xRrtHZaBr8IwFZiIOL/OjzIipcKCzdd5iRFueN3JqDu0+mXuod61be+XfGI4U1lB5S 1qtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704941833; x=1705546633; 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=OC4cmgp9pWBEGhOBagPxmTGQibwekEdPdcD5cLk/TkM=; b=L5XE2SWN5JLFKoBR2+hEgUmeCROLSYeEAOvbcacfPbn2M29SyoAUYVj+yBHjGU5ua4 eylF+LEtYw01oAs+SmVs7adKznKBsuiAuU5vGSiCzfLdo0Ql9E6SwhUwWAp7Cq9H2DIA gPIKLNV8VSX2B6eyO/Gk5PxbyWKZTEeTNfiQBoZTpcHbk3zY3kQxz/BlXkVoX2JJHeyP 494E00Pz8JA0FqRk/CAAN5GHqOTFAW3Wuae5VMdqtbwU1DYyZwO3ngwRzEjq70Qhy6KH 2kaHcM6Pbnd9iNygyz17ac9Kf6lZC9fc//RYZQenw2wtbidioOUDYc2/hcXTqFReHgb1 gi9A== X-Gm-Message-State: AOJu0YyzXUAlGQei11rCA1Pv851QfnxFnLVUCYyGVgBdFdivMqAFXE7J rjtmMFa25v0wE8VcD0aa7tjsisu6f7NFFEWfZuOFmhDTQdlYN62JGbJVhvEIIeGRTQ== X-Received: by 2002:a19:ad4b:0:b0:50e:dc99:b9d4 with SMTP id s11-20020a19ad4b000000b0050edc99b9d4mr148314lfd.44.1704941833114; Wed, 10 Jan 2024 18:57:13 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231024142706.195517-1-hezhongkun.hzk@bytedance.com> In-Reply-To: From: Zhongkun He Date: Thu, 11 Jan 2024 10:57:00 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] mm: zswap: fix the lack of page lru flag in zswap_writeback_entry To: Yosry Ahmed Cc: Nhat Pham , akpm@linux-foundation.org, hannes@cmpxchg.org, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Li , weijie.yang@samsung.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 10, 2024 at 12:30=E2=80=AFAM Yosry Ahmed wrote: > > On Mon, Jan 8, 2024 at 7:13=E2=80=AFPM Zhongkun He wrote: > > > > Hi Yosry, glad to hear from you and happy new year! > > > > > Sorry for being late to the party. It seems to me that all of this > > > hassle can be avoided if lru_add_fn() did the right thing in this cas= e > > > and added the folio to the tail of the lru directly. I am no expert i= n > > > how the page flags work here, but it seems like we can do something > > > like this in lru_add_fn(): > > > > > > if (folio_test_reclaim(folio)) > > > lruvec_add_folio_tail(lruvec, folio); > > > else > > > lruvec_add_folio(lruvec, folio); > > > > > > I think the main problem with this is that PG_reclaim is an alias to > > > PG_readahead, so readahead pages will also go to the tail of the lru, > > > which is probably not good. > > > > Agree with you=EF=BC=8C I will try it. > > +Matthew Wilcox > > I think we need to figure out if it's okay to do this first, because > it will affect pages with PG_readahead as well. Yes, I've tested it and there is one more thing that needs to be modified. + if (folio_test_reclaim(folio)) + lruvec_add_folio_tail(lruvec, folio); + else + lruvec_add_folio(lruvec, folio); @@ -1583,10 +1583,8 @@ void folio_end_writeback(struct folio *folio) * a gain to justify taking an atomic operation penalty at the * end of every folio writeback. */ - if (folio_test_reclaim(folio)) { + if (folio_test_reclaim(folio) && folio_rotate_reclaimable(folio)) folio_clear_reclaim(folio); - folio_rotate_reclaimable(folio); - } -void folio_rotate_reclaimable(struct folio *folio) +bool folio_rotate_reclaimable(struct folio *folio) { if (success=EF=BC=89 + return true; } + return false; } > > > > > > > > > A more intrusive alternative is to introduce a folio_lru_add_tail() > > > variant that always adds pages to the tail, and optionally call that > > > from __read_swap_cache_async() instead of folio_lru_add() based on a > > > new boolean argument. The zswap code can set that boolean argument > > > during writeback to make sure newly allocated folios are always added > > > to the tail of the lru. > > > > I have the same idea and also find it intrusive. I think the first solu= tion > > is very good and I will try it. If it works, I will send the next versi= on. > > One way to avoid introducing folio_lru_add_tail() and blumping a > boolean from zswap is to have a per-task context (similar to > memalloc_nofs_save()), that makes folio_add_lru() automatically add > folios to the tail of the LRU. I am not sure if this is an acceptable > approach though in terms of per-task flags and such. I got it.