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 22C5DCF9C69 for ; Tue, 24 Sep 2024 19:20:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD5376B00AD; Tue, 24 Sep 2024 15:20:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A859D6B00AE; Tue, 24 Sep 2024 15:20:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94D986B00AF; Tue, 24 Sep 2024 15:20:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 757E76B00AD for ; Tue, 24 Sep 2024 15:20:55 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D53D91202E4 for ; Tue, 24 Sep 2024 19:20:54 +0000 (UTC) X-FDA: 82600599228.26.F72B03B Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf21.hostedemail.com (Postfix) with ESMTP id E47CB1C0008 for ; Tue, 24 Sep 2024 19:20:52 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=vgVzOZtr; spf=pass (imf21.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727205533; 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=raaf+7JBNIDAcmpKXOzNkGLcUnQWjLcp9/ooEg61O8o=; b=uj8USQsyN5xhpsTofNmelGAkGH2CxwrVwU6TY2a2uNdNtMIdCzWAOWpH8o/LgbXV7p4V98 yIvac7tXviHCWmdr48c9a+7V9AARs0NId1sCwuNhYomyIklDQsbhPDxf4aoCK/9ygDL9ko TR7GaZJm3cCvldkvtz+YFSpipcLVhTk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727205533; a=rsa-sha256; cv=none; b=zuc1xEW0zwAS8em7k/MhFFCAesCSJMR+HKYjYhWSNZosJHS23boWgJIgHX+bkNo2eghLTH ze36MWYAWAuU8hjtdTo22dFhnUukjHwluOX21RRwriRm9Lw94S2+zV2KzrKmuIJWbaqcqA goioaye5Vl3YaDEkYckmrqf/xjMnqag= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=vgVzOZtr; spf=pass (imf21.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a7aa086b077so763074166b.0 for ; Tue, 24 Sep 2024 12:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727205651; x=1727810451; darn=kvack.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=raaf+7JBNIDAcmpKXOzNkGLcUnQWjLcp9/ooEg61O8o=; b=vgVzOZtrrBclX9cB37Hf2wbrUAmycHNrI+817K53dPEiyl/NL77IKau9vERjBZoHog 3x4mRjGJrJaHDx0TkMe1YTKv21uz1BWLFEqna77OSLwRX5AfHPijIMvy3uEp9ElXblW1 vNWpY417oY2x7M6W6eD5v0bfXOpRqvW4oBDxuW7YY7t+YD37RSsM9Rz4JXAxhPi9ZWDL 0zldcKn2a/2OdWJncAbOFPGIVbdfBiQn9HQMEoA1AQf3+I8pzGXeN/EiwR2hIGdy0HjP 4ytHdm0F4ZN6PYrgAHwSN7kbeU815mYqnWka338C9nvDzeS9+TVXFowMLBwQPGeHnsq2 3x8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727205651; x=1727810451; 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=raaf+7JBNIDAcmpKXOzNkGLcUnQWjLcp9/ooEg61O8o=; b=XDvhxbV0iG7wtlSEavajOczxspcc3oGJ1hPrg6cRl1FljlTOV5zAcoIhVBo05FkOcP h7XWCk0q1Bepj8bOpqPDDyM1kG4v0m1I50Th9BS0/zQNxamN/JyWjMgn7YxSRNzwCEB9 X3bw3AxhPDB28CoZglAIh2vGz1dSPgfym7pXUP7i77vfyTF9h8JARUACzGPD/OoTUjcy WDkpIYNuxWtrw26n3e8aZag49cyBKe4cQtDV2FFxdcqk2HqZ6+rmk1OYFRVaH9eX+A/0 wp0MolpL3lOcWRXprbN86RKMPnRWXrzO6GL5z8WKpR+dQs3r5S69SlZlLo/QsB9z1dMQ RkBA== X-Forwarded-Encrypted: i=1; AJvYcCWMlgnbb8KVahTYEOMggr9Q/Cc188zp8gwrtOoV/q6kW7sYwn/Du4Exp3O6zICRd5cUuT573Vak9Q==@kvack.org X-Gm-Message-State: AOJu0YxDYwjc3JwCMhsUzS3qV51JlRC3nu1R38A/o+MIp/thDW5dkHnp RXxWJ4gaDO4QKbDcXmgCtnTXQcJueErXoQ4VsKCmdNd8lLhYDb+G+MdECKrYSppO5x/kJmJ6/ij SxGPY62UX7r9aE779GLkA0s88J56hiPXZArSY X-Google-Smtp-Source: AGHT+IF56noL0SS3BYhYZVMxxk2MUDSX7D3UGPx+TBokGaqN9I3R+t03CX4nHG3AI+F0RW/YDav/JhykUXzasJCOGGk= X-Received: by 2002:a17:907:7287:b0:a8a:9207:c4c1 with SMTP id a640c23a62f3a-a93a068a306mr26560366b.58.1727205650990; Tue, 24 Sep 2024 12:20:50 -0700 (PDT) MIME-Version: 1.0 References: <20240924011709.7037-1-kanchana.p.sridhar@intel.com> <20240924011709.7037-5-kanchana.p.sridhar@intel.com> In-Reply-To: <20240924011709.7037-5-kanchana.p.sridhar@intel.com> From: Yosry Ahmed Date: Tue, 24 Sep 2024 12:20:15 -0700 Message-ID: Subject: Re: [PATCH v7 4/8] mm: zswap: Refactor code to delete stored offsets in case of errors. To: Kanchana P Sridhar Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, nphamcs@gmail.com, chengming.zhou@linux.dev, usamaarif642@gmail.com, shakeel.butt@linux.dev, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org, nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: h9giubs5tq6xjmjdquutiyqu9q5sngt1 X-Rspamd-Queue-Id: E47CB1C0008 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727205652-55488 X-HE-Meta: U2FsdGVkX1/1VNLdueXxRa3QGB3Pb9H1xfHRYVwZlH64RbhAFr3vuE69wXxQG97W3T/+qPBp0QvutqRehnZgKt8DHn4LTSEyxaJ+uyAr7ftJLILApiO2L8S0bpYXkyR2BJV0BFOeFULawa13ok62c5m5vsbr3XPUpVCOnlPeThNnF8ldmBEdQgMES0vlgXkSxiXvHPHI9ma/eigRelRjeHiu1vu1Qyld2p9vfm8lMwkY4NZBtsIEXxuzsJmgP9+4DBMWR/Ky9H4mgk5iLdqf6D5q3VEJ9UAzBZbyST9/01ykrnquSk5j3GzdEKJQzY0tkwrCAqHOBn9UZZO/4Sm6LqyFcoqstImF7cfQ4WaN0GP4Y2ba4eI2iWFoiOJvRpf1FI3Dr/ThGYGa/8AHz97Bn3KSS9zvSJ6ZK+vS83K41uQ+mr53Tl/xuTigxCXBOsmB9ooe5I48hAtKR1ASA8PuRKWlLUbB+B/7M5a4km1ENpAbQhNmZPUJYcxAb9PORhMfeTU5AOrbW6ymM7zDPTr0T9n8gbqogfFBRiG70SiXhgGBqR1uKHFhb+hladufCVtDeQXsmr7B238Go/7b42Tt6XP9kmv+xcnVdrYx9SbeoAVghqUlnjRLLEGTkSD6hBCWZ8zKzUUhXFQ3wlFyKDyKeejVkhP6QpfP5/IkZYkkWTAXMxAzYW3w3OJQc/WV1srU3u0kKKjWD64SipSpJ55m2VVvnu17rGwWAnntrUbP+ieqpC4DzHGm3adCRPmIxiVOHGIEtjtTcMSduj6Es+baqWg82iKrMV+gTJ39JXPJLcL6ZolntWSBQY0PvE2guiasmlPoKZi1jhlSttKQz0brptKyfrsLQ4hmADjVhH64WdOJ7j6kKc+PbBa53CT8+ML8KcZA9XUFB5R4mSalrxqYh4PWfKhINJzd45BCU/Jl025BgvoPiCSa9KKyJbVf5W4SWo5shhJsZM4Hd6Jpmxx rwc06+pr DHIahzOnbwcpyfsvYHdpJ1NLAu8PWmwjvBANR3NmciZ7paapHpbpTZCWRJK3ffOLAHtO8nKsHyO03qaLPfkXi1FbiYDgts2KJ/AMbsODKtKDA4fvjqef02gq9TknyCggCJ9uZyfve6iTO+1Du+WpIrAjJHgvM/DNnzJF37hRf9mHvti86p9mcYz4OyO92l1ZJFbdYPsiOOwvAsMgLqVuNWn5aQMN78VN6er6/ 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: On Mon, Sep 23, 2024 at 6:17=E2=80=AFPM Kanchana P Sridhar wrote: > > Added a new procedure zswap_delete_stored_offsets() that can be > called to delete stored offsets in a folio in case zswap_store() > fails or zswap is disabled. I don't see the value in this helper. It will get called in one place AFAICT, and it is a bit inconsistent that we have to explicitly loop in zswap_store() to store pages, but the loop to delete pages upon failure is hidden in the helper. I am not against adding a trivial zswap_tree_delete() helper (or similar) that calls xa_erase() and zswap_entry_free() to match zswap_tree_store() if you prefer that. > > Refactored the code in zswap_store() that handles these cases, > to call zswap_delete_stored_offsets(). > > Signed-off-by: Kanchana P Sridhar > --- > mm/zswap.c | 33 ++++++++++++++++++++++++++++++--- > 1 file changed, 30 insertions(+), 3 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index fd35a81b6e36..9bea948d653e 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1435,8 +1435,37 @@ static bool zswap_store_entry(struct xarray *tree, > return true; > } > > +/* > + * If the zswap store fails or zswap is disabled, we must invalidate the > + * possibly stale entries which were previously stored at the offsets > + * corresponding to each page of the folio. Otherwise, writeback could > + * overwrite the new data in the swapfile. > + * > + * This is called after the store of an offset in a large folio has fail= ed. > + * All zswap entries in the folio must be deleted. This helps make sure > + * that a swapped-out mTHP is either entirely stored in zswap, or entire= ly > + * not stored in zswap. > + * > + * This is also called if zswap_store() is invoked, but zswap is not ena= bled. > + * All offsets for the folio are deleted from zswap in this case. > + */ > +static void zswap_delete_stored_offsets(struct xarray *tree, > + pgoff_t offset, > + long nr_pages) > +{ > + struct zswap_entry *entry; > + long i; > + > + for (i =3D 0; i < nr_pages; ++i) { > + entry =3D xa_erase(tree, offset + i); > + if (entry) > + zswap_entry_free(entry); > + } > +} > + > bool zswap_store(struct folio *folio) > { > + long nr_pages =3D folio_nr_pages(folio); > swp_entry_t swp =3D folio->swap; > pgoff_t offset =3D swp_offset(swp); > struct xarray *tree =3D swap_zswap_tree(swp); > @@ -1541,9 +1570,7 @@ bool zswap_store(struct folio *folio) > * possibly stale entry which was previously stored at this offse= t. > * Otherwise, writeback could overwrite the new data in the swapf= ile. > */ > - entry =3D xa_erase(tree, offset); > - if (entry) > - zswap_entry_free(entry); > + zswap_delete_stored_offsets(tree, offset, nr_pages); > return false; > } > > -- > 2.27.0 >