From patchwork Wed Jun 14 14:31:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Cerasuolo X-Patchwork-Id: 13280128 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 35A59EB64D8 for ; Wed, 14 Jun 2023 14:31:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3C3A6B0074; Wed, 14 Jun 2023 10:31:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ECA06B0075; Wed, 14 Jun 2023 10:31:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 898746B0078; Wed, 14 Jun 2023 10:31:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7A4D96B0074 for ; Wed, 14 Jun 2023 10:31:37 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3D56A140658 for ; Wed, 14 Jun 2023 14:31:37 +0000 (UTC) X-FDA: 80901591834.27.EAC0714 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf10.hostedemail.com (Postfix) with ESMTP id 73EE8C0033 for ; Wed, 14 Jun 2023 14:31:32 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=HjkI1d0w; spf=pass (imf10.hostedemail.com: domain of cerasuolodomenico@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=cerasuolodomenico@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686753093; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=R6k6f2ympJcu3ns6Ija20elkW6bhMNjpeBhrfJ9xoy0=; b=1CCwNGHxHX4c9vyoYHeQ1J/ke3HdHti6dAnRTi3APusb1SypfCCwjTDC8a1YUyHEZH75h2 KtScEaGIwnrPNlS5wbIaqsb1+egrx+EGdlv/hxkhlDaHiMJmAPri3rK/eW112BJwCslYUC LkVkeXf1tu56FW2fs8AzAfhpZAf9QvY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=HjkI1d0w; spf=pass (imf10.hostedemail.com: domain of cerasuolodomenico@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=cerasuolodomenico@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686753093; a=rsa-sha256; cv=none; b=zdlEtca6gbaItUsuoRt7hFIopYzrQf9HeUvsZ0spXVJVbXj3qkgNTCu4/EXXf25WWspiKP 2a8u6d1ddFAKWaxwW8nR964zWtazx5aocxWA0//q+eB4IZs8Z+6Nqc55GtVCvFFHJHl44p Znt5FnkF+yJ2fpAF5SKJOUCU5oZt9EU= Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-976a0a1a92bso129881266b.1 for ; Wed, 14 Jun 2023 07:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686753092; x=1689345092; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=R6k6f2ympJcu3ns6Ija20elkW6bhMNjpeBhrfJ9xoy0=; b=HjkI1d0wFayV/as5yTDNIQtDbssukoexajKlZsiuAA2dK1489xvUAe0557735bTveq 15L/1h78tKHmG6o5I+zlZ8/h9vEWUfRIrcCwLFAes0eFzNA077iEL8NOgo3t2NHUZb9e Rqh+mfO76L1Ogl/rqrQaHRYGPG3mAH7VbHWg5cXreln2+JJD6sZTH7237wspca614BJj E0qlB4jY2AHHZtCyaCm5j4jCub9IhPoAgSba6gGTyNACNPX5cCFeqWZCRry9mEBkl9yy NoGljNSsMxtRaovXsjNOBc8D0q2Y4tO/7P/HGY7sOsH2HPmUBsSgZQ80khOTvqTkYRSM 9lWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686753092; x=1689345092; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R6k6f2ympJcu3ns6Ija20elkW6bhMNjpeBhrfJ9xoy0=; b=T1emVdSaAEWgYrTiTyLofCO9h/7zRAZdFxArYUb88O/AB5GnV+JbNcHi3zv3OXOfVA 6tqE92XrCp4Ju3wxv9NufOi+EXGbmlIGPGIfWeU+Ymxp9udHOo7beEUB3XNfBZfjxk55 WdBrWp306+gUvBl8Ix5NsqWMJ/0SiAjFj6C8Ow9hEAcyEuHiUn0QvrYaY9nTslCbcbyp J3WvUPq7zk5eeoC81RWI4ko1KdJ9OxAVXgRHw27SjUzG66ZDo8q6pZPEEIyJm/U/8lFd dLY9Bh44bS8ND3UiMd//rgQ7J9X8CNNxSqICLjmuXB94BlnNLGMltcUHWLmzVw4Sw4yz HhtA== X-Gm-Message-State: AC+VfDyvSPUeOrJbiLb0CamG0DUQEeVJhynm0ZocWsQ8DDPLX2N5oqHY 699bpQFelyfRjBYOSThO2K4= X-Google-Smtp-Source: ACHHUZ43SmOvYMDVVok7GBhgV6vKwQB3xnBs5kgWIpWtJgQHOVYnpeYRlK0pBG6kvsVSP+AP9PEeqw== X-Received: by 2002:a17:907:971d:b0:96f:ea85:3ef6 with SMTP id jg29-20020a170907971d00b0096fea853ef6mr15466663ejc.62.1686753091312; Wed, 14 Jun 2023 07:31:31 -0700 (PDT) Received: from lelloman-5950.homenet.telecomitalia.it (host-87-21-158-222.retail.telecomitalia.it. [87.21.158.222]) by smtp.gmail.com with ESMTPSA id p20-20020a170906b21400b009767c4235absm7983749ejz.219.2023.06.14.07.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 07:31:30 -0700 (PDT) From: Domenico Cerasuolo To: sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com Cc: yosryahmed@google.com, hannes@cmpxchg.org, nphamcs@gmail.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Domenico Cerasuolo Subject: [PATCH] mm: zswap: invaldiate entry after writeback Date: Wed, 14 Jun 2023 16:31:22 +0200 Message-Id: <20230614143122.74471-1-cerasuolodomenico@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 73EE8C0033 X-Rspam-User: X-Stat-Signature: hesp1xbbqmawcmrih3yfsfbbqe71d5g1 X-Rspamd-Server: rspam01 X-HE-Tag: 1686753092-39249 X-HE-Meta: U2FsdGVkX19TglOKbDw7h5+OHTe1cA0ito7S1Fm9daooU2caAY6DP9mUdwOLRbQpYChFNRb2Vf7lJacq5eC/k63oZuEsf7OZzgIlmOimfpPPJ6A3+Epay7n72nV1x+EbjnY1OsaMTaBOWeC3VPrr0oib4D4QhvGTJmHhZA2gYIY41hpo4iRi7CCmByDKYOQP+z0/UeTi7zIctg1ylvvGxQMLa8lKq7517IGKl7nDhObteV1ozYBsbjirjLaxPbY8tszbWMaCAoCZrOxYPd4eVsAchFfG39leDvvgWHwBAg9v96VrdRDEoPmP5Yo4L8fCuiSPv7/U0ifyJFFWCKjcTWbAvnzTpeo1V8EMnyF2IfuQBYeLL3AJvz9kCkQazVDr/YivXkOfntiS0lr506/E0Ttlz2qkdI8KOdCDNLh9TO4mlEH8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fPhmsSzscwPqs0gNhx2QClTnNd5+r+m6T9ekh0yg== 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: When an entry started writeback, it used to be invalidated with ref count logic alone, meaning that it would stay on the tree until all references were put. The problem with this behavior is that as soon as the writeback started, the ownership of the data held by the entry is passed to the swapcache and should not be left in zswap too. Currently there are no known issues because of this, but this change explicitly invalidates an entry that started writeback to reduce opportunities for future bugs. This patch is a follow up on the series titled "mm: zswap: move writeback LRU from zpool to zswap" with message id <20230612093815.133504-1-cerasuolodomenico@gmail.com> in mm-unstable + commit f090b7949768("mm: zswap: support exclusive loads") that's in mm-unstable as well. Suggested-by: Johannes Weiner Signed-off-by: Domenico Cerasuolo Acked-by: Johannes Weiner --- mm/zswap.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 02d0a6f46f4a..c122f042a49d 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -599,6 +599,16 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor) return NULL; } +static void zswap_invalidate_entry(struct zswap_tree *tree, + struct zswap_entry *entry) +{ + /* remove from rbtree */ + zswap_rb_erase(&tree->rbroot, entry); + + /* drop the initial reference from entry creation */ + zswap_entry_put(tree, entry); +} + static int zswap_reclaim_entry(struct zswap_pool *pool) { struct zswap_entry *entry; @@ -644,12 +654,13 @@ static int zswap_reclaim_entry(struct zswap_pool *pool) goto put_unlock; } - /* Check for invalidate() race */ - if (entry != zswap_rb_search(&tree->rbroot, swpoffset)) - goto put_unlock; - - /* Drop base reference */ - zswap_entry_put(tree, entry); + /* + * Writeback started successfully, the page now belongs to the + * swapcache. Drop the entry from zswap - unless invalidate already + * took it out while we had the tree->lock released for IO. + */ + if (entry == zswap_rb_search(&tree->rbroot, swpoffset)) + zswap_invalidate_entry(tree, entry); put_unlock: /* Drop local reference */ @@ -1376,16 +1387,6 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, goto reject; } -static void zswap_invalidate_entry(struct zswap_tree *tree, - struct zswap_entry *entry) -{ - /* remove from rbtree */ - zswap_rb_erase(&tree->rbroot, entry); - - /* drop the initial reference from entry creation */ - zswap_entry_put(tree, entry); -} - /* * returns 0 if the page was successfully decompressed * return -1 on entry not found or error