From patchwork Wed Jun 14 07:24:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 107767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1063242vqr; Wed, 14 Jun 2023 00:41:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ78Jk+d6kAyj7XtM3YvJTQaeTu6B3ILvci6zNOhGAAHcB3azTNFUhvqcgdWoCGAOHL2HSUu X-Received: by 2002:a17:907:6d8e:b0:973:940e:a01b with SMTP id sb14-20020a1709076d8e00b00973940ea01bmr16545513ejc.60.1686728469145; Wed, 14 Jun 2023 00:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686728469; cv=none; d=google.com; s=arc-20160816; b=aqOCWJx5aG4Z53nkoGqi3zzUiFjIvhoGxZxfJAki6BV4gv/ztGR0g7xaaBYx6TzR61 fmXAng54sgtoULLQMoEJP0Kma/ULOjBktR1eLu7Qx8Vqb2c6N4dJbUjN3KFJfc7ylZ6R oSaWT0Mm7OURNiRBMIjOJFYQ3xOweE9PqD+tP+IcTiUq5hedDK0AWSaYHzy96Dv9szq/ vrsJXGRWP9Hf7Z5iRd3dQwNziNlA7ajtu94K8rke64Zlec0W7n49JKly20Pgtv3hqBsM qjE4UyCCQOJxkcLGfQpoLNJej2EEriYJKfIyX5ikImNOQuhptY8J57dEscVbvaaMVonJ sK8w== 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=BZafq2gcnb7j+H2E/vMZc0nX9aLnL958qpHAnWtaM0LP1rdugAO4OWUnPaFaeXRj8r xaIvl5u9NgcUXI8Vo1/M5qfvVQYx6dyZzKdJI2qrNBDZMdCsU/55Ktr9b4UfqQsqwmA4 M4p6AZgM3QPKvV2kPjvIcM3jkPH1/tVxW4LbP9MRVaazb1J6y7CARePuWscPUT8QKFNh AfYamExaybj6eApiJ1dBNayFzNHwpkfA3BO39gGLT/ysxknYwHc9xU7NWcew3EI8hBwa 8Qr2YJDH5+F1DuYFrBWo2D6JLKzSn/cuM2EnptQBGQcUNsUGu0ahV0z+vDc9a5DR9Xz2 q2mQ== 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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e21-20020a170906249500b00977d84435c8si4796114ejb.933.2023.06.14.00.40.39; Wed, 14 Jun 2023 00:41:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S243369AbjFNH1F (ORCPT + 99 others); Wed, 14 Jun 2023 03:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243655AbjFNHZ3 (ORCPT ); Wed, 14 Jun 2023 03:25:29 -0400 Received: from out-22.mta0.migadu.com (out-22.mta0.migadu.com [IPv6:2001:41d0:1004:224b::16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 717D31FC4 for ; Wed, 14 Jun 2023 00:25:26 -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 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=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768662991468568685?= X-GMAIL-MSGID: =?utf-8?q?1768662991468568685?= 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); }