History

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>

Waiman Long committed 7 years ago

Commit fcf8a1e1 parent fb2f2b02 files · +64 −0Browse files

Unified · Split

2 files
  1. include/linux/slab.h +4 −0
  2. mm/slab_common.c +60 −0
include/linux/slab.h+4−0
@@ -116,6 +116,10 @@ · 115 unmodified lines
116/* Objects are reclaimable */116/* Objects are reclaimable */
117#define SLAB_RECLAIM_ACCOUNT ((slab_flags_t __force)0x00020000U)117#define SLAB_RECLAIM_ACCOUNT ((slab_flags_t __force)0x00020000U)
118#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */118#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
119
120/* Slab deactivation flag */
121#define SLAB_DEACTIVATED ((slab_flags_t __force)0x10000000U)
122
119/*123/*
120 * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.124 * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.
121 *125 *
mm/slab_common.c+60−0
@@ -17,6 +17,7 @@ · 16 unmodified lines
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) · 747 unmodified lines
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.dying777 * memcg_kmem_wq_lock is used to synchronize memcg_params.dying
@@ -1521,6 +1523,64 @@ static int __init slab_proc_init(void) · 745 unmodified lines
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,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t