Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2306709rwd; Wed, 14 Jun 2023 00:33:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Nj0kd27FmSSaF+xmN/pnKFdXwFNeJ6sbMVDbMOdKt+EuJpPxjUdcsJJu/z6+Hn6ugdxSv X-Received: by 2002:a05:6a20:1683:b0:10b:6265:6ddc with SMTP id q3-20020a056a20168300b0010b62656ddcmr567154pzc.22.1686728000741; Wed, 14 Jun 2023 00:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686728000; cv=none; d=google.com; s=arc-20160816; b=NCB+RbxcTCOkcmG4IsHJNtbZPImKZNu3EF4BpAvoAaTIUqQlMmHlzliBB+4G8RFUR0 k9ue2rHZAGnnaqC9xTFwMxFRIIO1VrbtY2gh2fF1uWotqDbrTSIh32YwZxuhDqlvzaxp pJlnseywsuoYtcXGtD/75oUOhaRaOVbWY+gGuFboyuwKzhd7dzSIwsftQVDGkpuIXiBt rdFDQXL3Fxqv2zHxeM8VMybtpfmRPXMUK+CaekBnX+LeTO1ugKA9Prfloax0jwc92W1W uqRU5SbA9BX7hBByJx38r6yeGEfS63M9fsjqtHvZtiRH+DmG/aTF40w99mJbtebd5eb/ 8hQw== 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=cnZA6R5dhheCWRN7S5Aij6O41OaBmn26JHiRPtLWJrg=; b=lxeUXtqcq/sB/pyrniSd0Fcz+EG6c9njzmRYRTvlsb3gWfvwPuE5DKxinSqUolAH/8 9OoN1vfIBce8pRsTCKbeDav/0mh7jwwGPjFEAJ2mZPA/NnLaD+HPl9QK3zMwW1ABONxD UOfAwfxlkygvtfwHVy8eY6vk8kF7Nr/pxnNXPC4gSjyotIfSDkn3ZDuryj1RwelwcdB6 qm6E6AT8CVnFr7Z/ZohfMkv27kVGHGNa/PeIr4gf6At8e+YUzDvIg2oAf5pitn2XrJOO 0p5WoRTXbvDakvUx1DeRWL46sBtRJmvuHpQ8iRZr1MRAjd6yw/8PMCODynqcskN4uLfY b6KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ozbiDhej; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t1-20020a170902e1c100b001b3eeaad177si2581188pla.99.2023.06.14.00.32.53; Wed, 14 Jun 2023 00:33:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ozbiDhej; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235394AbjFNHcv (ORCPT + 99 others); Wed, 14 Jun 2023 03:32:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234394AbjFNHct (ORCPT ); Wed, 14 Jun 2023 03:32:49 -0400 X-Greylist: delayed 442 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 14 Jun 2023 00:32:48 PDT Received: from out-4.mta0.migadu.com (out-4.mta0.migadu.com [IPv6:2001:41d0:1004:224b::4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8DC6E62 for ; Wed, 14 Jun 2023 00:32:48 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1686727524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cnZA6R5dhheCWRN7S5Aij6O41OaBmn26JHiRPtLWJrg=; b=ozbiDhejsVX0xqtk/O4xv5w7K/gwHY1rgEvgaeo+TfiYYiYot7jzITkhjVudTO2dF4tYTX zEW/hLIqxsqOhsY7gVLd8KAI9ZWT2PvKq3oDX/LHEKyjh5I8CDBv1/iUFSf0DH1q/BmntT Barc9KHGTM0FcAPUalkd/va76Mdcvvc= From: Qi Zheng To: trond.myklebust@hammerspace.com, anna@kernel.org, fllinden@amazon.com Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH] NFSv4.2: fix wrong shrinker_id Date: Wed, 14 Jun 2023 07:24:43 +0000 Message-Id: <20230614072443.3264264-1-qi.zheng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Qi Zheng Currently, the list_lru::shrinker_id corresponding to the nfs4_xattr shrinkers is wrong: >>> prog["nfs4_xattr_cache_lru"].shrinker_id (int)0 >>> prog["nfs4_xattr_entry_lru"].shrinker_id (int)0 >>> prog["nfs4_xattr_large_entry_lru"].shrinker_id (int)0 >>> prog["nfs4_xattr_cache_shrinker"].id (int)18 >>> prog["nfs4_xattr_entry_shrinker"].id (int)19 >>> prog["nfs4_xattr_large_entry_shrinker"].id (int)20 This is not what we expect, which will cause these shrinkers not to be found in shrink_slab_memcg(). We should assign shrinker::id before calling list_lru_init_memcg(), so that the corresponding list_lru::shrinker_id will be assigned the correct value like below: >>> prog["nfs4_xattr_cache_lru"].shrinker_id (int)16 >>> prog["nfs4_xattr_entry_lru"].shrinker_id (int)17 >>> prog["nfs4_xattr_large_entry_lru"].shrinker_id (int)18 >>> prog["nfs4_xattr_cache_shrinker"].id (int)16 >>> prog["nfs4_xattr_entry_shrinker"].id (int)17 >>> prog["nfs4_xattr_large_entry_shrinker"].id (int)18 So just do it. Fixes: 95ad37f90c33 ("NFSv4.2: add client side xattr caching.") Signed-off-by: Qi Zheng --- fs/nfs/nfs42xattr.c | 83 ++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/fs/nfs/nfs42xattr.c b/fs/nfs/nfs42xattr.c index 76ae11834206..e3dab0131e4c 100644 --- a/fs/nfs/nfs42xattr.c +++ b/fs/nfs/nfs42xattr.c @@ -991,6 +991,33 @@ static void nfs4_xattr_cache_init_once(void *p) INIT_LIST_HEAD(&cache->dispose); } +static int nfs4_xattr_shrinker_init(struct shrinker *shrinker, + struct list_lru *lru, const char *name) +{ + int ret = 0; + + ret = prealloc_shrinker(shrinker, name); + if (ret) + return ret; + + ret = list_lru_init_memcg(lru, shrinker); + if (ret) { + free_prealloced_shrinker(shrinker); + return ret; + } + + register_shrinker_prepared(shrinker); + + return 0; +} + +static void nfs4_xattr_shrinker_destroy(struct shrinker *shrinker, + struct list_lru *lru) +{ + unregister_shrinker(shrinker); + list_lru_destroy(lru); +} + int __init nfs4_xattr_cache_init(void) { int ret = 0; @@ -1002,44 +1029,30 @@ int __init nfs4_xattr_cache_init(void) if (nfs4_xattr_cache_cachep == NULL) return -ENOMEM; - ret = list_lru_init_memcg(&nfs4_xattr_large_entry_lru, - &nfs4_xattr_large_entry_shrinker); - if (ret) - goto out4; - - ret = list_lru_init_memcg(&nfs4_xattr_entry_lru, - &nfs4_xattr_entry_shrinker); - if (ret) - goto out3; - - ret = list_lru_init_memcg(&nfs4_xattr_cache_lru, - &nfs4_xattr_cache_shrinker); - if (ret) - goto out2; - - ret = register_shrinker(&nfs4_xattr_cache_shrinker, "nfs-xattr_cache"); + ret = nfs4_xattr_shrinker_init(&nfs4_xattr_cache_shrinker, + &nfs4_xattr_cache_lru, + "nfs-xattr_cache"); if (ret) goto out1; - ret = register_shrinker(&nfs4_xattr_entry_shrinker, "nfs-xattr_entry"); + ret = nfs4_xattr_shrinker_init(&nfs4_xattr_entry_shrinker, + &nfs4_xattr_entry_lru, + "nfs-xattr_entry"); if (ret) - goto out; + goto out2; - ret = register_shrinker(&nfs4_xattr_large_entry_shrinker, - "nfs-xattr_large_entry"); + ret = nfs4_xattr_shrinker_init(&nfs4_xattr_large_entry_shrinker, + &nfs4_xattr_large_entry_lru, + "nfs-xattr_large_entry"); if (!ret) return 0; - unregister_shrinker(&nfs4_xattr_entry_shrinker); -out: - unregister_shrinker(&nfs4_xattr_cache_shrinker); -out1: - list_lru_destroy(&nfs4_xattr_cache_lru); + nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker, + &nfs4_xattr_entry_lru); out2: - list_lru_destroy(&nfs4_xattr_entry_lru); -out3: - list_lru_destroy(&nfs4_xattr_large_entry_lru); -out4: + nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker, + &nfs4_xattr_cache_lru); +out1: kmem_cache_destroy(nfs4_xattr_cache_cachep); return ret; @@ -1047,11 +1060,11 @@ int __init nfs4_xattr_cache_init(void) void nfs4_xattr_cache_exit(void) { - unregister_shrinker(&nfs4_xattr_large_entry_shrinker); - unregister_shrinker(&nfs4_xattr_entry_shrinker); - unregister_shrinker(&nfs4_xattr_cache_shrinker); - list_lru_destroy(&nfs4_xattr_large_entry_lru); - list_lru_destroy(&nfs4_xattr_entry_lru); - list_lru_destroy(&nfs4_xattr_cache_lru); + nfs4_xattr_shrinker_destroy(&nfs4_xattr_large_entry_shrinker, + &nfs4_xattr_large_entry_lru); + nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker, + &nfs4_xattr_entry_lru); + nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker, + &nfs4_xattr_cache_lru); kmem_cache_destroy(nfs4_xattr_cache_cachep); } -- 2.30.2