From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D450C197A0 for ; Thu, 16 Nov 2023 20:12:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F7B6440165; Thu, 16 Nov 2023 15:12:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 980D68D0005; Thu, 16 Nov 2023 15:12:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82234440165; Thu, 16 Nov 2023 15:12:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6CAA48D0005 for ; Thu, 16 Nov 2023 15:12:10 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 27226120D0A for ; Thu, 16 Nov 2023 20:12:10 +0000 (UTC) X-FDA: 81464914020.21.562702C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 2D76740004 for ; Thu, 16 Nov 2023 20:12:07 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G+VhEEeE; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700165528; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xEyEPOduZvXsW6JCW3EvIV8l1fEfOk8Dt8YmxhMEDlg=; b=kCufsj6ZLzYqDGk0IkheYWdJfTXOP8+Pgq0Sk6HVk6H87TBf3sASfDfGJQgIZSk7KHAZ1Z vCsokV1LTDEdClS7ynQxygjnNGG8rMYurmyh6RBBKHf9dul6V5v8t0bAIFqXn2qZYELKIM x9HXoiAX6l2R2rpLq9PZhLWSgjs1y8U= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G+VhEEeE; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700165528; a=rsa-sha256; cv=none; b=cmqxhFPB1zoN1S0JMY6kD2ziQBLL/YZZ6erpLPBYCykkEy80cHXuepzo/0kOw6VNNYbmRJ WNoIDyrQwMeNvYkZc6RQNsQxf91Ccy89PVwi6a/nikR5SUekAV+tBFCy7gx4WTtNxNbKAn IMq/CGI2zi2tmjpTIvEmIXq9brqPsxk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1FDFB61B09 for ; Thu, 16 Nov 2023 20:12:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EF45C43395 for ; Thu, 16 Nov 2023 20:12:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700165526; bh=C5Ag1NQb4cc7th3TofT7+5tV5THCDr4smloIfN3cIT8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=G+VhEEeEu98nDD/uX+PWythEgk4mnU5QndLxsSN8himE0uc4GEJ3FnzQxjc+Vpv5D ktSPawRpgT91Pr90Ed9n5No+1Ry0O8mjccIgnf8qwZ4AZxv0Bihx9gE01jpSLW8oIM +oO5s/d6f8Ay5qO4Q1MVJvbMXsga+X8AoJipTbdrrmXjOQpnlUp0xLTathTRWiH92J 7IDMLHg/mB+YlrdXHGZ+O1T4yHJMtzOVMacGgKneYzHfofmi9F2XEKQVoqEq40Jbhm YonHu9ghVYABG2A0UPgAVvXHoMJwZPaWw8uz441RaDiz8Dt2YK/5qypu8xu8pk5oWr xExUyv0Mtp2Ew== Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-28098ebd5aeso963415a91.0 for ; Thu, 16 Nov 2023 12:12:06 -0800 (PST) X-Gm-Message-State: AOJu0YzWozcdiw8OHSJ9o7ZWDlpwQPfYt9KlxLTD2hBkAiUqjm5dSfKM Ys/ZwtC+3L/4xcMTo7vgge5w8Mwijgzzrzoi9gMG1w== X-Google-Smtp-Source: AGHT+IG0K5P5Vq19J39db/gwdi+x76zhJReRhaju/NQOIby1hNOhosKgN6jisI8FQMvoBybSJPNEHy8biG3OJDGliuc= X-Received: by 2002:a17:90b:3b87:b0:280:a69e:45e5 with SMTP id pc7-20020a17090b3b8700b00280a69e45e5mr17271341pjb.44.1700165525441; Thu, 16 Nov 2023 12:12:05 -0800 (PST) MIME-Version: 1.0 References: <20231113130601.3350915-1-hezhongkun.hzk@bytedance.com> In-Reply-To: From: Chris Li Date: Thu, 16 Nov 2023 12:11:54 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] mm:zswap: fix zswap entry reclamation failure in two scenarios To: Yosry Ahmed Cc: Zhongkun He , Andrew Morton , Johannes Weiner , Nhat Pham , Seth Jennings , Dan Streetman , Vitaly Wool , linux-mm , LKML , Ying Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2D76740004 X-Stat-Signature: 6he399ihace4zghbhircjbu9nn8s4jks X-Rspam-User: X-HE-Tag: 1700165527-269641 X-HE-Meta: U2FsdG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MYywCl3zoNggZVOGEpaxd9DO3sURxBjOKXlaIJFYX8kUDNXVLcrUz13pOh5ggRJsj2VuKOoMYkTG4H+yFXhxSsOnQbc0AVzL6JRGyozs0IcSCGhkj1Ynbkihb1VDY0/I7Qc0YaptYOZf+5XDc3SE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Yosry, On Tue, Nov 14, 2023 at 9:16=E2=80=AFAM Yosry Ahmed = wrote: > > 1)The swap entry has been freed, but cached in swap_slots_cache, > > no swap cache and swapcount=3D0. > > 2)When the option zswap_exclusive_loads_enabled disabled and > > zswap_load completed(page in swap_cache and swapcount =3D 0). > > For case (1), I think a cleaner solution would be to move the > zswap_invalidate() call from swap_range_free() (which is called after > the cached slots are freed) to __swap_entry_free_locked() if the usage > goes to 0. I actually think conceptually this makes not just for > zswap_invalidate(), but also for the arch call, memcg uncharging, etc. > Slots caching is a swapfile optimization that should be internal to > swapfile code. Once a swap entry is freed (i.e. swap count is 0 AND Do you mean moving all swap slots free to bypass the swap slot cache, even = it is not from zswap? That might have unwanted side effects. The swap slot cache is not just for swap files on disk. The batching has the effect that on average lower cost of freeing per entry. > not in the swap cache), all the hooks should be called (memcg, zswap, > arch, ..) as the swap entry is effectively freed. The fact that > swapfile code internally batches and caches slots should be > transparent to other parts of MM. I am not sure if the calls can just > be moved or if there are underlying assumptions in the implementation > that would be broken, but it feels like the right thing to do. There is also the behavior that if the page gets swapped in but hasn't changed, when swap out again, it is possible to avoid writing the page again to the disk. For disk there is no overhead keeping the old date on the disk not to touch it. For zpool it might have memory overhead holding the compressed pool. The trade off might be different. Chris