Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp653241rdb; Fri, 6 Oct 2023 14:42:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQiiveeCvzUf/TODaN+zojnmgmbGE1d5efkqNXoRuH57myFo9Jw6iSt0j+46/NSL8Sz9Uw X-Received: by 2002:a05:6a21:6d9b:b0:14d:e615:277c with SMTP id wl27-20020a056a216d9b00b0014de615277cmr9942125pzb.11.1696628551100; Fri, 06 Oct 2023 14:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696628551; cv=none; d=google.com; s=arc-20160816; b=kJ4/+/K/dco00cDKXMa1je1MS3MWX0pJnWm9pS2fudGZ4zTozHMqkJLdtfX0G909qm V4zehDI1803HRLuAvv6G60l2GFecTKOZbMnvK6mxzhqQEPK+S/TGy9PwOKXSTNa+QGQe 4RFoZeCMcg+3pyO3zokyH06UTX3VI3DFEmTwrkmlhnxWkc1sHyiaz8v+0fyGNOBZ/I8L u33i3lBhDHJEDX7s3xyXHzEgTIbciBhH6bjbrfl1pFfqy3sACEm0onouo2PAue/PIAfN auJNmyNSXcLLYY/qxUYP2w8Lg4lYpYaezZQjUJdFrFC2ShfMP9LFXOF3cCWD4WFA1bBe 4Dpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=4EmFZA6ZudbHCtkJzwnbsAak5FQyVkG6XojscroYQT8=; fh=K/Z36wQYHXD7hHUoh1zycitynQ/4C7L+ysiOV0mbMqU=; b=OeGHNPvt4XXycMRdqaFXAJoRUH6AUwlSCEZlEOtMWe85Eu5r54ARcZPkS8JLOgi/AK bh3hzxK66zNH9X9POqINn6wkjdISYaucAmhfBhlOQSqKegIxvdeafka/5a30wntiySXN r7pThvyRAlJLQjscu41vv7scn7UEjmA4msv5V1YeolC49TXnuxrO1WkQ9FSI2zF04gOr MlnVKobCdj9l8d9pP5U0sf12tXeFftxVVU0sjd5+9FtY5QiIGq8f3rJbEklUQJGseTaA oFxD7n1Xcn6oiJrZjq/n5U+yZH9w44KGOVGHkoRVXkwI968c7md6IYknfBii2FZ0S4eI 24nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="ZU6Q/6F8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id k187-20020a6324c4000000b00578b21f1890si4500796pgk.294.2023.10.06.14.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 14:42:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="ZU6Q/6F8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id CB1E9807D8C8; Fri, 6 Oct 2023 14:41:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233413AbjJFVlF (ORCPT + 99 others); Fri, 6 Oct 2023 17:41:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233710AbjJFVlB (ORCPT ); Fri, 6 Oct 2023 17:41:01 -0400 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C563BD; Fri, 6 Oct 2023 14:41:00 -0700 (PDT) Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-35164833a21so11146215ab.0; Fri, 06 Oct 2023 14:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696628459; x=1697233259; darn=vger.kernel.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=4EmFZA6ZudbHCtkJzwnbsAak5FQyVkG6XojscroYQT8=; b=ZU6Q/6F8366DRFjnozMnQTOnZby3B4xsOyyx6bTH8VpC28IQCjXG9E4oBLOlug0DtN m0PjIHaggoTzIFg+mryuBvtMmlfdp9pdA1rQ0FWeprBHST2zDTyjca1rKdHDYyhiupum 4WEv9yNmNxQAq/JIUsE9gg5DVLpgGysWwLxOyuvoDXTyZ7fUGGb9HFTZR2UnM9etsv4q mSnoML3MA/0HnX7x6GPPU5TNeKwm9ebcb0a2NJhMPbixxRZ50C/H1xNUhtqBaiYqAkY4 chlm4rcQ+6bRWMMSKZNVJkfZwJkiCyeU93r2apoyqr97n8JFrCVt3s8WIO1PMO96Srby +3dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696628459; x=1697233259; 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=4EmFZA6ZudbHCtkJzwnbsAak5FQyVkG6XojscroYQT8=; b=NHAdrCIOePTjtTVK1RhHXLoRyIASd7gHd2Wv7+YnSH48fY767i8w2+4NoOVxLRh9nh on/lCd7xLEbZkIDZJr7pnmZwylwU+kN5I7n3k7QSms5b/dtgtzTr5fS5ANJKgF+V9nyd fsjl3yMTVEhoDcFkhx2C5pA8TEaQ/bw+T7kP8uKoBWe+4pFgQDSYpWLctXwWlnFlrG1Z eh4yGBExH+o2ebdZ83+HcC+pLva2Dg+D+pflcAH/+CtKtszJ5nhl2kr6Fmk1erIvD73r eg/sZhii1WgbckMAsNX7177XffRE1rj7yGmYTki/BNM42zg/5Y7H3tyWjBnxFEtcOcQC alLA== X-Gm-Message-State: AOJu0Yyd8UG2GTz+Ldge5BwuREzOEtB/Rpj7XrPCz+UbZLeKROM08J4L MWf199jIzlye4zgfpLeNn0ycPC1XOJ5PVbjK98M= X-Received: by 2002:a05:6e02:1a05:b0:351:375f:2a31 with SMTP id s5-20020a056e021a0500b00351375f2a31mr4529823ild.6.1696628459466; Fri, 06 Oct 2023 14:40:59 -0700 (PDT) MIME-Version: 1.0 References: <20231006160024.170748-1-hannes@cmpxchg.org> In-Reply-To: <20231006160024.170748-1-hannes@cmpxchg.org> From: Nhat Pham Date: Fri, 6 Oct 2023 14:40:48 -0700 Message-ID: Subject: Re: [PATCH] mm: zswap: fix pool refcount bug around shrink_worker() To: Johannes Weiner Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Mason , stable@vger.kernel.org, Vitaly Wool , Domenico Cerasuolo Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 06 Oct 2023 14:41:20 -0700 (PDT) X-Spam-Level: ** On Fri, Oct 6, 2023 at 9:00=E2=80=AFAM Johannes Weiner = wrote: > > 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 =3D 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 > Acked-by: Nhat Pham Random tangent: this asynchronous writeback mechanism is always kinda weird to me. We could have quite a bit of memory inversion before the shrinker finally kicks in and frees up zswap pool space. But I guess if it doesn't break then don't fix it. Maybe a shrinker that proactively writes pages back as memory pressure builds up could help ;)