summaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorWaiman Long <longman@redhat.com>2019-07-11 23:56:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-12 14:05:44 -0400
commitfcf8a1e483490cd249df4e02d5425636c3f43c86 (patch)
treef157fe973ec1e5500b83fa93fe46431d7a9c3b0a /mm
parentfb2f2b0adb98bbbbbb51c5a5327f3f90f5dc417e (diff)
mm, memcg: add a memcg_slabinfo debugfs file
There are concerns about memory leaks from extensive use of memory cgroups as each memory cgroup creates its own set of kmem caches. There is a possiblity that the memcg kmem caches may remain even after the memory cgroups have been offlined. Therefore, it will be useful to show the status of each of memcg kmem caches. This patch introduces a new <debugfs>/memcg_slabinfo file which is somewhat similar to /proc/slabinfo in format, but lists only information about kmem caches that have child memcg kmem caches. Information available in /proc/slabinfo are not repeated in memcg_slabinfo. A portion of a sample output of the file was: # <name> <css_id[:dead]> <active_objs> <num_objs> <active_slabs> <num_slabs> rpc_inode_cache root 13 51 1 1 rpc_inode_cache 48 0 0 0 0 fat_inode_cache root 1 45 1 1 fat_inode_cache 41 2 45 1 1 xfs_inode root 770 816 24 24 xfs_inode 92 22 34 1 1 xfs_inode 88:dead 1 34 1 1 xfs_inode 89:dead 23 34 1 1 xfs_inode 85 4 34 1 1 xfs_inode 84 9 34 1 1 The css id of the memcg is also listed. If a memcg is not online, the tag ":dead" will be attached as shown above. [longman@redhat.com: memcg: add ":deact" tag for reparented kmem caches in memcg_slabinfo] Link: http://lkml.kernel.org/r/20190621173005.31514-1-longman@redhat.com [longman@redhat.com: set the flag in the common code as suggested by Roman] Link: http://lkml.kernel.org/r/20190627184324.5875-1-longman@redhat.com Link: http://lkml.kernel.org/r/20190619171621.26209-1-longman@redhat.com Signed-off-by: Waiman Long <longman@redhat.com> Suggested-by: Shakeel Butt <shakeelb@google.com> Reviewed-by: Shakeel Butt <shakeelb@google.com> Acked-by: Roman Gushchin <guro@fb.com> Acked-by: David Rientjes <rientjes@google.com> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/slab_common.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/mm/slab_common.c b/mm/slab_common.c
index b893eefb6229..6c49dbb3769e 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -17,6 +17,7 @@
17#include <linux/uaccess.h> 17#include <linux/uaccess.h>
18#include <linux/seq_file.h> 18#include <linux/seq_file.h>
19#include <linux/proc_fs.h> 19#include <linux/proc_fs.h>
20#include <linux/debugfs.h>
20#include <asm/cacheflush.h> 21#include <asm/cacheflush.h>
21#include <asm/tlbflush.h> 22#include <asm/tlbflush.h>
22#include <asm/page.h> 23#include <asm/page.h>
@@ -770,6 +771,7 @@ static void kmemcg_cache_deactivate(struct kmem_cache *s)
770 return; 771 return;
771 772
772 __kmemcg_cache_deactivate(s); 773 __kmemcg_cache_deactivate(s);
774 s->flags |= SLAB_DEACTIVATED;
773 775
774 /* 776 /*
775 * memcg_kmem_wq_lock is used to synchronize memcg_params.dying 777 * memcg_kmem_wq_lock is used to synchronize memcg_params.dying
@@ -1521,6 +1523,64 @@ static int __init slab_proc_init(void)
1521 return 0; 1523 return 0;
1522} 1524}
1523module_init(slab_proc_init); 1525module_init(slab_proc_init);
1526
1527#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_MEMCG_KMEM)
1528/*
1529 * Display information about kmem caches that have child memcg caches.
1530 */
1531static int memcg_slabinfo_show(struct seq_file *m, void *unused)
1532{
1533 struct kmem_cache *s, *c;
1534 struct slabinfo sinfo;
1535
1536 mutex_lock(&slab_mutex);
1537 seq_puts(m, "# <name> <css_id[:dead|deact]> <active_objs> <num_objs>");
1538 seq_puts(m, " <active_slabs> <num_slabs>\n");
1539 list_for_each_entry(s, &slab_root_caches, root_caches_node) {
1540 /*
1541 * Skip kmem caches that don't have any memcg children.
1542 */
1543 if (list_empty(&s->memcg_params.children))
1544 continue;
1545
1546 memset(&sinfo, 0, sizeof(sinfo));
1547 get_slabinfo(s, &sinfo);
1548 seq_printf(m, "%-17s root %6lu %6lu %6lu %6lu\n",
1549 cache_name(s), sinfo.active_objs, sinfo.num_objs,
1550 sinfo.active_slabs, sinfo.num_slabs);
1551
1552 for_each_memcg_cache(c, s) {
1553 struct cgroup_subsys_state *css;
1554 char *status = "";
1555
1556 css = &c->memcg_params.memcg->css;
1557 if (!(css->flags & CSS_ONLINE))
1558 status = ":dead";
1559 else if (c->flags & SLAB_DEACTIVATED)
1560 status = ":deact";
1561
1562 memset(&sinfo, 0, sizeof(sinfo));
1563 get_slabinfo(c, &sinfo);
1564 seq_printf(m, "%-17s %4d%-6s %6lu %6lu %6lu %6lu\n",
1565 cache_name(c), css->id, status,
1566 sinfo.active_objs, sinfo.num_objs,
1567 sinfo.active_slabs, sinfo.num_slabs);
1568 }
1569 }
1570 mutex_unlock(&slab_mutex);
1571 return 0;
1572}
1573DEFINE_SHOW_ATTRIBUTE(memcg_slabinfo);
1574
1575static int __init memcg_slabinfo_init(void)
1576{
1577 debugfs_create_file("memcg_slabinfo", S_IFREG | S_IRUGO,
1578 NULL, NULL, &memcg_slabinfo_fops);
1579 return 0;
1580}
1581
1582late_initcall(memcg_slabinfo_init);
1583#endif /* CONFIG_DEBUG_FS && CONFIG_MEMCG_KMEM */
1524#endif /* CONFIG_SLAB || CONFIG_SLUB_DEBUG */ 1584#endif /* CONFIG_SLAB || CONFIG_SLUB_DEBUG */
1525 1585
1526static __always_inline void *__do_krealloc(const void *p, size_t new_size, 1586static __always_inline void *__do_krealloc(const void *p, size_t new_size,