From patchwork Fri Oct 6 16:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13411719 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 34029E81E13 for ; Fri, 6 Oct 2023 16:00:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43EB58D00CD; Fri, 6 Oct 2023 12:00:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C7D08D00C9; Fri, 6 Oct 2023 12:00:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 268488D00CD; Fri, 6 Oct 2023 12:00:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 114F78D00C9 for ; Fri, 6 Oct 2023 12:00:30 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 761DFC02D7 for ; Fri, 6 Oct 2023 16:00:29 +0000 (UTC) X-FDA: 81315498978.20.1D534F1 Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.52]) by imf04.hostedemail.com (Postfix) with ESMTP id 4A97340033 for ; Fri, 6 Oct 2023 16:00:26 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=wQbXxJy8; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf04.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.52 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696608026; 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=qipDY+TyShwnZedCZslVfS1LPA9lYq7Ryr1gmRWX8Wk=; b=gPRS0JG6Zp1WLXX7Vvc4/sQWqhrh6ACK77poyyuG6+Rc55w9qfpMoPrrazYIZyMFv3r+kP gvg0DiVxVg6VubaHSrCBrCg2YCh4BlcAjfhGbTBH+W9iPUsWUc5+QhrThmnCN7EtGB+3Eg KTDAw/zOi5zFdrqwqY2RjMLvBDjBze8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=wQbXxJy8; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf04.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.52 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696608026; a=rsa-sha256; cv=none; b=cecHcQ6YUGBZyM8TqfP5AbPXZ4Li9JQv64p1mmMGxy1A0DhtEH7Fg9LVmo2UfaE2hRyl8i 8yHalktAX1rCzZvXzFTMK+l67WkC4mttQoBDrsam3c/WPCTqAkwEVaoRlrbnfV1oCBCbfs YH8G8CEgk3e35wnnQV9/Zr96OG4YDPc= Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-1e562706d29so1183884fac.2 for ; Fri, 06 Oct 2023 09:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1696608025; x=1697212825; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qipDY+TyShwnZedCZslVfS1LPA9lYq7Ryr1gmRWX8Wk=; b=wQbXxJy8f9Jhz5IVMABSOn+vckBU2V9nfg1ZNNHsRHzTQAKUhPPesgJkL7+FxIpytp J+NyVe+Rus1IBvbtmDvIQKiMseFQbeFSEoX2PsRMf14RAC1nfiUqLMr9JQr/QVXI6rZ/ OZRlKDDJX25zxG4xC69UDDNA1lAbxLAH7Pqj24RvwYDE7N82DbFvceE0RR1cLupAgOgQ mwZyV3aIxgbDwfjUMdAvTbGiUX50XWVMPc3qFkGA7YhU8vcFYoEpyYOFA19i5SKVoUKM 3E+ruM4VHTXjlM8dO5Fc06JyD6CxzLWCMtsJUGmap4+rVRPMMlE6j+Mg3SGcmAuojkbS LOng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696608025; x=1697212825; 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=qipDY+TyShwnZedCZslVfS1LPA9lYq7Ryr1gmRWX8Wk=; b=aepsN3muUS4MK8uhYrpFzWgtZxGJrw0u9+VHQYfM8CUVwV9FVsEZDl5g31rPlY9iD/ B85cUweIEDHILoWKTWpb2JRNghLomsktmG908EMTtasFQmMN8hVce55FWvd9jH+3GqzS tkmYIQfSQZSdVyauWXvOkVgOqx8bKn9cLgWEcuqgZO17Jr8IE2Rqn8qeV0OAw0T+QCPh uOYAumnLgIwcm0lb/BlvW6LObCVhDyni0wy2A6SgxZIeFYl9Wzg4nqicE5Qv3WHeKne5 m3H2jpKp6QWV/R0BcxiigI8NUS3NL8FpFVRpTHVhmN1XocP4cFqAoY86WgbjXqYjURtk BDag== X-Gm-Message-State: AOJu0Yzb88ToTR7vxTPIm/A4mNYWNePLGyLklfgdC0iYenARYb8JY5Ai PmMVS49z4DF4fst5+7vsh49eBw== X-Google-Smtp-Source: AGHT+IFcrDjjLybvUkweHij+P/eiaXeTS/GeNwh9ZIJUxL310AKztCl3NLTVHG9Tj3lqj+S9iQZQJg== X-Received: by 2002:a05:6870:8294:b0:1db:3679:198a with SMTP id q20-20020a056870829400b001db3679198amr9905667oae.24.1696608025151; Fri, 06 Oct 2023 09:00:25 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:753d]) by smtp.gmail.com with ESMTPSA id o16-20020a0ccb10000000b00656506a1881sm1485256qvk.74.2023.10.06.09.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 09:00:24 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Mason , stable@vger.kernel.org, Vitaly Wool , Domenico Cerasuolo , Nhat Pham Subject: [PATCH] mm: zswap: fix pool refcount bug around shrink_worker() Date: Fri, 6 Oct 2023 12:00:24 -0400 Message-ID: <20231006160024.170748-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4A97340033 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: qw5wcpu43qj5nr6qbpdq38ba7qp1zde6 X-HE-Tag: 1696608026-924793 X-HE-Meta: U2FsdGVkX1/vx8Aqngd+dHJNTwKlMTHYYRGJ8vd0BXdDgtNAf2ZnhofFoKRMRkP0FDAYxCntwKwJvzzJDEYqHx404q/s5pW7jKKyytIOPyaIHBKqPyz6qqEzVxv5TO4vO1i3SWSB+JuGiOX22B+iFdeLkFIwzd+sYHBXxgeZd1UK5S3LePBWWBMRreINeJCDeb2jnX5iWRAF6Ky1xPP+KxDJLa/PEePeqwVbORORGtlRsZMJBwASD3YVs5rmSERxwo/EUfIhD4s4s030OFn2W1ViDmM4KcW4WtRbTNiMnPrUS23CYAp28DGBeD2waneb0VtcLbj66GCFZ9Do0d+P0/IK+UnTGt8qNr/bIZrtNl76LgBOSNKRgNLzyIeGfp0R2jH1gq5MM9J4OdW9T5114yscpSF8b7h9ng9WReyvoorUfS3GhRfZRaANspDK38z82MOeYamv7AE6UOK/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buXife2zSaELhFOmtWyDUsW6COMPQnBEa5eZTLrB0B1je8xQWgfNs0wHRoL3UUBDQeJDkqMlG/tsdiyt6hpUaWSlyQgFDmjeRi0GSFpdWPh1kE/zH3yjObIR2o+FDfX2OpLezr2hRad6sVY0hSlOo2KUPxoGbALc8CUEtKtfFSV4A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Reported-by: Chris Mason Fixes: 45190f01dd40 ("mm/zswap.c: add allocation hysteresis if pool limit is hit") Cc: stable@vger.kernel.org [5.6+] Cc: Vitaly Wool Cc: Domenico Cerasuolo Cc: Nhat Pham Signed-off-by: Johannes Weiner Acked-by: Nhat Pham --- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; }