From nobody Sun Feb 8 12:20:26 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 717D6C0015E for ; Thu, 27 Jul 2023 16:23:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234229AbjG0QX4 (ORCPT ); Thu, 27 Jul 2023 12:23:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233922AbjG0QXv (ORCPT ); Thu, 27 Jul 2023 12:23:51 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45B5C2D4B for ; Thu, 27 Jul 2023 09:23:48 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-63cf96c37beso5142926d6.0 for ; Thu, 27 Jul 2023 09:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1690475027; x=1691079827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V4WqUpKSmXvGR1M+fIFBD/JXbqB10oByq1yE4svjvKk=; b=qNto7iFRrzOxESe9fv4KXfCHzvEpqtjq8zKP6G+FHbxknRdRQyruOVS/C6JV+mmMvY +/rWcuLtgsi9NpP8YgxSITdR8dLpz4uKoeqElIiF8b0B/yCc6cd24rpY8lAY+hhsYZCj nuB6QswJUQX/5foZILCFhUOhAhxdSuiL48uJ9//IKXR5DiNmxdHTFCXSUib5GYajdUMC BZX4uCMOPsz4wm4GIKg0pa4I8kmWdNTYMyl1/gbCDWOOuOnTP6xcrq/91YCR699FRai3 uD/9XMZLJawLy/Dvhly73UgklITjc1pFzK3nbx3xqKttOiuUSz1YJoFeSUFYn+hyS7zH wtww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690475027; x=1691079827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V4WqUpKSmXvGR1M+fIFBD/JXbqB10oByq1yE4svjvKk=; b=IzwlHxanvXS0f8sD+SMJGQh8RMXbBArVrUW9Xda/VY/w4nh7+1Br7ZmOd0Yr9w1aPh KZ+suPIpp68DQ+TN46QVNQSMATUF4QpiqLzpik8LSjp0lacfwUc95YO93fMwadsWSzcx R8AQdtr8Ly/hKhjmMDCh7LB7/5CFmlag15KnePE87nxaUT/ey92gAQ5N86jTr9bIbjPl CKQO9VlHVWLDQhPwb+4AReg5+Nox9dSF5qkvDLg86rVHTSk0NCiwI2/bEWDq2vfmikod 8XqVb5NyZkmYVEohrnifWnjnsSmAnisq9gThLYy8CSVZYxjnQmTYWJmUjOheSxhkaXxe OMpw== X-Gm-Message-State: ABy/qLZ9RnKyp1z3JSslzjpoG6Q9zUcGDtb6R3YSqq0HiK2QDzVawk/q LXx0xVLAOd0u8eNFTt6tjNVKJaD+3/6foktG00IaIg== X-Google-Smtp-Source: APBJJlEf3a+4nlFwkjw+loMNGiZ+A28qMm0A+SS4AICZPLdvjR5GWT3rErmZtaoO4i263nli3LNnqA== X-Received: by 2002:a05:6214:d6a:b0:635:dbab:a588 with SMTP id 10-20020a0562140d6a00b00635dbaba588mr850652qvs.16.1690475027432; Thu, 27 Jul 2023 09:23:47 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ad06]) by smtp.gmail.com with ESMTPSA id s18-20020a0cb312000000b0063762ab2f90sm527074qve.83.2023.07.27.09.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 09:23:47 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Domenico Cerasuolo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm: zswap: use zswap_invalidate_entry() for duplicates Date: Thu, 27 Jul 2023 12:22:23 -0400 Message-ID: <20230727162343.1415598-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727162343.1415598-1-hannes@cmpxchg.org> References: <20230727162343.1415598-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Minor cleanup. Instead of open-coding the tree deletion and the put, use the zswap_invalidate_entry() convenience helper. Suggested-by: Yosry Ahmed Signed-off-by: Johannes Weiner Reviewed-by: Yosry Ahmed --- mm/zswap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 583ef7b84dc3..e123b1c7981c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1344,9 +1344,7 @@ bool zswap_store(struct page *page) spin_lock(&tree->lock); while (zswap_rb_insert(&tree->rbroot, entry, &dupentry) =3D=3D -EEXIST) { zswap_duplicate_entry++; - /* remove from rbtree */ - zswap_rb_erase(&tree->rbroot, dupentry); - zswap_entry_put(tree, dupentry); + zswap_invalidate_entry(tree, dupentry); } if (entry->length) { spin_lock(&entry->pool->lru_lock); --=20 2.41.0 From nobody Sun Feb 8 12:20:26 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A014C0015E for ; Thu, 27 Jul 2023 16:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234304AbjG0QYA (ORCPT ); Thu, 27 Jul 2023 12:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234003AbjG0QXv (ORCPT ); Thu, 27 Jul 2023 12:23:51 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9E7D2D64 for ; Thu, 27 Jul 2023 09:23:49 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-768054797f7so101768685a.2 for ; Thu, 27 Jul 2023 09:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1690475028; x=1691079828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g6xeXNZ7MmGxs9MCe+qdgeE1O4rbj13SYexzHrnrzbc=; b=t1KwP89hpnwg0NYhi1k1hMQB/3gQRSOWAy1zvJ7pueqsOL6lMhlnGs29bj9q3R7ed2 5TGX5AbXfBOKFrqHxQDMSSGFph1MqS/IIURzJrYtuyq5DJDNQSlPgyx6HKbsJCFrgyMs etJArP1Qo7jM62rDTvet0BjBWc9wIdYpICMtw4B6tf9ouYzlHD0s6flS1M2mtpzmsp3P Tg1utgnTtVxz7Ck+6yn7HuwnCpOeXrrLAxZP/B7IVeVZfU45bb/Ad1ZLt/8jOMuY4acP s9Ljx+sG57pZI23evKzyyIa5rmfHvAJu7nn7DIh1eF/R8VZWmTH5gwWvPzEBnh8xunF7 LIIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690475028; x=1691079828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g6xeXNZ7MmGxs9MCe+qdgeE1O4rbj13SYexzHrnrzbc=; b=NtSpgW7h4tLR1CtowqtNzfZVgxDUc2ptcNdn8nHCiDANe/vlmePDpaOjDWXMbhI9UH QGXWoY9uWcARYLoNLDoU5Imbr28ERcpEGHx5sMritglpLc5/JBtyaLUf0FXC/J5a32K4 PzpqxqWO6ldiEaOVuInPqW+YV5jCofGuC5Evof7zg91CH/TImOm3XxFEwpHekVW8xrT7 MLxIDbFMyQTo8K2Dh50hjbfVpXdSJPgv0/Trytc2sJmyD46JvdLAJIjRG3KMbj13PVg0 IylhqNKhBI/okHK1zRC8PLB012ZEebOzfKsxnbgqsQJldDk+E+IXork5d9NIT3gOERHH OQ4A== X-Gm-Message-State: ABy/qLZUwhfqzB54oYBno9DXP6qALgN2s/14eVj6mVWr+OtVK2+ksWaQ 2vB/HSA5LZ9EXI5indJgl4LMFA== X-Google-Smtp-Source: APBJJlHsm+mf07gWGmI92coTtdUdEWEsIic/VUEsa+GtEeTjX9B1tCutvPQZueF/jzY9ZsnEbTyiCA== X-Received: by 2002:a05:620a:ccf:b0:768:b0c:e4c1 with SMTP id b15-20020a05620a0ccf00b007680b0ce4c1mr434494qkj.27.1690475028555; Thu, 27 Jul 2023 09:23:48 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ad06]) by smtp.gmail.com with ESMTPSA id p13-20020ae9f30d000000b0076816153dcdsm505827qkg.106.2023.07.27.09.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 09:23:48 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Domenico Cerasuolo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: zswap: tighten up entry invalidation Date: Thu, 27 Jul 2023 12:22:24 -0400 Message-ID: <20230727162343.1415598-3-hannes@cmpxchg.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727162343.1415598-1-hannes@cmpxchg.org> References: <20230727162343.1415598-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Removing a zswap entry from the tree is tied to an explicit operation that's supposed to drop the base reference: swap invalidation, exclusive load, duplicate store. Don't silently remove the entry on final put, but instead warn if an entry is in tree without reference. While in that diff context, convert a BUG_ON to a WARN_ON_ONCE. No need to crash on a refcount underflow. Signed-off-by: Johannes Weiner Reviewed-by: Yosry Ahmed --- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index e123b1c7981c..e34ac89e6098 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -402,9 +402,9 @@ static void zswap_entry_put(struct zswap_tree *tree, { int refcount =3D --entry->refcount; =20 - BUG_ON(refcount < 0); + WARN_ON_ONCE(refcount < 0); if (refcount =3D=3D 0) { - zswap_rb_erase(&tree->rbroot, entry); + WARN_ON_ONCE(!RB_EMPTY_NODE(&entry->rbnode)); zswap_free_entry(entry); } } --=20 2.41.0 From nobody Sun Feb 8 12:20:26 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 698A4C0015E for ; Thu, 27 Jul 2023 16:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234279AbjG0QYD (ORCPT ); Thu, 27 Jul 2023 12:24:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234088AbjG0QXw (ORCPT ); Thu, 27 Jul 2023 12:23:52 -0400 Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C93B30ED for ; Thu, 27 Jul 2023 09:23:51 -0700 (PDT) Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1bb5ce75e43so808470fac.3 for ; Thu, 27 Jul 2023 09:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1690475030; x=1691079830; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9xKvUZAC/PcwLq4Mn3vj+fKTV8KIinkTpyaNVs2EYco=; b=ZM6siFmcEpT22TCKTBC20dzc2m3blvxe+fV7xBWQ5V/W+B8u2sR51MOrUVn0oe9H9r p3SLhh1gZWJjZ41HzedjMK816QkKQbpYiYtUKKn82b4C9atpUvnedHQf+0jDaBf3j77Q tJOmmfcGqfxttLoXBrJCFjVGF8sW0Q572CZ16Ht4fa8chGgIb2Jw6/K1cT/xLpr/JkM5 r3iilsyakH1SBZfuqYO5hwJQP1WMnOayvcj1j6HQ6bVFu643j76ZwjEXMY25LUTF4q1y UHe6Ly/6TR285I3CJYLC6dr76PLwRPjFwQFb634smNKQW1NJjIxSKuDdZhMfZRorHggK kV/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690475030; x=1691079830; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9xKvUZAC/PcwLq4Mn3vj+fKTV8KIinkTpyaNVs2EYco=; b=Fjn64tsHhutAsxaz4eOb9uixzUsGm48tj1b4kdBW3Xs9cjs1AtDU/yTwJ9eXQB/DWr k59sdv2klcfHXPQguigtBbHdpRuE65X2Q9LtUr+QIq0VBYKSk9JeMpyKGRUQ94BOOUTh xxOMJ3JDNtqLCwpn9BWH2IGSCweO+IsV3Sbb0N85AQ3ApPaR2ar5CQhj0NR72M2H+MJP Iz5z26J2Lv2E86qfsjYLom+zrrzTWfZzqngco5CXswWX/4VHzK9oP+wONHO4XpU52f4K puk9z3+WKWQxlqYKvHXmDoITBgNThkNK0Y3C/6QCCYZFSJblPbQZbRm/W1AUqG6y340m nOlQ== X-Gm-Message-State: ABy/qLb6qqEYzYjNjk+GWzyjPuw1TQW4WGGn/3hP91wi/9kAil+RaTKJ 6z18JA+XkN1eIwIFkL8yp7uzAQ== X-Google-Smtp-Source: APBJJlGe/1LwJSfSBsFM0E1SehZPQyy8thiIa1GfuOSx8pATP8cfV6nW9jnsPOBTG2/9/yJ+wCDfCQ== X-Received: by 2002:a05:6871:593:b0:1bb:5ef8:d606 with SMTP id u19-20020a056871059300b001bb5ef8d606mr3430099oan.41.1690475029900; Thu, 27 Jul 2023 09:23:49 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ad06]) by smtp.gmail.com with ESMTPSA id x19-20020ac87ed3000000b004055106ee80sm519047qtj.44.2023.07.27.09.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 09:23:49 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Domenico Cerasuolo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm: zswap: kill zswap_get_swap_cache_page() Date: Thu, 27 Jul 2023 12:22:25 -0400 Message-ID: <20230727162343.1415598-4-hannes@cmpxchg.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727162343.1415598-1-hannes@cmpxchg.org> References: <20230727162343.1415598-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The __read_swap_cache_async() interface isn't more difficult to understand than what the helper abstracts. Save the indirection and a level of indentation for the primary work of the writeback func. Signed-off-by: Johannes Weiner Reviewed-by: Yosry Ahmed --- mm/zswap.c | 142 ++++++++++++++++++++--------------------------------- 1 file changed, 53 insertions(+), 89 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index e34ac89e6098..bba4ead672be 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1016,43 +1016,6 @@ static int zswap_enabled_param_set(const char *val, /********************************* * writeback code **********************************/ -/* return enum for zswap_get_swap_cache_page */ -enum zswap_get_swap_ret { - ZSWAP_SWAPCACHE_NEW, - ZSWAP_SWAPCACHE_EXIST, - ZSWAP_SWAPCACHE_FAIL, -}; - -/* - * zswap_get_swap_cache_page - * - * This is an adaption of read_swap_cache_async() - * - * This function tries to find a page with the given swap entry - * in the swapper_space address space (the swap cache). If the page - * is found, it is returned in retpage. Otherwise, a page is allocated, - * added to the swap cache, and returned in retpage. - * - * If success, the swap cache page is returned in retpage - * Returns ZSWAP_SWAPCACHE_EXIST if page was already in the swap cache - * Returns ZSWAP_SWAPCACHE_NEW if the new page needs to be populated, - * the new page is added to swapcache and locked - * Returns ZSWAP_SWAPCACHE_FAIL on error - */ -static int zswap_get_swap_cache_page(swp_entry_t entry, - struct page **retpage) -{ - bool page_was_allocated; - - *retpage =3D __read_swap_cache_async(entry, GFP_KERNEL, - NULL, 0, &page_was_allocated); - if (page_was_allocated) - return ZSWAP_SWAPCACHE_NEW; - if (!*retpage) - return ZSWAP_SWAPCACHE_FAIL; - return ZSWAP_SWAPCACHE_EXIST; -} - /* * Attempts to free an entry by adding a page to the swap cache, * decompressing the entry data into the page, and issuing a @@ -1073,7 +1036,7 @@ static int zswap_writeback_entry(struct zswap_entry *= entry, struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; struct zpool *pool =3D entry->pool->zpool; - + bool page_was_allocated; u8 *src, *tmp =3D NULL; unsigned int dlen; int ret; @@ -1088,65 +1051,66 @@ static int zswap_writeback_entry(struct zswap_entry= *entry, } =20 /* try to allocate swap cache page */ - switch (zswap_get_swap_cache_page(swpentry, &page)) { - case ZSWAP_SWAPCACHE_FAIL: /* no memory or invalidate happened */ + page =3D __read_swap_cache_async(swpentry, GFP_KERNEL, NULL, 0, + &page_was_allocated); + if (!page) { ret =3D -ENOMEM; goto fail; + } =20 - case ZSWAP_SWAPCACHE_EXIST: - /* page is already in the swap cache, ignore for now */ + /* Found an existing page, we raced with load/swapin */ + if (!page_was_allocated) { put_page(page); ret =3D -EEXIST; goto fail; + } =20 - case ZSWAP_SWAPCACHE_NEW: /* page is locked */ - /* - * Having a local reference to the zswap entry doesn't exclude - * swapping from invalidating and recycling the swap slot. Once - * the swapcache is secured against concurrent swapping to and - * from the slot, recheck that the entry is still current before - * writing. - */ - spin_lock(&tree->lock); - if (zswap_rb_search(&tree->rbroot, swp_offset(entry->swpentry)) !=3D ent= ry) { - spin_unlock(&tree->lock); - delete_from_swap_cache(page_folio(page)); - ret =3D -ENOMEM; - goto fail; - } + /* + * Page is locked, and the swapcache is now secured against + * concurrent swapping to and from the slot. Verify that the + * swap entry hasn't been invalidated and recycled behind our + * backs (our zswap_entry reference doesn't prevent that), to + * avoid overwriting a new swap page with old compressed data. + */ + spin_lock(&tree->lock); + if (zswap_rb_search(&tree->rbroot, swp_offset(entry->swpentry)) !=3D entr= y) { spin_unlock(&tree->lock); + delete_from_swap_cache(page_folio(page)); + ret =3D -ENOMEM; + goto fail; + } + spin_unlock(&tree->lock); =20 - /* decompress */ - acomp_ctx =3D raw_cpu_ptr(entry->pool->acomp_ctx); - dlen =3D PAGE_SIZE; + /* decompress */ + acomp_ctx =3D raw_cpu_ptr(entry->pool->acomp_ctx); + dlen =3D PAGE_SIZE; =20 - src =3D zpool_map_handle(pool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(pool)) { - memcpy(tmp, src, entry->length); - src =3D tmp; - zpool_unmap_handle(pool, entry->handle); - } + src =3D zpool_map_handle(pool, entry->handle, ZPOOL_MM_RO); + if (!zpool_can_sleep_mapped(pool)) { + memcpy(tmp, src, entry->length); + src =3D tmp; + zpool_unmap_handle(pool, entry->handle); + } =20 - mutex_lock(acomp_ctx->mutex); - sg_init_one(&input, src, entry->length); - sg_init_table(&output, 1); - sg_set_page(&output, page, PAGE_SIZE, 0); - acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length,= dlen); - ret =3D crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_= ctx->wait); - dlen =3D acomp_ctx->req->dlen; - mutex_unlock(acomp_ctx->mutex); - - if (!zpool_can_sleep_mapped(pool)) - kfree(tmp); - else - zpool_unmap_handle(pool, entry->handle); + mutex_lock(acomp_ctx->mutex); + sg_init_one(&input, src, entry->length); + sg_init_table(&output, 1); + sg_set_page(&output, page, PAGE_SIZE, 0); + acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, = dlen); + ret =3D crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_c= tx->wait); + dlen =3D acomp_ctx->req->dlen; + mutex_unlock(acomp_ctx->mutex); + + if (!zpool_can_sleep_mapped(pool)) + kfree(tmp); + else + zpool_unmap_handle(pool, entry->handle); =20 - BUG_ON(ret); - BUG_ON(dlen !=3D PAGE_SIZE); + BUG_ON(ret); + BUG_ON(dlen !=3D PAGE_SIZE); =20 - /* page is up to date */ - SetPageUptodate(page); - } + /* page is up to date */ + SetPageUptodate(page); =20 /* move it to the tail of the inactive list after end_writeback */ SetPageReclaim(page); @@ -1157,16 +1121,16 @@ static int zswap_writeback_entry(struct zswap_entry= *entry, zswap_written_back_pages++; =20 return ret; + fail: if (!zpool_can_sleep_mapped(pool)) kfree(tmp); =20 /* - * if we get here due to ZSWAP_SWAPCACHE_EXIST - * a load may be happening concurrently. - * it is safe and okay to not free the entry. - * it is also okay to return !0 - */ + * 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 ret; } =20 --=20 2.41.0