Skip to content

Commit 7f7ab33

Browse files
Qi ZhengTrond Myklebust
authored andcommitted
NFSv4.2: fix wrong shrinker_id
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: 95ad37f ("NFSv4.2: add client side xattr caching.") Signed-off-by: Qi Zheng <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 6ad477a commit 7f7ab33

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

fs/nfs/nfs42xattr.c

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,29 @@ static void nfs4_xattr_cache_init_once(void *p)
991991
INIT_LIST_HEAD(&cache->dispose);
992992
}
993993

994+
static int nfs4_xattr_shrinker_init(struct shrinker *shrinker,
995+
struct list_lru *lru, const char *name)
996+
{
997+
int ret = 0;
998+
999+
ret = register_shrinker(shrinker, name);
1000+
if (ret)
1001+
return ret;
1002+
1003+
ret = list_lru_init_memcg(lru, shrinker);
1004+
if (ret)
1005+
unregister_shrinker(shrinker);
1006+
1007+
return ret;
1008+
}
1009+
1010+
static void nfs4_xattr_shrinker_destroy(struct shrinker *shrinker,
1011+
struct list_lru *lru)
1012+
{
1013+
unregister_shrinker(shrinker);
1014+
list_lru_destroy(lru);
1015+
}
1016+
9941017
int __init nfs4_xattr_cache_init(void)
9951018
{
9961019
int ret = 0;
@@ -1002,56 +1025,42 @@ int __init nfs4_xattr_cache_init(void)
10021025
if (nfs4_xattr_cache_cachep == NULL)
10031026
return -ENOMEM;
10041027

1005-
ret = list_lru_init_memcg(&nfs4_xattr_large_entry_lru,
1006-
&nfs4_xattr_large_entry_shrinker);
1007-
if (ret)
1008-
goto out4;
1009-
1010-
ret = list_lru_init_memcg(&nfs4_xattr_entry_lru,
1011-
&nfs4_xattr_entry_shrinker);
1012-
if (ret)
1013-
goto out3;
1014-
1015-
ret = list_lru_init_memcg(&nfs4_xattr_cache_lru,
1016-
&nfs4_xattr_cache_shrinker);
1017-
if (ret)
1018-
goto out2;
1019-
1020-
ret = register_shrinker(&nfs4_xattr_cache_shrinker, "nfs-xattr_cache");
1028+
ret = nfs4_xattr_shrinker_init(&nfs4_xattr_cache_shrinker,
1029+
&nfs4_xattr_cache_lru,
1030+
"nfs-xattr_cache");
10211031
if (ret)
10221032
goto out1;
10231033

1024-
ret = register_shrinker(&nfs4_xattr_entry_shrinker, "nfs-xattr_entry");
1034+
ret = nfs4_xattr_shrinker_init(&nfs4_xattr_entry_shrinker,
1035+
&nfs4_xattr_entry_lru,
1036+
"nfs-xattr_entry");
10251037
if (ret)
1026-
goto out;
1038+
goto out2;
10271039

1028-
ret = register_shrinker(&nfs4_xattr_large_entry_shrinker,
1029-
"nfs-xattr_large_entry");
1040+
ret = nfs4_xattr_shrinker_init(&nfs4_xattr_large_entry_shrinker,
1041+
&nfs4_xattr_large_entry_lru,
1042+
"nfs-xattr_large_entry");
10301043
if (!ret)
10311044
return 0;
10321045

1033-
unregister_shrinker(&nfs4_xattr_entry_shrinker);
1034-
out:
1035-
unregister_shrinker(&nfs4_xattr_cache_shrinker);
1036-
out1:
1037-
list_lru_destroy(&nfs4_xattr_cache_lru);
1046+
nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker,
1047+
&nfs4_xattr_entry_lru);
10381048
out2:
1039-
list_lru_destroy(&nfs4_xattr_entry_lru);
1040-
out3:
1041-
list_lru_destroy(&nfs4_xattr_large_entry_lru);
1042-
out4:
1049+
nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker,
1050+
&nfs4_xattr_cache_lru);
1051+
out1:
10431052
kmem_cache_destroy(nfs4_xattr_cache_cachep);
10441053

10451054
return ret;
10461055
}
10471056

10481057
void nfs4_xattr_cache_exit(void)
10491058
{
1050-
unregister_shrinker(&nfs4_xattr_large_entry_shrinker);
1051-
unregister_shrinker(&nfs4_xattr_entry_shrinker);
1052-
unregister_shrinker(&nfs4_xattr_cache_shrinker);
1053-
list_lru_destroy(&nfs4_xattr_large_entry_lru);
1054-
list_lru_destroy(&nfs4_xattr_entry_lru);
1055-
list_lru_destroy(&nfs4_xattr_cache_lru);
1059+
nfs4_xattr_shrinker_destroy(&nfs4_xattr_large_entry_shrinker,
1060+
&nfs4_xattr_large_entry_lru);
1061+
nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker,
1062+
&nfs4_xattr_entry_lru);
1063+
nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker,
1064+
&nfs4_xattr_cache_lru);
10561065
kmem_cache_destroy(nfs4_xattr_cache_cachep);
10571066
}

0 commit comments

Comments
 (0)