[PATCH v8 08/17] fs: Propagate shrinker::id to list_lru
From: Kirill Tkhai
Date: Tue Jul 03 2018 - 11:10:14 EST
The patch adds list_lru::shrinker_id field, and populates
it by registered shrinker id.
This will be used to set correct bit in memcg shrinkers
map by lru code in next patches, after there appeared
the first related to memcg element in list_lru.
Signed-off-by: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx>
Acked-by: Vladimir Davydov <vdavydov.dev@xxxxxxxxx>
Tested-by: Shakeel Butt <shakeelb@xxxxxxxxxx>
---
fs/super.c | 4 ++--
include/linux/list_lru.h | 17 +++++++++--------
mm/list_lru.c | 11 ++++++++++-
mm/workingset.c | 3 ++-
4 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/fs/super.c b/fs/super.c
index 002e46d874da..f858178f74fe 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -260,9 +260,9 @@ static struct super_block *alloc_super(struct fs_context *fc)
s->s_shrink.flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE;
if (prealloc_shrinker(&s->s_shrink))
goto fail;
- if (list_lru_init_memcg(&s->s_dentry_lru))
+ if (list_lru_init_memcg(&s->s_dentry_lru, &s->s_shrink))
goto fail;
- if (list_lru_init_memcg(&s->s_inode_lru))
+ if (list_lru_init_memcg(&s->s_inode_lru, &s->s_shrink))
goto fail;
return s;
diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
index 5d7f951f4f32..c4cdda4dffa0 100644
--- a/include/linux/list_lru.h
+++ b/include/linux/list_lru.h
@@ -54,19 +54,20 @@ struct list_lru {
bool lock_irq;
#ifdef CONFIG_MEMCG_KMEM
struct list_head list;
+ int shrinker_id;
#endif
};
void list_lru_destroy(struct list_lru *lru);
int __list_lru_init(struct list_lru *lru, bool memcg_aware, bool lock_irq,
- struct lock_class_key *key);
-
-#define list_lru_init(lru) __list_lru_init((lru), false, false, \
- NULL)
-#define list_lru_init_key(lru, key) __list_lru_init((lru), false, false, \
- (key))
-#define list_lru_init_memcg(lru) __list_lru_init((lru), true, false, \
- NULL)
+ struct lock_class_key *key, struct shrinker *shrinker);
+
+#define list_lru_init(lru) \
+ __list_lru_init((lru), false, false, NULL, NULL)
+#define list_lru_init_key(lru, key) \
+ __list_lru_init((lru), false, false, (key), NULL)
+#define list_lru_init_memcg(lru, shrinker) \
+ __list_lru_init((lru), true, false, NULL, shrinker)
int memcg_update_all_list_lrus(int num_memcgs);
void memcg_drain_all_list_lrus(int src_idx, int dst_idx);
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 6743cdb76ea6..f8ae4a04ef36 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -559,12 +559,18 @@ static void memcg_destroy_list_lru(struct list_lru *lru)
#endif /* CONFIG_MEMCG_KMEM */
int __list_lru_init(struct list_lru *lru, bool memcg_aware, bool lock_irq,
- struct lock_class_key *key)
+ struct lock_class_key *key, struct shrinker *shrinker)
{
int i;
size_t size = sizeof(*lru->node) * nr_node_ids;
int err = -ENOMEM;
+#ifdef CONFIG_MEMCG_KMEM
+ if (shrinker)
+ lru->shrinker_id = shrinker->id;
+ else
+ lru->shrinker_id = -1;
+#endif
memcg_get_cache_ids();
lru->node = kzalloc(size, GFP_KERNEL);
@@ -607,6 +613,9 @@ void list_lru_destroy(struct list_lru *lru)
kfree(lru->node);
lru->node = NULL;
+#ifdef CONFIG_MEMCG_KMEM
+ lru->shrinker_id = -1;
+#endif
memcg_put_cache_ids();
}
EXPORT_SYMBOL_GPL(list_lru_destroy);
diff --git a/mm/workingset.c b/mm/workingset.c
index b16489c60471..a682306db49b 100644
--- a/mm/workingset.c
+++ b/mm/workingset.c
@@ -511,7 +511,8 @@ static int __init workingset_init(void)
if (ret)
goto err;
/* list_lru lock nests inside the IRQ-safe i_pages lock */
- ret = __list_lru_init(&shadow_nodes, true, true, &shadow_nodes_key);
+ ret = __list_lru_init(&shadow_nodes, true, true, &shadow_nodes_key,
+ &workingset_shadow_shrinker);
if (ret)
goto err_list_lru;
register_shrinker_prepared(&workingset_shadow_shrinker);