Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp117756rdh; Mon, 18 Dec 2023 06:07:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOx59+AvCaWwA6mkxz3gkdcRFWjd2RMIkDSoAjrkBxgvmfDdp77FXxpqhVI2jQ9FKKTGnO X-Received: by 2002:a05:6a20:d42f:b0:190:53c1:fee2 with SMTP id il47-20020a056a20d42f00b0019053c1fee2mr17775641pzb.19.1702908438388; Mon, 18 Dec 2023 06:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702908438; cv=none; d=google.com; s=arc-20160816; b=L4WiniG6K6FEAqMQZn9mnajJw3qpLblmi/HAamUMuF2P9Sd28t1IZJdKLjwxCccuGf xo4ieBakeNrO0rA+Q++AzYPDetxA4SFJwwSUcTLLvWQzF120hDXXG0+1eysIj/oUOPtY yl9+UotepYA+dcJ77nbe0pbp+djQkKf+4jJkd73YyGa8O7ONXSNp1aFl2zLkWN/4Wnup 4JgRgQRnYFM5fjiL/1xYQ13aAr/aOL9l6rKtI0qA+tKeDXGWyPYYlt+1plz3nDxDaiqW F93I83v6nVu8umOXDsK3SDY5dU0VmzzMWOHWc42FoaJYe4tr8IM62t6hOgwR6wgMOLqm rjfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SeIfmjTD20WCr2YilJIxer8YjFa9qmpum3ZmpdpwHyc=; fh=IzyCheeqPuN0j6FaIbe+bnLPmWMkSXZtMFHnxQxbcbQ=; b=tgSTgNnNHujXGSptDdN37/Z9L7tKVBGYr+w6MYYvGp/s9dhgQFFXBc1tlMpjCVJnvT dkPzM2O6PVK367citz6C/sh0mlCyC1V8R2T3TUg0w39ENbI7fPY+h6QXsZ8RC/YyqXK4 5HScqv7jf1wa15IJGa7mAdJsNb9K+nwgG9imx2iQdg4IJ+f+ly1I6t0P4XpYm4x96g3Y rzw9vP5mHFRyWQiqTMxuxVmL7oeKuxaU5zKra+Yh4AddKZM1VM+TR7tDIotPvxDfiiG5 FeHjKyRkH9DgpnDITUxkYuy9tJ1fbUoRnrC7fTiZYbDB7sLqLu6cSEoW3kPAlAyaskGd SZMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=vnP0j8j3; spf=pass (google.com: domain of linux-kernel+bounces-3806-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3806-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j192-20020a638bc9000000b005cd8486d5ccsi3845602pge.65.2023.12.18.06.07.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 06:07:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3806-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=vnP0j8j3; spf=pass (google.com: domain of linux-kernel+bounces-3806-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3806-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org 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 283AD284070 for ; Mon, 18 Dec 2023 14:07:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6721E5BFA4; Mon, 18 Dec 2023 14:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="vnP0j8j3" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (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 6780F3788B for ; Mon, 18 Dec 2023 14:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-67f4a160dbbso3700146d6.0 for ; Mon, 18 Dec 2023 06:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1702908236; x=1703513036; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=SeIfmjTD20WCr2YilJIxer8YjFa9qmpum3ZmpdpwHyc=; b=vnP0j8j3nA2tDrIsLef6sAjUi4Y9BsScoIJWfnhWYmTm7v8A+GTgm5ao8qM3p982pl OevBvOeIcWRCMdSuTJ1I03LvFeh3gjr1xIRe1T/kb9XfpXKPrqMGzk0zr9VwDGrlLCx0 YutfYhef88SRi8mBINz3ceIFgruS6choYh+Jh8Lyf3GktjFkOwk7nGlQ0H5Ss62UG4Qj M8XFVX/doh+Y6pAwaek0Pfi4H8aI1+ruwSgsXhUXlp9r5T+83udpsuE8vYUEU+IkXfOG Y4MUay2l0UirW8mGdMyBkjB9eWH6UeL7A79rBizJactclhOxV/iupVjebOLo+E3HgZSR Y6QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702908236; x=1703513036; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SeIfmjTD20WCr2YilJIxer8YjFa9qmpum3ZmpdpwHyc=; b=k2jUgg8+fxu7TrdeubJNDyoaqwt/PALv/79iK6aQ1tW6ea5dpfn1v0m63MEUoWtjJn S/v8nhPABnPTelecyhOiKypatZw4hgUZcpONi0ZbzXyXo0FaXp/uQ0h296TmnX2wDb4S Uk7y8v9ZnFxFJEvbhtseoZHFr0jvjfWarTz++YmHnYUThRBfufnPU8lu9X6+Yp4beG7H c1yHL1Zexcdf4ykkExQdl6VCn3UgjFm6Bw7z/oo4BFz/Eb54O3Unx9YJAE9Vc+GvIUzW FFcb3P0nqX2KWpRqztxxJOh1GKPSzXmVoqWdeIftfWFwsKCsdbtKWbY7ZrAmYFylpb6W G/ig== X-Gm-Message-State: AOJu0YwBLVZgl9hqprLJUJD0xD7jSeBrbWa6fYHd8+PqibZlBHs9DYY0 chfnbCyY6Rks5EVMsYiXr2OtQw== X-Received: by 2002:a05:6214:daf:b0:67f:3d1e:ad22 with SMTP id h15-20020a0562140daf00b0067f3d1ead22mr2663046qvh.31.1702908236081; Mon, 18 Dec 2023 06:03:56 -0800 (PST) Received: from localhost ([2620:10d:c091:400::5:c6bd]) by smtp.gmail.com with ESMTPSA id mx2-20020a0562142e0200b0067f566221d8sm175076qvb.121.2023.12.18.06.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 06:03:54 -0800 (PST) Date: Mon, 18 Dec 2023 15:03:54 +0100 From: Johannes Weiner To: Yosry Ahmed Cc: Andrew Morton , Chengming Zhou , Nhat Pham , Chris Li , Seth Jennings , Dan Streetman , Vitaly Wool , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 5/5] mm/zswap: cleanup zswap_reclaim_entry() Message-ID: <20231218140313.GA19167@cmpxchg.org> References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> <20231213-zswap-dstmem-v1-5-896763369d04@bytedance.com> <20231214142320.f5cf319e619dbb2127c423e9@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Dec 14, 2023 at 02:41:26PM -0800, Yosry Ahmed wrote: > On Thu, Dec 14, 2023 at 2:23 PM Andrew Morton wrote: > > > > On Wed, 13 Dec 2023 17:02:25 -0800 Yosry Ahmed wrote: > > > > > On Tue, Dec 12, 2023 at 8:18 PM 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 swapcache, a > > > > - * load may be happening concurrently. It is safe and okay 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 = get_task_policy(current); > > page = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, > > NO_INTERLEAVE_INDEX, &page_was_allocated, true); > > - if (!page) > > + if (!page) { > > + /* > > + * If we get here because the page is already in swapcache, 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 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 ;)