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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32E50C25B67 for ; Fri, 27 Oct 2023 12:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbjJ0MPB (ORCPT ); Fri, 27 Oct 2023 08:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjJ0MPA (ORCPT ); Fri, 27 Oct 2023 08:15:00 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8060FC0 for ; Fri, 27 Oct 2023 05:14:58 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C04FCC433C9; Fri, 27 Oct 2023 12:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1698408898; bh=yweH11pjm2gkm3PNekDj8758KTjpD/xeO8IbWgaENvs=; h=Subject:To:Cc:From:Date:From; b=K1pzPH55xjC6gW/xPDstzE87zYi7oh7vHu70zEzbNiNVbnpMgseeqf4pzS56jaZcy HiaDToEFYV0G1Gg8qglly2qN0Su6RvqnV23/3sUeCAyuAEfh4gLnXGPr6PleQAz/jS nJ/OkggJyJ/Lp2w7SN/BhzD9WMYakRtjSeeEGIj4= Subject: FAILED: patch "[PATCH] mm: zswap: fix pool refcount bug around shrink_worker()" failed to apply to 6.5-stable tree To: hannes@cmpxchg.org, akpm@linux-foundation.org, cerasuolodomenico@gmail.com, clm@fb.com, nphamcs@gmail.com, stable@vger.kernel.org, vitaly.wool@konsulko.com Cc: From: Date: Fri, 27 Oct 2023 14:14:52 +0200 Message-ID: <2023102752-rift-applicant-8761@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch below does not apply to the 6.5-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.5.y git checkout FETCH_HEAD git cherry-pick -x 969d63e1af3b3abe35a49b08218f3125131ac32f # git commit -s git send-email --to '' --in-reply-to '2023102752-rift-applicant-8761@gregkh' --subject-prefix 'PATCH 6.5.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 969d63e1af3b3abe35a49b08218f3125131ac32f Mon Sep 17 00:00:00 2001 From: Johannes Weiner Date: Fri, 6 Oct 2023 12:00:24 -0400 Subject: [PATCH] mm: zswap: fix pool refcount bug around shrink_worker() When a zswap store fails due to the limit, it acquires a pool reference and queues the shrinker. When the shrinker runs, it drops the reference. However, there can be multiple store attempts before the shrinker wakes up and runs once. This results in reference leaks and eventual saturation warnings for the pool refcount. Fix this by dropping the reference again when the shrinker is already queued. This ensures one reference per shrinker run. Link: https://lkml.kernel.org/r/20231006160024.170748-1-hannes@cmpxchg.org Fixes: 45190f01dd40 ("mm/zswap.c: add allocation hysteresis if pool limit is hit") Signed-off-by: Johannes Weiner Reported-by: Chris Mason Acked-by: Nhat Pham Cc: Vitaly Wool Cc: Domenico Cerasuolo Cc: [5.6+] Signed-off-by: Andrew Morton diff --git a/mm/zswap.c b/mm/zswap.c index 083c693602b8..37d2b1cb2ecb 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1383,8 +1383,8 @@ bool zswap_store(struct folio *folio) shrink: pool = zswap_pool_last_get(); - if (pool) - queue_work(shrink_wq, &pool->shrink_work); + if (pool && !queue_work(shrink_wq, &pool->shrink_work)) + zswap_pool_put(pool); goto reject; }