Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1655110rdb; Thu, 25 Jan 2024 02:06:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWYTAgvTbpK05GgUqNVQUwL1FLRmAiWmlXGaCmwOmdacw1m1WQ4Cxwk0lWfTYg4aieAnir X-Received: by 2002:a17:906:2303:b0:a2e:ad24:da8 with SMTP id l3-20020a170906230300b00a2ead240da8mr236142eja.19.1706177209381; Thu, 25 Jan 2024 02:06:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706177209; cv=pass; d=google.com; s=arc-20160816; b=Muftw3H9yYWf+OCQmRWHILWfE225dpOco1rrD2Tcm91amDSMTAvJqyZJCJ4W+CEoTd w6n8dqIqOHjJH8gvyT9ZXBVvnSbBI1HsuP7AqdkoLK7+JWewWXaL6ECMNQDVq6Hdz4c6 mYBTslZ+1xSnUFR0jMTsS64ybrfcgOIQ8MDcZzrBkNTJoIwjOspSk+/K3ieZBqi/mLqh l9IQJ9Q5dz+D9jdHBMt7iQ70L9tn19BPtxEsH2E4uhJrjugwLJKTkohM0vZHEa/OXv41 Z8t49OqUQuN6D3Swgdbc7PPnTqwGJU9fh12rPi0ngWnZhe5TCrsBziJJ8oQH8F7Vanak fqBw== 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=jxu9V88yZ4UG+aRX+313RxWb5ML+i/iwlaR54KeMD+s=; fh=kvnKAmCovA7pS/80Rp12B1K9+eX8ESrIScut0060G28=; b=wM5PEFpZTPs2isYQpuFDZYrRNAQr70/TD/scRbpaZQ/vmS9Sk5m247kPmu8w9Z80RS rL2N5b+QxxeLBTM6xf55ZY6+jtFbv5ibOmdFbUMcu2tiTwGnALt9LJ1clA10JCKFa5OO QkSGpyO1fV0dwn+f+1GZvNA9PD1vNL1i+ycJq5eWVfVYAzNPZ806VQjUj/l1VdDFH0tM CirPtBTwq5DANJu8BROOe8NTMM/oHD7TyvVCWUIE3oJM3ZenFOGgcUpVTvDUQQE4Qdln VIl67QXrcBeoaEy6vd5NC8nYxlgqV3nAwbG3JvlWH4Dyu6K7DBFLokPbL/RmVKCIOGAl WqBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2RdueRfj; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-38255-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38255-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b22-20020a170906d11600b00a319215d486si170367ejz.716.2024.01.25.02.06.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 02:06:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38255-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2RdueRfj; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-38255-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38255-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 74DC31F2C558 for ; Thu, 25 Jan 2024 09:27:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A524C1BC5E; Thu, 25 Jan 2024 09:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2RdueRfj" Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.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 289771BC3E for ; Thu, 25 Jan 2024 09:27:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706174855; cv=none; b=QJ4CuUwVX4mRawo4JzyG5mIGWk6Da4wWHcKYFKeXd/8X0R4TD5jEo3j2ydFaRknSqSlCqCM8bC7/ptsDy2V4AMBzwP9/V1NyaY8Zyb/sEEFsv1ndZfYDG5SW645UCqgnDuYYQ8Dok0q7Uzwltnvw5oN20y/aXk8zL/YDPpPYXbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706174855; c=relaxed/simple; bh=jxu9V88yZ4UG+aRX+313RxWb5ML+i/iwlaR54KeMD+s=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=qbmUMtvbLUwjAIohB0P+y7T5RtqVXG/UWueL7vgSFRWjSNay6/q6lVZoto14xa0i3+77KYDoOmZiTEOVW6NbLP0ZXCcYp3QPcsLUP9pJMVbEmJP1EkrjNwWhArm/dItJIb6x/aIjtO3eGZ0hDBn62DhoheDgfK/grWq9XG9LtM0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2RdueRfj; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a30b3a9e9c6so351542866b.2 for ; Thu, 25 Jan 2024 01:27:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706174852; x=1706779652; 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=jxu9V88yZ4UG+aRX+313RxWb5ML+i/iwlaR54KeMD+s=; b=2RdueRfj+ygV1uHTW+ycrqr2NObDygr5/nJmTxoRqCwlNNn49fQhrA35+b1d+2qNvS HJSdrbTErPq/TLmhXB22+9MxVvIdanOxihqQnmdsBDsjBIsSXK6UwHgLgTzP1wEw4xFz 4cpvVSLgYMXITMol0lZhW0fHLhEyT23GRhJJ0BaafByTh1QI3cqKTc+Ubt7R4/OdMVxo 0jgsNL56y5soz4I2wvymoWdSU8e9YI0JNs1cLcPJmLOJwwlmmTEGSSW4HONqEAK6+7oK AwsYRpZn7xPLdLkbb6n7UTrploKzdaJdpl2ewJfmKg9pgn1aUezRFwcGHHkWj8Jkcqoz /zzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706174852; x=1706779652; 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=jxu9V88yZ4UG+aRX+313RxWb5ML+i/iwlaR54KeMD+s=; b=pj6OaON1AChr4nxOcKe7c252MKSR1t6JS0t4NraFPZ61Yn+SKNxSDY8A8/nnDkmqcL zjvwey68B4BusbXfneNmEvNoDEhgZRGsyWIwei38QdFmMZjiZEmz6A0IpYIZ1IzpeF78 pc6UpbDKq55ry9KETmO/cBxAlS9Ak/B2/JsJZzJIuFXIZww3vpOx5cEYwXzHR2zCfDn4 DsioGmhPF+/cL/Dq8g6qC0tvSrgqJTcLtFr9qk61ltqDEARu/aMMsvVH5RUTNeUmRAQU c/URzI0p8TUkW982TbiMwg4rB26V3mMbyc0ZXgbHlgcZJBMlOl4lemZYnXGUldY1rPVG /l5A== X-Gm-Message-State: AOJu0Yzwn0MitLONesuAD9pvsWyrLkq/zNGKPMH+PtrRYMqoxsphUGbr 4f9iObor3hF3r7aJC3S1nFiCJDGjrBhcqXidZV0oMIQ6gaa9Jnd+rjdXNmMKbjk0HZqGamPVQG2 jhV8szXUx79Wx2umGYS3khh+W8z42Q5t0uGjY4jtmk7qCtZ12Wz16 X-Received: by 2002:a17:906:c056:b0:a30:deb6:1bb7 with SMTP id bm22-20020a170906c05600b00a30deb61bb7mr211283ejb.132.1706174852166; Thu, 25 Jan 2024 01:27:32 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240120024007.2850671-1-yosryahmed@google.com> <20240120024007.2850671-3-yosryahmed@google.com> <20240122201906.GA1567330@cmpxchg.org> <20240123153851.GA1745986@cmpxchg.org> <20240123201234.GC1745986@cmpxchg.org> <1496dce3-a4bb-4ccf-92d6-701a45b67da3@bytedance.com> <35c3b0e5-a5eb-44b2-aa7d-3167f4603c73@bytedance.com> <1a8a513f-fa84-41ca-b7f4-62726e78fd31@bytedance.com> In-Reply-To: <1a8a513f-fa84-41ca-b7f4-62726e78fd31@bytedance.com> From: Yosry Ahmed Date: Thu, 25 Jan 2024 01:26:56 -0800 Message-ID: Subject: Re: [PATCH 2/2] mm: zswap: remove unnecessary tree cleanups in zswap_swapoff() To: Chengming Zhou Cc: Johannes Weiner , Andrew Morton , Nhat Pham , Chris Li , Huang Ying , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 25, 2024 at 1:22=E2=80=AFAM Chengming Zhou wrote: > > On 2024/1/25 17:03, Yosry Ahmed wrote: > >>>>>> The second difference is the handling of lru entry, which is easy = that we > >>>>>> just zswap_lru_del() in tree lock. > >>>>> > >>>>> Why do we need zswap_lru_del() at all? We should have already isola= ted > >>>>> the entry at that point IIUC. > >>>> > >>>> I was thinking how to handle the "zswap_lru_putback()" if not writeb= ack, > >>>> in which case we can't use the entry actually since we haven't got r= eference > >>>> of it. So we can don't isolate at the entry, and only zswap_lru_del(= ) when > >>>> we are going to writeback actually. > >>> > >>> Why not just call zswap_lru_putback() before we unlock the folio? > >> > >> When early return because __read_swap_cache_async() return NULL or !fo= lio_was_allocated, > >> we don't have a locked folio yet. The entry maybe invalidated and free= d concurrently. > > > > Oh, that path, right. > > > > If we don't isolate the entry straightaway, concurrent reclaimers will > > see the same entry, call __read_swap_cache_async(), find the folio > > already in the swapcache and stop shrinking. This is because usually > > this means we are racing with swapin and hitting the warmer part of > > the zswap LRU. > > > > I am not sure if this would matter in practice, maybe Nhat knows > > better. Perhaps we can rotate the entry in the LRU before calling > > __read_swap_cache_async() to minimize the chances of such a race? Or > > we can serialize the calls to __read_swap_cache_async() but this may > > be an overkill. > > Also, not sure, rotate the entry maybe good IMHO since we will zswap_lru_= del() > once we checked the invalidate race. Not sure what you mean. If we rotate first, we won't have anything to do in the failure case (if the folio is not locked). We will have to do zswap_lru_del() if actually writeback, yes, but in this case no synchronization is needed because the folio is locked, right?