Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp141978rdh; Mon, 18 Dec 2023 06:43:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFD5QIMF0n3Qvt7yINg/pAXDBemcr+vRwm9Y7hOTd7iJVLkJ4cs0c0uB4b7oCAIDoVW8DBm X-Received: by 2002:a17:902:bd0c:b0:1d0:a9fa:5939 with SMTP id p12-20020a170902bd0c00b001d0a9fa5939mr6564408pls.111.1702910613892; Mon, 18 Dec 2023 06:43:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702910613; cv=none; d=google.com; s=arc-20160816; b=BuGcTSyh4V3G6F460gCfzR+PmxespJmEmFSyvS2U0vGm8J1DdFgK+AMrKLWVZ3po6Y EAy+wIL6MV03b7OrL/dVZsAuMFJ4AbVkiRONd21022lJioc8NKVZG3fM/xIAW/+eDCO8 7RIjCcD9Zb1ac2OlYxL52Kz53cNZppn46ErQdoVkB2nFt1T/P5PWF7CoMDL9gP0/9Fuc pwWdnHMTVifkps39HwlnLImpEZn29A+qdxu97UakRBJdKmMngiVXfUXUY+XjMTbj6DCs kPah63eyRlCaq0Zj3ErjUuDVciSsEhQSTxsSIRgjEoC4wPErciKWbFCH3EXapC1C/MZ4 crvw== 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=0pTaPp82Aa5VZmUHLjVfWpth1QdXOXHq0YobrMTPaUg=; fh=CX+uLh97bCEQz9TIBXMYjW+THKgU42vhH6SVd7qHTP8=; b=h6zLm56wZ1+narkHfbbHm/0Ggy0t3uurW228/DSCkINU/s6wNGrZTqxAZ0OJDtUS5x KMLwRgZRMzXj3aAbUK/3tAAPjf0PTb9S2GscctW10Bv0CSCvXwOmhfZUsVnQNEvuZDZd 2GOPo2mVwp+gOnURRlGRJV9pjW07Q9wFZZIek8ZhDIX/rMiMa//o9u3Me9hM6ymvA6Vp UFBuv6eZcfvonG9twpCillBzih/J/L2+RJERkSiLVwrnoC4eNj1bt1stn9OeXGxG7lhV bFO+dfrVExLTRDaV7f7SEF8tLpxbM7IlP9FWa8faz+rDm6dfWQb0ZUGYZJta4L1rNAGJ F1hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="tF/ZkDce"; spf=pass (google.com: domain of linux-kernel+bounces-3847-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3847-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c18-20020a170903235200b001d08a8c56a7si11521993plh.279.2023.12.18.06.43.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 06:43:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3847-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=@google.com header.s=20230601 header.b="tF/ZkDce"; spf=pass (google.com: domain of linux-kernel+bounces-3847-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3847-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 152C9B22B64 for ; Mon, 18 Dec 2023 14:40:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0DD937860; Mon, 18 Dec 2023 14:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tF/ZkDce" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 84CDA200C0 for ; Mon, 18 Dec 2023 14:39:53 +0000 (UTC) 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-f44.google.com with SMTP id a640c23a62f3a-a2356bb40e3so95067766b.1 for ; Mon, 18 Dec 2023 06:39:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702910392; x=1703515192; 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=0pTaPp82Aa5VZmUHLjVfWpth1QdXOXHq0YobrMTPaUg=; b=tF/ZkDceha8LK/6OvLLlhyrHVEOXJEcS0DaYFsoEE0SEuxGUuA8Z0COlkBTsLoy+Mr IwelOXhWZqlHD7xq3ToJFnTR2Z/vzlnQYcshkmk14Wg9CxofTX8i2UL8BdCVXz0eZ05S XF7Js10wYruR8gGRsruAUmULIfi4tvbaI4HrLrBUdrlG6ijsYbcLsZlVu6ccgq0LpPxm N2xFlbCnYp+zliaLeqvmmTDuwdqiVJEsrstiFNmYrsNhUAhTP69lPl3c5VCm+LcRXj8c YCDgpURPMFUFxfo287S31LIsd+VgUzFCEnux/0AaA2eva3LFpVPSxIhFKhsbzPmcevRS 7AZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702910392; x=1703515192; 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=0pTaPp82Aa5VZmUHLjVfWpth1QdXOXHq0YobrMTPaUg=; b=udRuTKgfOBTG/kHV9/UTNByfEAWNvI2XCWPyVGubo5ajqDU7IY0RSazxUtzqT6RpC1 jNPVSNCzl/EafcVkChTTHBpyZV9Z0ZpJGrZNK+AID+bdch9G8XD0x9z5g+eXEfj6unZ+ 4g+deJMyvk5Gwm9LQlKaWFBxRUXehUPOXdZoGWMDTGhzQF98EqTXfA4jWkrhKQJT8a5s 4pAor5KEzh4SftY0Qi2oYZky4D4pBi7EzMOaQ6z7wjU+pW+HC/AZLBGNshl5+dFFOCD4 OcYe58yiLad7o0ZxF74i87YFxUMCJsjBFGh2PZFdBdFTP8h3w8YQiS1ZFkLb3HGQa+QZ 8mVw== X-Gm-Message-State: AOJu0YwEDQ52lNkZ2FLTIYrDW0p0F/gZnRaoHnUQY0XJS4I/16KN482T s/PXNRIpegnkno8SqieNWKG0661gQdkL23SKvmAXNg== X-Received: by 2002:a17:906:6847:b0:a23:5412:c4a5 with SMTP id a7-20020a170906684700b00a235412c4a5mr1280318ejs.61.1702910391612; Mon, 18 Dec 2023 06:39:51 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> <20231213-zswap-dstmem-v1-5-896763369d04@bytedance.com> <20231214142320.f5cf319e619dbb2127c423e9@linux-foundation.org> <20231218140313.GA19167@cmpxchg.org> In-Reply-To: <20231218140313.GA19167@cmpxchg.org> From: Yosry Ahmed Date: Mon, 18 Dec 2023 06:39:13 -0800 Message-ID: Subject: Re: [PATCH 5/5] mm/zswap: cleanup zswap_reclaim_entry() To: Johannes Weiner Cc: Andrew Morton , Chengming Zhou , Nhat Pham , Chris Li , Seth Jennings , Dan Streetman , Vitaly Wool , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 18, 2023 at 6:03=E2=80=AFAM Johannes Weiner wrote: > > On Thu, Dec 14, 2023 at 02:41:26PM -0800, Yosry Ahmed wrote: > > On Thu, Dec 14, 2023 at 2:23=E2=80=AFPM Andrew Morton wrote: > > > > > > On Wed, 13 Dec 2023 17:02:25 -0800 Yosry Ahmed wrote: > > > > > > > On Tue, Dec 12, 2023 at 8:18=E2=80=AFPM Chengming Zhou > > > > wrote: > > > > > > > > > > Also after the common decompress part goes to __zswap_load(), we = can > > > > > cleanup the zswap_reclaim_entry() a little. > > > > > > > > I think you mean zswap_writeback_entry(), same for the commit title= . > > > > > > I updated my copy of the changelog, thanks. > > > > > > > > - /* > > > > > - * If we get here because the page is already in swapcach= e, a > > > > > - * load may be happening concurrently. It is safe and oka= y to > > > > > - * not free the entry. It is also okay to return !0. > > > > > - */ > > > > > > > > This comment should be moved above the failure check of > > > > __read_swap_cache_async() above, not completely removed. > > > > > > This? > > > > Yes, thanks a lot. Although I think a new version is needed anyway to > > address other comments. > > > > > > > > --- a/mm/zswap.c~mm-zswap-cleanup-zswap_reclaim_entry-fix > > > +++ a/mm/zswap.c > > > @@ -1457,8 +1457,14 @@ static int zswap_writeback_entry(struct > > > mpol =3D get_task_policy(current); > > > page =3D __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, > > > NO_INTERLEAVE_INDEX, &page_was_alloca= ted, true); > > > - if (!page) > > > + if (!page) { > > > + /* > > > + * If we get here because the page is already in swap= cache, a > > > + * load may be happening concurrently. It is safe and= okay to > > > + * not free the entry. It is also okay to return !0. > > > + */ > > > return -ENOMEM; > > > + } > > > > > > /* Found an existing page, we raced with load/swapin */ > > > if (!page_was_allocated) { > > That's the wrong branch, no? > > !page -> -ENOMEM > > page && !page_was_allocated -> already in swapcache Ah yes, my bad. > > Personally, I don't really get the comment. What does it mean that > it's "okay" not to free the entry? There is a put, which may or may > not free the entry if somebody else is using it. Is it explaining how > lifetime works for refcounted objects? I'm similarly confused by the > "it's okay" to return non-zero. What is that trying to convey? > > Deletion seemed like the right choice here, IMO ;) It's not the clearest of comments for sure. I think it is just trying to say that it is okay not to write back the entry from zswap and to fail, because the caller will just try another page. I did not like silently deleting the comment during the refactoring. How about rewriting it to something like: /* * If we get here because the page is already in the swapcache, a * load may be happening concurrently. Skip this page, the caller * will move on to a different page. */