Skip to content

Commit

Permalink
NFSv4.2: dynamically allocate the nfs-xattr shrinkers
Browse files Browse the repository at this point in the history
Use new APIs to dynamically allocate the nfs-xattr shrinkers.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Qi Zheng <[email protected]>
Reviewed-by: Muchun Song <[email protected]>
Cc: Trond Myklebust <[email protected]>
Cc: Anna Schumaker <[email protected]>
Cc: Abhinav Kumar <[email protected]>
Cc: Alasdair Kergon <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Alyssa Rosenzweig <[email protected]>
Cc: Andreas Dilger <[email protected]>
Cc: Andreas Gruenbacher <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bob Peterson <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Carlos Llamas <[email protected]>
Cc: Chandan Babu R <[email protected]>
Cc: Chao Yu <[email protected]>
Cc: Chris Mason <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Christian Koenig <[email protected]>
Cc: Chuck Lever <[email protected]>
Cc: Coly Li <[email protected]>
Cc: Dai Ngo <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: "Darrick J. Wong" <[email protected]>
Cc: Dave Chinner <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: David Airlie <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: David Sterba <[email protected]>
Cc: Dmitry Baryshkov <[email protected]>
Cc: Gao Xiang <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Huang Rui <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jaegeuk Kim <[email protected]>
Cc: Jani Nikula <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: Jeff Layton <[email protected]>
Cc: Jeffle Xu <[email protected]>
Cc: Joel Fernandes (Google) <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
Cc: Josef Bacik <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: Kirill Tkhai <[email protected]>
Cc: Marijn Suijten <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Mike Snitzer <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Muchun Song <[email protected]>
Cc: Nadav Amit <[email protected]>
Cc: Neil Brown <[email protected]>
Cc: Oleksandr Tyshchenko <[email protected]>
Cc: Olga Kornievskaia <[email protected]>
Cc: Paul E. McKenney <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Rob Clark <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Rodrigo Vivi <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Sean Paul <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Steven Price <[email protected]>
Cc: "Theodore Ts'o" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Tomeu Vizoso <[email protected]>
Cc: Tom Talpey <[email protected]>
Cc: Tvrtko Ursulin <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Xuan Zhuo <[email protected]>
Cc: Yue Hu <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Qi Zheng authored and akpm00 committed Oct 4, 2023
1 parent 8ee0fd9 commit d5dad49
Showing 1 changed file with 44 additions and 43 deletions.
87 changes: 44 additions & 43 deletions fs/nfs/nfs42xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,28 +796,9 @@ static unsigned long nfs4_xattr_cache_scan(struct shrinker *shrink,
static unsigned long nfs4_xattr_entry_scan(struct shrinker *shrink,
struct shrink_control *sc);

static struct shrinker nfs4_xattr_cache_shrinker = {
.count_objects = nfs4_xattr_cache_count,
.scan_objects = nfs4_xattr_cache_scan,
.seeks = DEFAULT_SEEKS,
.flags = SHRINKER_MEMCG_AWARE,
};

static struct shrinker nfs4_xattr_entry_shrinker = {
.count_objects = nfs4_xattr_entry_count,
.scan_objects = nfs4_xattr_entry_scan,
.seeks = DEFAULT_SEEKS,
.batch = 512,
.flags = SHRINKER_MEMCG_AWARE,
};

static struct shrinker nfs4_xattr_large_entry_shrinker = {
.count_objects = nfs4_xattr_entry_count,
.scan_objects = nfs4_xattr_entry_scan,
.seeks = 1,
.batch = 512,
.flags = SHRINKER_MEMCG_AWARE,
};
static struct shrinker *nfs4_xattr_cache_shrinker;
static struct shrinker *nfs4_xattr_entry_shrinker;
static struct shrinker *nfs4_xattr_large_entry_shrinker;

static enum lru_status
cache_lru_isolate(struct list_head *item,
Expand Down Expand Up @@ -943,7 +924,7 @@ nfs4_xattr_entry_scan(struct shrinker *shrink, struct shrink_control *sc)
struct nfs4_xattr_entry *entry;
struct list_lru *lru;

lru = (shrink == &nfs4_xattr_large_entry_shrinker) ?
lru = (shrink == nfs4_xattr_large_entry_shrinker) ?
&nfs4_xattr_large_entry_lru : &nfs4_xattr_entry_lru;

freed = list_lru_shrink_walk(lru, sc, entry_lru_isolate, &dispose);
Expand Down Expand Up @@ -971,7 +952,7 @@ nfs4_xattr_entry_count(struct shrinker *shrink, struct shrink_control *sc)
unsigned long count;
struct list_lru *lru;

lru = (shrink == &nfs4_xattr_large_entry_shrinker) ?
lru = (shrink == nfs4_xattr_large_entry_shrinker) ?
&nfs4_xattr_large_entry_lru : &nfs4_xattr_entry_lru;

count = list_lru_shrink_count(lru, sc);
Expand All @@ -991,26 +972,42 @@ 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)
typedef unsigned long (*count_objects_cb)(struct shrinker *s,
struct shrink_control *sc);
typedef unsigned long (*scan_objects_cb)(struct shrinker *s,
struct shrink_control *sc);

static int __init nfs4_xattr_shrinker_init(struct shrinker **shrinker,
struct list_lru *lru, const char *name,
count_objects_cb count,
scan_objects_cb scan, long batch, int seeks)
{
int ret = 0;
int ret;

ret = register_shrinker(shrinker, name);
if (ret)
*shrinker = shrinker_alloc(SHRINKER_MEMCG_AWARE, name);
if (!*shrinker)
return -ENOMEM;

ret = list_lru_init_memcg(lru, *shrinker);
if (ret) {
shrinker_free(*shrinker);
return ret;
}

ret = list_lru_init_memcg(lru, shrinker);
if (ret)
unregister_shrinker(shrinker);
(*shrinker)->count_objects = count;
(*shrinker)->scan_objects = scan;
(*shrinker)->batch = batch;
(*shrinker)->seeks = seeks;

shrinker_register(*shrinker);

return ret;
}

static void nfs4_xattr_shrinker_destroy(struct shrinker *shrinker,
struct list_lru *lru)
{
unregister_shrinker(shrinker);
shrinker_free(shrinker);
list_lru_destroy(lru);
}

Expand All @@ -1026,27 +1023,31 @@ int __init nfs4_xattr_cache_init(void)
return -ENOMEM;

ret = nfs4_xattr_shrinker_init(&nfs4_xattr_cache_shrinker,
&nfs4_xattr_cache_lru,
"nfs-xattr_cache");
&nfs4_xattr_cache_lru, "nfs-xattr_cache",
nfs4_xattr_cache_count,
nfs4_xattr_cache_scan, 0, DEFAULT_SEEKS);
if (ret)
goto out1;

ret = nfs4_xattr_shrinker_init(&nfs4_xattr_entry_shrinker,
&nfs4_xattr_entry_lru,
"nfs-xattr_entry");
&nfs4_xattr_entry_lru, "nfs-xattr_entry",
nfs4_xattr_entry_count,
nfs4_xattr_entry_scan, 512, DEFAULT_SEEKS);
if (ret)
goto out2;

ret = nfs4_xattr_shrinker_init(&nfs4_xattr_large_entry_shrinker,
&nfs4_xattr_large_entry_lru,
"nfs-xattr_large_entry");
"nfs-xattr_large_entry",
nfs4_xattr_entry_count,
nfs4_xattr_entry_scan, 512, 1);
if (!ret)
return 0;

nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker,
nfs4_xattr_shrinker_destroy(nfs4_xattr_entry_shrinker,
&nfs4_xattr_entry_lru);
out2:
nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker,
nfs4_xattr_shrinker_destroy(nfs4_xattr_cache_shrinker,
&nfs4_xattr_cache_lru);
out1:
kmem_cache_destroy(nfs4_xattr_cache_cachep);
Expand All @@ -1056,11 +1057,11 @@ int __init nfs4_xattr_cache_init(void)

void nfs4_xattr_cache_exit(void)
{
nfs4_xattr_shrinker_destroy(&nfs4_xattr_large_entry_shrinker,
nfs4_xattr_shrinker_destroy(nfs4_xattr_large_entry_shrinker,
&nfs4_xattr_large_entry_lru);
nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker,
nfs4_xattr_shrinker_destroy(nfs4_xattr_entry_shrinker,
&nfs4_xattr_entry_lru);
nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker,
nfs4_xattr_shrinker_destroy(nfs4_xattr_cache_shrinker,
&nfs4_xattr_cache_lru);
kmem_cache_destroy(nfs4_xattr_cache_cachep);
}

0 comments on commit d5dad49

Please sign in to comment.