fs: propagate shrinker::id to list_lru
authorKirill Tkhai <ktkhai@virtuozzo.com>
Fri, 17 Aug 2018 22:47:50 +0000 (15:47 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Aug 2018 23:20:31 +0000 (16:20 -0700)
Add list_lru::shrinker_id field and populate 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.

Link: http://lkml.kernel.org/r/153063059758.1818.14866596416857717800.stgit@localhost.localdomain
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Acked-by: Vladimir Davydov <vdavydov.dev@gmail.com>
Tested-by: Shakeel Butt <shakeelb@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Josef Bacik <jbacik@fb.com>
Cc: Li RongQing <lirongqing@baidu.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Matthias Kaehlcke <mka@chromium.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Sahitya Tummala <stummala@codeaurora.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman Long <longman@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/super.c
include/linux/list_lru.h
mm/list_lru.c
mm/workingset.c

index 78227c4ddb219eb3cc3d9fbba1256112744bef48..f5f96e52e0cdee8eeac0437d1aa5207ae68fbaa0 100644 (file)
@@ -261,9 +261,9 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags,
        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;
 
index 2d23b5b745bed09320ca660171c49b34fce5c869..9e75bb33766ba55015fd955e6517414b2692c00d 100644 (file)
@@ -53,16 +53,20 @@ struct list_lru {
        struct list_lru_node    *node;
 #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,
-                   struct lock_class_key *key);
-
-#define list_lru_init(lru)             __list_lru_init((lru), false, NULL)
-#define list_lru_init_key(lru, key)    __list_lru_init((lru), false, (key))
-#define list_lru_init_memcg(lru)       __list_lru_init((lru), true, NULL)
+                   struct lock_class_key *key, struct shrinker *shrinker);
+
+#define list_lru_init(lru)                             \
+       __list_lru_init((lru), false, NULL, NULL)
+#define list_lru_init_key(lru, key)                    \
+       __list_lru_init((lru), false, (key), NULL)
+#define list_lru_init_memcg(lru, shrinker)             \
+       __list_lru_init((lru), true, NULL, shrinker)
 
 int memcg_update_all_list_lrus(int num_memcgs);
 void memcg_drain_all_list_lrus(int src_idx, int dst_idx);
index c5217d84c6e10203aefd17dde10e17e72a5e0bb3..5aebbb9b2f5ba9535157f7bfb8193636049ad7d2 100644 (file)
@@ -546,12 +546,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,
-                   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);
@@ -594,6 +600,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);
index 4e0b2523aae26d90de969cfb1e0d613aaeaeff55..cd0b2ae615e46e7ef7c207e9b067ce9700326737 100644 (file)
@@ -526,7 +526,8 @@ static int __init workingset_init(void)
        ret = prealloc_shrinker(&workingset_shadow_shrinker);
        if (ret)
                goto err;
-       ret = __list_lru_init(&shadow_nodes, true, &shadow_nodes_key);
+       ret = __list_lru_init(&shadow_nodes, true, &shadow_nodes_key,
+                             &workingset_shadow_shrinker);
        if (ret)
                goto err_list_lru;
        register_shrinker_prepared(&workingset_shadow_shrinker);