Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp33205lqp; Mon, 10 Jun 2024 17:11:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAC6UAAowvSSNwAeC7GKhzoOFV7nnfVRlaDHbXGNQYiWPG4/zhvOL8X6ZALHV6zMVSJXn26KiLk2Zbzkiwl6dCnfxnuMx53FGGaEOg6g== X-Google-Smtp-Source: AGHT+IFRjRvSsQU8a1Eft+3fBrpnRe/G5v1eXA0aD/pFLcf7NEXu8vyKjYolvaJ3tUCamcQ+dCaw X-Received: by 2002:a05:6a00:1911:b0:702:65de:19e5 with SMTP id d2e1a72fcca58-7040c765ad2mr12795527b3a.33.1718064696122; Mon, 10 Jun 2024 17:11:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718064696; cv=pass; d=google.com; s=arc-20160816; b=qxm40XXOwrlGIaGfOianMd8PLdXXXN1V36G+hPEKEAa4HMy2U9U1jq71BywpzrVnvs hi0Bjq0ol1OyuTAh3O7qnoZmqWfh0k+K8iN8gtXBoHZy/q/9ihsNmmQ0WjVAgY7+iHav droZgQhQX5nQIHGzkPfTpD+53ECd3RC8NHpeoHdS0xmMbmS0lWryngYgI4lVAMGYUIgm p4rT7FHMxzjgDvP2qjVuK2X0GrTeRIUIDHRdMNxXsIjk9y0+u7EXfbeD328roHBUHPwd bpESeCvx1ciBW1Js+YnTOOSl0G764p1Os95vb3JqbhNkZjUBz9WMzq0z0Krd50oFX2Ug KntQ== 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=n26t2+PmJ0hXBNFN+MS0jl8gQ+UB5BKKsd8smeb5Xfw=; fh=u/JCt6Jfkonitb8Yxse2ugMW4FetxmQ8HjUV5OygPLs=; b=f9k3hvuqB9otYBTp+wESr0U+ojPqvt+s0SUQgmk+wxpnpMPtiBdj8CtxAEVgsRaqmT sA8sG7SvlJ9eRtoUtyP3h++MJqjYew7nooG8KT4WyHC3CZ2ChgzJUP0XZfUEzRL1M1KL GJ/r4O3zycQB0ZLIY2LFjqlpCDmH1IMwPS4ppAh0THmsTLmiJu+a1DHdSlSYlk0yIVEn YwZ2GWdU2Zc3TkaC3XGC5K4TZa1v6hMBrrBwfLRYC86ZH3mwDjvt1KBlgOoNspJgNGLF gMFXqLrqTSd5wZUKwYuWIwlO4xAzc0IBlsU0s7hMZYm6lod3pCWv21fgkWlCgPQGaJqN lX1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VDdf4q2T; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-209108-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209108-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70420f42c18si4723809b3a.191.2024.06.10.17.11.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 17:11:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209108-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=@gmail.com header.s=20230601 header.b=VDdf4q2T; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-209108-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209108-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B9EB6284755 for ; Tue, 11 Jun 2024 00:11:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2F7017736; Tue, 11 Jun 2024 00:03:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VDdf4q2T" Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 2495C1173F for ; Tue, 11 Jun 2024 00:02:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718064179; cv=none; b=jwE30udNR2OESPjK11y7t65olBHkliVTjx9h2LjQwtWLcRjGRZRqea5A8f06VyFGV/MgS/qRTpDC9tPfsopYnHXbrvEURPVxj5FUzathZQFcGx8J0OJrnjw8zyLc0Dp3KEARQEsE4V4eC17hJc+YOnVFSJHAiba+Mf2p+XJ7QO8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718064179; c=relaxed/simple; bh=wb9ieqV0h0WivBtLqAOZwsq/1SKW15pq7lWIwad18Fo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=c8sP/Sj/fRline0BFUPe7MKCeNM660NPa/ERKRw3HRwUXxFmMP92b0iJAFJoGO7KtwiidQ0xM1T209Nv2eXOOEotjcJBSA84XX3WKfe0VXSXKI6osmcaUbvBDF7pZFannMVlzLy192czSotp5QJquk40PVTH0T3OwCIGvNEiEVU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VDdf4q2T; arc=none smtp.client-ip=209.85.219.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-dfa727d47c1so5168403276.0 for ; Mon, 10 Jun 2024 17:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718064177; x=1718668977; 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=n26t2+PmJ0hXBNFN+MS0jl8gQ+UB5BKKsd8smeb5Xfw=; b=VDdf4q2TZb5q+z6WtblmFuNi6QJaSOJQwGnvj0FjEf4g94MEbN+nwOFF6Y9DUXHkYu UARmRYeS5BByhONdwROd5JYgrNPLtnh5UTRxmIqnU6ghTSBrgrBYYoQVOj+NyNRwaq0R WfeI9TPhgxiVyli5Y31qNnfIQYPIKnGP3zRyBpvu1bYcOMfwhwC0V4pXEMku59oW+kxL zbgjZHEBvrsof4+ont9TIQ6Fgfja2Ggc9KeMUcz8xqGyytq1f8tzn3pnRq8EtcLqiP2F Gna6l+MTYUA1O72YfAiL81ndvdkZz4aKomqn9AmRBNEodX6p+QvZLidFnPARzXtos81b 4VbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718064177; x=1718668977; 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=n26t2+PmJ0hXBNFN+MS0jl8gQ+UB5BKKsd8smeb5Xfw=; b=vg6n100W9JbvrQGv5lQIV1qajo2lgmE9L7oanSiyHWarqXvDff5YwZLRGwypVojb0P rlCpb4SxkQ5JbLWQxlluyC3dUmDPRhPhcFgNJ3IUcjMamaKvGjBfmTay++F3f4n3UqNM f4gcqkG3dev/H6MoCotx2XdgR/H8mjRbdgBUuCkNYTVsX0WJ5N9jpXSjUhsoeyocRQG/ j3Fgon40XQfFX5YID+S+TSusayO3uRze+erSmgPCVQ3oIwMmsiPVTF1mDNLiXFIRh3+c DB1+veVYu/B3TiPTuuYfYKX/K7laSNBcoerYAKGOzHBrfTpTv8ULCL0Kwhol3fl1xx9G KgLA== X-Forwarded-Encrypted: i=1; AJvYcCUcq+DlowKQSJZu1YEKSyzO7KoRsFF+fxQWU0iiPJOmYwB4H6RehLu5nHLccZPYoYw+Qxl6ouNxjGls4GbuMyUu/8YhBLQn5nBY+3MZ X-Gm-Message-State: AOJu0Yxk2luUYAXWiDValtiEUdgwERkryKJ4QbLvluoOLOshz/Pbju9D zQHVaCnS0SHKcr8JV4980AAlxPHE+XgUuagMDvZxq8p1jZmsBcVV1YN6R5A+nOW+f6lcJv/rjaC iF1n7PGI6ZOjd52xAFjVO4VhlLAk= X-Received: by 2002:a25:8205:0:b0:de6:197b:ff89 with SMTP id 3f1490d57ef6-dfaf65f0993mr8935828276.64.1718064176831; Mon, 10 Jun 2024 17:02:56 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240608023654.3513385-1-yosryahmed@google.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Tue, 11 Jun 2024 12:02:45 +1200 Message-ID: Subject: Re: [PATCH v2] mm: zswap: handle incorrect attempts to load of large folios To: Yosry Ahmed Cc: Andrew Morton , Johannes Weiner , Nhat Pham , Chengming Zhou , Baolin Wang , Chris Li , Ryan Roberts , David Hildenbrand , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 11, 2024 at 11:41=E2=80=AFAM Yosry Ahmed wrote: > > [..] > > > > > We can't always WARN_ON for large folios, as this will fire even = if > > > > > zswap was never enabled. The alternative is tracking whether zswa= p was > > > > > ever enabled, and checking that instead of checking if any part o= f the > > > > > folio is in zswap. > > > > > > > > > > Basically replacing xa_find(..) with zswap_was_enabled(..) or som= ething. > > > > > > > > My point is that mm core should always fallback > > > > > > > > if (zswap_was_or_is_enabled()) > > > > goto fallback; > > > > > > > > till zswap fixes the issue. This is the only way to enable large fo= lios swap-in > > > > development before we fix zswap. > > > > > > I agree with this, I just want an extra fallback in zswap itself in > > > case something was missed during large folio swapin development (whic= h > > > can evidently happen). > > > > yes. then i feel we only need to warn_on the case mm-core fails to fall= back. > > > > I mean, only WARN_ON is_zswap_ever_enabled&&large folio. there is no > > need to do more. Before zswap brings up the large folio support, mm-cor= e > > will need is_zswap_ever_enabled() to do fallback. > > I don't have a problem with doing it this way instead of checking if > any part of the folio is in zswap. Such a check may be needed for core > MM to fallback to order-0 anyway, as we discussed. But I'd rather have > this as a static key since it will never be changed. right. This is better. > > Also, I still prefer we do not mark the folio as uptodate in this > case. It is one extra line of code to propagate the kernel warning to > userspace as well and make it much more noticeable. right. I have no objection to returning true and skipping mark uptodate. Just searching xa is not so useful as anyway, we have to either fallback in mm-core or bring up large folios in zswap. > > > > > > diff --git a/include/linux/zswap.h b/include/linux/zswap.h > > index 2a85b941db97..035e51ed89c4 100644 > > --- a/include/linux/zswap.h > > +++ b/include/linux/zswap.h > > @@ -36,6 +36,7 @@ void zswap_memcg_offline_cleanup(struct mem_cgroup *m= emcg); > > void zswap_lruvec_state_init(struct lruvec *lruvec); > > void zswap_folio_swapin(struct folio *folio); > > bool is_zswap_enabled(void); > > +bool is_zswap_ever_enabled(void); > > #else > > > > struct zswap_lruvec_state {}; > > @@ -65,6 +66,10 @@ static inline bool is_zswap_enabled(void) > > return false; > > } > > > > +static inline bool is_zswap_ever_enabled(void) > > +{ > > + return false; > > +} > > #endif > > > > #endif /* _LINUX_ZSWAP_H */ > > diff --git a/mm/zswap.c b/mm/zswap.c > > index b9b35ef86d9b..bf2da5d37e47 100644 > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -86,6 +86,9 @@ static int zswap_setup(void); > > static bool zswap_enabled =3D IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON); > > static int zswap_enabled_param_set(const char *, > > const struct kernel_param *); > > + > > +static bool zswap_ever_enable; > > + > > static const struct kernel_param_ops zswap_enabled_param_ops =3D { > > .set =3D zswap_enabled_param_set, > > .get =3D param_get_bool, > > @@ -136,6 +139,11 @@ bool is_zswap_enabled(void) > > return zswap_enabled; > > } > > > > +bool is_zswap_ever_enabled(void) > > +{ > > + return zswap_enabled || zswap_ever_enabled; > > +} > > + > > /********************************* > > * data structures > > **********************************/ > > @@ -1734,6 +1742,7 @@ static int zswap_setup(void) > > pr_info("loaded using pool %s/%s\n", pool->tfm_name, > > zpool_get_type(pool->zpools[0])); > > list_add(&pool->list, &zswap_pools); > > + zswap_ever_enabled =3D true; > > zswap_has_pool =3D true; > > } else { > > pr_err("pool creation failed\n"); > > Thanks Barry