Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp481563rdb; Fri, 6 Oct 2023 09:00:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJ7l+ou0oH+3ahU/WQAC9uANE5ARFz9vaiTv+u+K4gqQWvvp+S2eBSDSSXaRaRbzfOaZwr X-Received: by 2002:a17:90b:38c7:b0:268:2164:dc93 with SMTP id nn7-20020a17090b38c700b002682164dc93mr8372941pjb.13.1696608049974; Fri, 06 Oct 2023 09:00:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696608049; cv=none; d=google.com; s=arc-20160816; b=NNVJ4F1rgbSK44qVj8w9HG+fnXYLJZEUZGBYyb4yeqzgfWEGqLm4gos9f7PRxfobK3 LnZfdKfj4l35/1R96XWdgcsi2hh5U7cGuMKd+WYFFISFSHvHcGAu4YX1r9WwyO3jQYJo Wo+8k/+xbT0rSwinbVtoeSwHETNkncWZFCs8SFfN1FP+kC+hss9syyi8PlqDxcYpwdI0 oNyg75QIKVqRjDncZowYnigMRklys9Wgiwr8MLMb+kkhx93KmzAnc3PBC7LCUqOnALlF sIU2II6USH3jlpY1shYvJH40yIBlbEn1zpDSLnzh+ne4iKy/2tPmWkBNIWU5q9z1XOlT toZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qipDY+TyShwnZedCZslVfS1LPA9lYq7Ryr1gmRWX8Wk=; fh=Ek/5Q7DC/RPg8Sq06VB6FQbB9hJIvdvotTlZAap+ibk=; b=kaudpHdmoEvYS5u3YTQ0DReZHughGGtFIQ7YsJJ/34n5m5ctdiEszlvnm5jRUFgJxT Hmy1ifcXqkaVqUo00d0a6+gPmBemraaDr31uhHUWdUHXbjGdCkKBReLzhZ/bMgfIl6cZ 7DBF95A2EOvkW+DuLQGTCYRWzmkW2rZh8PknW7VH+0gIj+jkk7SF6adHKHNpoMi+CMY4 6XQZL7xvZdyprwu8phr1R4EO0hFI+ktUwB8cf9T6MM78Hop3vWJuyS5tG3BWgQjR9xC6 GGKt14GKBJcBbFATdZg81IZMIFxSMAc/rm1Udis7DQJlO5RBFElgn8UJBq9TBseLT9Ub oQHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=f7ji7foX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id kk1-20020a17090b4a0100b0025c1d114af0si480328pjb.93.2023.10.06.09.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 09:00:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=f7ji7foX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 831958096BA7; Fri, 6 Oct 2023 09:00:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232888AbjJFQA3 (ORCPT + 99 others); Fri, 6 Oct 2023 12:00:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232873AbjJFQA1 (ORCPT ); Fri, 6 Oct 2023 12:00:27 -0400 Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE4CAAD for ; Fri, 6 Oct 2023 09:00:25 -0700 (PDT) Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-1dcead29b3eso1424900fac.3 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=vger.kernel.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=f7ji7foXE1FCJI8aT5/i5jSpXuwJ9bf/pjfj68WbvhzDBTTnQJQDOqDPre2trVwl9d vV26jHAZlqCtd1alyXVcyid9qikF61VZJPJIxeXlkrJfRe9RYtJJor1jCccuIv9OrTMT 1QldXMuAyMTS4K3O+8USesUG3YO6jppRKvQBpQ9LWaOqNTnQX7h6rQ6u8Mgk/RquZfU7 NukcpImZU3Ud0lgsvmzkqKsz4EJ3p0783BvY5dVI3krYCHABpkCK2VxLUFCbWAeThuZ4 FCCPjdTnV9QBytdUzH1HV8FejEbMA6CXFt9BzbC1euCVhE902mM0gtSVeX0OL65iFPSQ 3KjA== 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=UOHY9usUo93W/PU0XZbrnwK3HOzAHPwu6nk3DEDhLqoTMFchuXzF5oQK+lZ95J05/s wAbEIuxQAt1LKMXG1/JkMWIrTcMxeMxSspNKucQDrgCiVIFzj/QLfdy+0ic1R2yT+zSU B9Ftjp4KAM0gYuXvcMmmg4R6SFrm+hbuhYnd2dEmntKaaHTFB6Co4wkjTy2SGbJCfx3b HsO0gZS4ISuuupgJd8YNgi4d8ItVigTEiXsI4/Wkhrwl2N+0W8jL3yuCduz+XlBKb4g0 uKyGipyf2z4t9Z8kf+ZZOL9gRGUKWUWsfWNffHIZbQKq5o7TBdSvW3uYok922kN2YMZN s8Cg== X-Gm-Message-State: AOJu0Yy6r4clBg0Su7ig2mDNwDdZAG0nm5eUSxmVyS78hkugjTGOWeRF 6SDNmIyGNc+HiV5X/DtOueyDtw== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 06 Oct 2023 09:00:46 -0700 (PDT) X-Spam-Level: ** 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 --- 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; } -- 2.42.0