dcache leak in 2.6.16-git8
Subsystems (11)
A 2GB x86-64 desktop system here is currently swapping itself to death after a few days uptime.
Some investigation shows this:
inode_cache 1287 1337 568 7 1 : tunables 54 27 8 : slabdata 191 191 0 dentry_cache 1867436 1867643 208 19 1 : tunables 120 60 8 : slabdata 98297 98297 0
Going to reboot it now.
-Andi
Quoted 9 lines · Andi Kleen
A 2GB x86-64 desktop system here is currently swapping itself to death after a few days uptime.
Some investigation shows this:
inode_cache 1287 1337 568 7 1 : tunables 54 27 8 : slabdata 191 191 0 dentry_cache 1867436 1867643 208 19 1 : tunables 120 60 8 : slabdata 98297 98297 0
Would it be possible to try out this experimental patch which gets some stats from the dentry cache ?
Patch 1: dcache_stats.patch
- shows some dentry cache stats in /proc/meminfo.
Patch 2: cache_shrink_stats.patch (currently in mm)
- applies on top of the 1st patch; shows the of shrinking of slab caches in /proc/slabinfo.
The patches are against 2.6.16-git8. I have just verified that these work on x86_64. Haven't really stress tested to check if they hold for reasonable time.
Regards,
Bharata.
This patch collects a few statistics from the dcache and exports it as part of /proc/meminfo.
A typical dcache stats output from /proc/meminfo looks like this:
--------- /proc/meminfo data start -------------
nr_dentries/page nr_pages nr_inuse
0 0 0
1 7 3
2 1 1
3 3 6
4 1 2
5 5 8
6 4 9
7 1 1
8 4 4
9 4 18
10 3 4
11 6 16
12 2 6
13 3 13
14 2 9
15 2 13
16 6 28
17 2 9
18 1 2
19 0 0
20 1 3
21 2 16
22 2 20
23 2 14
24 18 116
25 20 148
26 218 2041
27 0 0
28 0 0
29 0 0
Total: 320 2510dcache lru: total 4869 inuse 117
--------- /proc/meminfo data end ---------------
Here,
nr_dentries/page - Number of dentries per pagenr_pages - Number of pages with given number of dentries nr_inuse - Number of inuse dentries in those pages.
Eg: From the above data, there are 3 pages with 3 dentries each and out of 9 total dentries in these 3 pages, 6 dentries are in use.
The number of dentries in lru list and number of inuse dentries in them are also listed at the end.
Original Author: Dave Hansen <[email protected]>
---
arch/i386/mm/init.c | 4 + arch/x86_64/mm/init.c | 8 +++ fs/dcache.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/proc/proc_misc.c | 19 ++++++++ include/linux/dcache.h | 11 ++++- include/linux/mm.h | 3 + mm/page_alloc.c | 2 7 files changed, 150 insertions(+), 2 deletions(-)
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~dcache_stats +4 -0
@@ -273,6 +273,7 @@ static void __meminit free_new_highpage(init_page_count (page);__free_page (page); totalhigh_pages++; +spin_lock_init (&page->dcount_lock); }void __init add_one_highpage_init (struct page *page,int pfn,int bad_ppro)
@@ -746,12 +747,15 @@ void mark_rodata_ro(void)void free_init_pages (char *what,unsigned long begin,unsigned long end) {unsigned long addr; +struct page *page;for (addr = begin; addr < end; addr +=PAGE_SIZE ) {ClearPageReserved (virt_to_page (addr));init_page_count (virt_to_page (addr));memset ((void *)addr,0xcc ,PAGE_SIZE );free_page (addr); + page =virt_to_page (addr); +spin_lock_init (&page->dcount_lock); totalram_pages++; }printk (KERN_INFO "Freeing %s: %ldk freed\n" , what, (end - begin) >>10 );
fs/dcache.c renamed from fs/dcache.c~dcache_stats +105 -0
199 lines not on this page · raw message
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c~dcache_stats +19 -0
@@ -46,6 +46,7 @@#include <linux/sysrq.h> #include <linux/vmalloc.h> #include <linux/crash_dump.h> +#include <linux/dcache.h> #include <asm/uaccess.h> #include <asm/pgtable.h> #include <asm/io.h>
@@ -128,6 +129,7 @@ static int meminfo_read_proc(char *page,unsigned long allowed;struct vmalloc_info vmi;long cached; +int j, total_dpages =0 , total_inuse =0 ;get_page_state (&ps);get_zone_counts (&active, &inactive, &free);
@@ -202,6 +204,23 @@ static int meminfo_read_proc(char *page, len +=hugetlb_report_meminfo (page + len); + len +=sprintf (page + len,"nr_dentries/page\t" +"nr_pages\tnr_inuse\n" ); +for (j =0 ; j <MAX_DENTRIES_PER_PAGE ; j++) { + len +=sprintf (page + len, +"\t%2d\t\t%d\t\t%d\n" , j, +atomic_read (&nr_dpages[j]), +atomic_read (&nr_dinuse[j])); + total_dpages +=atomic_read (&nr_dpages[j]); + total_inuse +=atomic_read (&nr_dinuse[j]); + } + len +=sprintf (page + len,"Total: \t\t\t%d\t\t%d\n" , + total_dpages, total_inuse); +get_dcache_lru (); + len +=sprintf (page + len, +"dcache lru: total %d inuse %d\n" , + dentry_stat.nr_unused, dentry_stat.nr_lru_inuse); +return proc_calc_metrics (page, start, off, count, eof, len);#undef K }
include/linux/dcache.h renamed from include/linux/dcache.h~dcache_stats +9 -2
@@ -38,10 +38,11 @@ struct qstr {struct dentry_stat_t {int nr_dentry; -int nr_unused; +int nr_unused;/* number of dentries in lru list */ int age_limit;/* age in seconds */ int want_pages;/* pages requested by system */ -int dummy[2 ]; +int nr_lru_inuse;/* inuse dentries in lru */ +int dummy[1 ]; };extern struct dentry_stat_t dentry_stat;
@@ -235,6 +236,12 @@ extern int have_submounts(struct dentry*/ extern void d_rehash (struct dentry *); +/* dcache statistics */ +#define MAX_DENTRIES_PER_PAGE 30 +extern atomic_t nr_dpages[]; +extern atomic_t nr_dinuse[]; +extern void get_dcache_lru (void ); +/** * d_add - add dentry to hash queues * @entry: dentry to add
include/linux/mm.h renamed from include/linux/mm.h~dcache_stats +3 -0
@@ -224,6 +224,9 @@ struct page {* to show when page is mapped * & limit reverse map searches. */ +int dcount;/* Number of dentries in this page */ +int d_inuse_count;/* Number of inuse dentries */ +spinlock_t dcount_lock; union { struct { unsigned long private; /* Mapping-private opaque data:
mm/page_alloc.c renamed from mm/page_alloc.c~dcache_stats +2 -0
@@ -457,6 +457,7 @@ void fastcall __init __free_pages_bootme__ClearPageReserved (page);set_page_count (page,0 );set_page_refcounted (page); +spin_lock_init (&page->dcount_lock);__free_page (page); }else {int loop;
@@ -469,6 +470,7 @@ void fastcall __init __free_pages_bootmeprefetchw (p +1 );__ClearPageReserved (p);set_page_count (p,0 ); +spin_lock_init (&p->dcount_lock); }set_page_refcounted (page);
arch/x86_64/mm/init.c renamed from arch/x86_64/mm/init.c~dcache_stats +8 -0
@@ -490,6 +490,7 @@ void online_page(struct page *page)__free_page (page); totalram_pages++; num_physpages++; +spin_lock_init (&page->dcount_lock); }int add_memory (u64 start,u64 size)
@@ -588,6 +589,7 @@ void __init mem_init(void)void free_initmem (void ) {unsigned long addr; +struct page *page; addr = (unsigned long )(&__init_begin);for (; addr < (unsigned long )(&__init_end); addr +=PAGE_SIZE ) {
@@ -596,6 +598,8 @@ void free_initmem(void)memset ((void *)(addr & ~(PAGE_SIZE -1 )),0xcc ,PAGE_SIZE );free_page (addr); totalram_pages++; + page =virt_to_page (addr); +spin_lock_init (&page->dcount_lock); }memset (__initdata_begin,0xba , __initdata_end - __initdata_begin);printk ("Freeing unused kernel memory: %luk freed\n" , (__init_end - __init_begin) >>10 );
@@ -627,6 +631,8 @@ void mark_rodata_ro(void)#ifdef CONFIG_BLK_DEV_INITRD void free_initrd_mem (unsigned long start,unsigned long end) { +struct page *page; +if (start >= end)return ;printk ("Freeing initrd memory: %ldk freed\n" , (end - start) >>10 );
@@ -635,6 +641,8 @@ void free_initrd_mem(unsigned long startinit_page_count (virt_to_page (start));free_page (start); totalram_pages++; + page =virt_to_page (start); + spin_lock_init(&page->dcount_lock); } }#endif
_
This patch adds two more fields to each entry of shrinkable cache in /proc/slabinfo: the number of objects scanned for freeing and the actual number of objects freed.
---
fs/dcache.c | 4 +++- fs/dquot.c | 4 +++- fs/inode.c | 4 +++- fs/mbcache.c | 2 ++ include/linux/mm.h | 39 ++++++++++++++++++++++++++++++++++++++- include/linux/slab.h | 3 +++ mm/slab.c | 15 +++++++++++++++ mm/vmscan.c | 23 +++++++++++------------ 8 files changed, 78 insertions(+), 16 deletions(-)
fs/dcache.c renamed from fs/dcache.c~cache_shrink_stats +3 -1
@@ -1778,6 +1778,7 @@ static void __init dcache_init_early(voistatic void __init dcache_init (unsigned long mempages) {int loop; +struct shrinker *shrinker;/* * A constructor could be added for stable state like the lists,
@@ -1790,7 +1791,8 @@ static void __init dcache_init(unsignedSLAB_RECLAIM_ACCOUNT |SLAB_PANIC , NULL, NULL); -set_shrinker (DEFAULT_SEEKS , shrink_dcache_memory); + shrinker =set_shrinker (DEFAULT_SEEKS , shrink_dcache_memory); +kmem_set_shrinker (dentry_cache, shrinker);/* Hash may have been set up in dcache_init_early */ if (!hashdist)
fs/dquot.c renamed from fs/dquot.c~cache_shrink_stats +3 -1
@@ -1814,6 +1814,7 @@ static int __init dquot_init(void) {int i;unsigned long nr_hash, order; +struct shrinker *shrinker;printk (KERN_NOTICE "VFS: Disk quotas %s\n" , __DQUOT_VERSION__);
@@ -1845,7 +1846,8 @@ static int __init dquot_init(void)printk ("Dquot-cache hash table entries: %ld (order %ld, %ld bytes)\n" , nr_hash, order, (PAGE_SIZE << order)); -set_shrinker (DEFAULT_SEEKS , shrink_dqcache_memory); + shrinker =set_shrinker (DEFAULT_SEEKS , shrink_dqcache_memory); +kmem_set_shrinker (dquot_cachep, shrinker);return 0 ; }
fs/inode.c renamed from fs/inode.c~cache_shrink_stats +3 -1
@@ -1373,11 +1373,13 @@ void __init inode_init_early(void)void __init inode_init (unsigned long mempages) {int loop; +struct shrinker *shrinker;/* inode slab cache */ inode_cachep =kmem_cache_create ("inode_cache" ,sizeof (struct inode ),0 ,SLAB_RECLAIM_ACCOUNT |SLAB_PANIC , init_once,NULL ); -set_shrinker (DEFAULT_SEEKS , shrink_icache_memory); + shrinker =set_shrinker (DEFAULT_SEEKS , shrink_icache_memory); +kmem_set_shrinker (inode_cachep, shrinker);/* Hash may have been set up in inode_init_early */ if (!hashdist)
fs/mbcache.c renamed from fs/mbcache.c~cache_shrink_stats +2 -0
@@ -292,6 +292,8 @@ mb_cache_create(const char *name, structif (!cache->c_entry_cache) goto fail; +kmem_set_shrinker (cache->c_entry_cache, mb_shrinker); +spin_lock (&mb_cache_spinlock);list_add (&cache->c_cache_list, &mb_cache_list);spin_unlock (&mb_cache_spinlock);
include/linux/mm.h renamed from include/linux/mm.h~cache_shrink_stats +38 -1
@@ -789,7 +789,44 @@ typedef int (*shrinker_t)(int nr_to_scan*/ #define DEFAULT_SEEKS 2 -struct shrinker ; + +struct shrinker_stats { +unsigned long nr_req;/* objs scanned for possible freeing */ +unsigned long nr_freed;/* actual number of objects freed */ +}; + +/* +* The list of shrinker callbacks used by to apply pressure to +* ageable caches. +*/ +struct shrinker { +shrinker_t shrinker; +struct list_head list; +int seeks;/* seeks to recreate an obj */ +long nr;/* objs pending delete */ +struct shrinker_stats *s_stats; +}; + +#define shrinker_stat_add (shrinker, field, addnd) \ + do { \ + preempt_disable(); \ + (per_cpu_ptr(shrinker->s_stats, \ + smp_processor_id())->field += addnd); \ + preempt_enable(); \ + } while (0) + +#define shrinker_stat_read (shrinker, field) \ +({ \ + typeof(shrinker->s_stats->field) res = 0; \ + int i; \ + for (i=0; i < NR_CPUS; i++) { \ + if (!cpu_possible(i)) \ + continue; \ + res += per_cpu_ptr(shrinker->s_stats, i)->field; \ + } \ + res; \ +}) +extern struct shrinker *set_shrinker (int ,shrinker_t );extern void remove_shrinker (struct shrinker *shrinker);
include/linux/slab.h renamed from include/linux/slab.h~cache_shrink_stats +3 -0
@@ -187,6 +187,9 @@ extern kmem_cache_t *bio_cachep;extern atomic_t slab_reclaim_pages; +struct shrinker ; +extern void kmem_set_shrinker (kmem_cache_t *cachep,struct shrinker *shrinker); +#endif /* __KERNEL__ */ #endif /* _LINUX_SLAB_H */
mm/slab.c renamed from mm/slab.c~cache_shrink_stats +15 -0
@@ -403,6 +403,9 @@ struct kmem_cache {/* de-constructor func */ void (*dtor) (void *,struct kmem_cache *,unsigned long ); +/* shrinker data for this cache */ +struct shrinker *shrinker; +/* 5) cache creation/removal */ const char *name;struct list_head next;
@@ -3671,6 +3674,7 @@ static void print_slabinfo_header(struct "<error> <maxfreeable> <nodeallocs> <remotefrees>");seq_puts (m," : cpustat <allochit> <allocmiss> <freehit> <freemiss>" );#endif +seq_puts (m," : shrinker stat <nr requested> <nr freed>" );seq_putc (m,'\n' ); }
@@ -3799,6 +3803,12 @@ static int s_show(struct seq_file *m, vo allochit, allocmiss, freehit, freemiss); }#endif +/* shrinker stats */ +if (cachep->shrinker) { +seq_printf (m," : shrinker stat %7lu %7lu" , +shrinker_stat_read (cachep->shrinker, nr_req), +shrinker_stat_read (cachep->shrinker, nr_freed)); + }seq_putc (m,'\n' );return 0 ; }
@@ -3897,3 +3907,8 @@ unsigned int ksize(const void *objp)return obj_size (virt_to_cache (objp)); } + +void kmem_set_shrinker (kmem_cache_t *cachep,struct shrinker *shrinker) +{ + cachep->shrinker = shrinker; +}
mm/vmscan.c renamed from mm/vmscan.c~cache_shrink_stats +11 -12
@@ -63,17 +63,6 @@ struct scan_control {int swap_cluster_max; }; -/* -* The list of shrinker callbacks used by to apply pressure to -* ageable caches. -*/ -struct shrinker { -shrinker_t shrinker; -struct list_head list; -int seeks;/* seeks to recreate an obj */ -long nr;/* objs pending delete */ -}; -#define lru_to_page (_head) (list_entry((_head)->prev, struct page, lru))#ifdef ARCH_HAS_PREFETCH
@@ -125,6 +114,11 @@ struct shrinker *set_shrinker(int seeks, shrinker->shrinker = theshrinker; shrinker->seeks = seeks; shrinker->nr =0 ; + shrinker->s_stats = alloc_percpu(struct shrinker_stats); +if (!shrinker->s_stats) { +kfree (shrinker); +return NULL ; + }down_write (&shrinker_rwsem);list_add_tail (&shrinker->list, &shrinker_list);up_write (&shrinker_rwsem);
@@ -141,6 +135,7 @@ void remove_shrinker(struct shrinker *shdown_write (&shrinker_rwsem);list_del (&shrinker->list);up_write (&shrinker_rwsem); +free_percpu (shrinker->s_stats);kfree (shrinker); }EXPORT_SYMBOL (remove_shrinker);
@@ -212,8 +207,12 @@ unsigned long shrink_slab(unsigned long shrink_ret = (*shrinker->shrinker)(this_scan, gfp_mask);if (shrink_ret ==-1 )break ; -if (shrink_ret < nr_before) +if (shrink_ret < nr_before) { ret += nr_before - shrink_ret; +shrinker_stat_add (shrinker, nr_freed, + (nr_before - shrink_ret)); + } +shrinker_stat_add (shrinker, nr_req, this_scan);mod_page_state (slabs_scanned, this_scan); total_scan -= this_scan;
_
Quoted 5 lines · Bharata B Rao
Quoted 4 lines · Andi Kleen
A 2GB x86-64 desktop system here is currently swapping itself to death after a few days uptime.
Quoted 8 lines
Quoted 5 lines
Some investigation shows this:
inode_cache 1287 1337 568 7 1 : tunables 54 27 8 : slabdata 191 191 0 dentry_cache 1867436 1867643 208 19 1 : tunables 120 60 8 : slabdata 98297 98297 0Would it be possible to try out this experimental patch which gets some stats from the dentry cache ?
It should be trivial to reproduce by other people. Biggest workload is kernel compiles and quilt.
After a few hours with -git12 it's already at
dentry_cache 947013 952014 208 19 1 : tunables 120 60 8 : slabdata 50100 50106 480
and starting to go into swap.
I can't imagine I'm the only one seeing this?
I have a few x86-64 patches applied too, but they don't change anything in this area.
-Andi
Quoted 21 lines · Andi Kleen
Quoted 5 lines · Bharata B Rao
Quoted 4 lines · Andi Kleen
A 2GB x86-64 desktop system here is currently swapping itself to death after a few days uptime.
Quoted 8 lines
Quoted 5 lines
Some investigation shows this:
inode_cache 1287 1337 568 7 1 : tunables 54 27 8 : slabdata 191 191 0 dentry_cache 1867436 1867643 208 19 1 : tunables 120 60 8 : slabdata 98297 98297 0Would it be possible to try out this experimental patch which gets some stats from the dentry cache ?
It should be trivial to reproduce by other people. Biggest workload is kernel compiles and quilt.
After a few hours with -git12 it's already at
Quoted 8 lines
dentry_cache947013 952014 208 19 1 : tunables 120 60 8 : slabdata 50100 50106 480and starting to go into swap.
I can't imagine I'm the only one seeing this?
I have a few x86-64 patches applied too, but they don't change anything in this area.
I don't think I can reproduce this on x86 uniproc. (avtab_node_cache is a different story - maintainers separately pinged).
I'd expect pretty much everything we have in there now was under test in -mm for quite some time - any obvious leaks would have been noticed. I'd be suspecting recent changes in perhaps audit or nfs, at a guess. Or something weird.
Which filesystems are in use?
Quoted 26 lines · Andrew Morton
Quoted 25 lines · Andi Kleen
Quoted 5 lines · Bharata B Rao
Quoted 4 lines · Andi Kleen
A 2GB x86-64 desktop system here is currently swapping itself to death after a few days uptime.
Quoted 8 lines
Quoted 5 lines
Some investigation shows this:
inode_cache 1287 1337 568 7 1 : tunables 54 27 8 : slabdata 191 191 0 dentry_cache 1867436 1867643 208 19 1 : tunables 120 60 8 : slabdata 98297 98297 0Would it be possible to try out this experimental patch which gets some stats from the dentry cache ?
It should be trivial to reproduce by other people. Biggest workload is kernel compiles and quilt.
After a few hours with -git12 it's already at
dentry_cache947013 952014 208 19 1 : tunables 120 60 8 : slabdata 50100 50106 480and starting to go into swap.
Quoted 7 lines
Quoted 4 lines
I can't imagine I'm the only one seeing this?
I have a few x86-64 patches applied too, but they don't change anything in this area.
I don't think I can reproduce this on x86 uniproc. (
avtab_node_cacheis a different story - maintainers separately pinged).
This is x86-64 dual core.
Quoted 7 lines
I'd expect pretty much everything we have in there now was under test in -mm for quite some time - any obvious leaks would have been noticed. I'd be suspecting recent changes in perhaps audit or nfs, at a guess. Or something weird.
Which filesystems are in use?
ext3, NFS (not much)
-Andi
Re: dcache leak in 2.6.16-git8 II
In reply to Andrew MortonQuoted 26 lines · Andrew Morton
Quoted 25 lines · Andi Kleen
Quoted 5 lines · Bharata B Rao
Quoted 4 lines · Andi Kleen
A 2GB x86-64 desktop system here is currently swapping itself to death after a few days uptime.
Quoted 8 lines
Quoted 5 lines
Some investigation shows this:
inode_cache 1287 1337 568 7 1 : tunables 54 27 8 : slabdata 191 191 0 dentry_cache 1867436 1867643 208 19 1 : tunables 120 60 8 : slabdata 98297 98297 0Would it be possible to try out this experimental patch which gets some stats from the dentry cache ?
It should be trivial to reproduce by other people. Biggest workload is kernel compiles and quilt.
After a few hours with -git12 it's already at
dentry_cache947013 952014 208 19 1 : tunables 120 60 8 : slabdata 50100 50106 480and starting to go into swap.
Quoted 7 lines
Quoted 4 lines
I can't imagine I'm the only one seeing this?
I have a few x86-64 patches applied too, but they don't change anything in this area.
I don't think I can reproduce this on x86 uniproc. (
avtab_node_cacheis a different story - maintainers separately pinged).
I got another OOM from this with -git13. Unfortunately it seems to take a few days at least to trigger.
dentry_cache 999168 1024594 208 19 1 : tunables 120 60 8 : slabdata 53926 53926 0 : shrinker stat 18522624 8871000
Hrm interesting is this one:
sock_inode_cache 996784 996805 704 5 1 : tunables 54 27 8 : slabdata 199361 199361 0
Most of the leaked dentries seem to be sockets. I didn't notice this earlier.
This was with the debugging patches applied btw.
So maybe we have a socket leak?
I still got a copy of the /proc in case anybody wants more information.
-Andi
meminfo debugging was
r_dentries/page nr_pages nr_inuse
0 0 0
1 139 139
2 115 230
3 99 297
4 103 412
5 84 419
6 80 480
7 75 519
8 65 520
9 52 466
10 58 580
11 55 605
12 73 868
13 124 1610
14 184 2576
15 313 4685
16 518 8288
17 1338 22744
18 4591 82633
19 45843 870758
20 0 0
21 0 0
22 0 0
23 0 0
24 0 0
25 0 0
26 0 0
27 0 0
28 0 0
29 0 0
Total: 53909 998829dcache lru: total 232 inuse 1
Re: dcache leak in 2.6.16-git8 II
Quoted 44 lines · Andi Kleen
Quoted 26 lines · Andrew Morton
Quoted 25 lines · Andi Kleen
Quoted 5 lines · Bharata B Rao
Quoted 4 lines · Andi Kleen
A 2GB x86-64 desktop system here is currently swapping itself to death after a few days uptime.
Quoted 8 lines
Quoted 5 lines
Some investigation shows this:
inode_cache 1287 1337 568 7 1 : tunables 54 27 8 : slabdata 191 191 0 dentry_cache 1867436 1867643 208 19 1 : tunables 120 60 8 : slabdata 98297 98297 0Would it be possible to try out this experimental patch which gets some stats from the dentry cache ?
It should be trivial to reproduce by other people. Biggest workload is kernel compiles and quilt.
After a few hours with -git12 it's already at
dentry_cache947013 952014 208 19 1 : tunables 120 60 8 : slabdata 50100 50106 480and starting to go into swap.
Quoted 7 lines
Quoted 4 lines
I can't imagine I'm the only one seeing this?
I have a few x86-64 patches applied too, but they don't change anything in this area.
I don't think I can reproduce this on x86 uniproc. (
avtab_node_cacheis a different story - maintainers separately pinged).I got another OOM from this with -git13. Unfortunately it seems to take a few days at least to trigger.
dentry_cache999168 1024594 208 19 1 : tunables 120 60 8 : slabdata 53926 53926 0 : shrinker stat 18522624 8871000Hrm interesting is this one:
Quoted 7 lines
sock_inode_cache996784 996805 704 5 1 : tunables 54 27 8 : slabdata 199361 199361 0Most of the leaked dentries seem to be sockets. I didn't notice this earlier.
This was with the debugging patches applied btw.
So maybe we have a socket leak?
It looks that way. Didn't someone else report a sock_inode_cache leak?
Quoted 1 line
I still got a copy of the /proc in case anybody wants more information.
We have this fancy new /proc/slab_allocators now, it might show something interesting. It needs CONFIG_DEBUG_SLAB_LEAK.
Re: dcache leak in 2.6.16-git8 II
Quoted 1 line · Andrew Morton
It looks that way. Didn't someone else report a
sock_inode_cacheleak?
Didn't see it.
Quoted 4 lines
Quoted 1 line
I still got a copy of the /proc in case anybody wants more information.
We have this fancy new
/proc/slab_allocatorsnow, it might show something interesting. It needsCONFIG_DEBUG_SLAB_LEAK.
I didn't have that enabled unfortunately. I can try it on the next round.
-Andi
Re: dcache leak in 2.6.16-git8 II
Quoted 6 lines · Andi Kleen
Quoted 1 line · Andrew Morton
It looks that way. Didn't someone else report a
sock_inode_cacheleak?Didn't see it.
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
I still got a copy of the /proc in case anybody wants more information.
We have this fancy new
/proc/slab_allocatorsnow, it might show something interesting. It needsCONFIG_DEBUG_SLAB_LEAK.I didn't have that enabled unfortunately. I can try it on the next round.
-Andi
There is also a new sysctl to drop caches. It is called vm.drop_caches. It will be interesting to see if it is able to free up some dcache memory for you.
Balbir
Re: dcache leak in 2.6.16-git8 II
In reply to Andi KleenQuoted 7 lines · Andi Kleen
dentry_cache999168 1024594 208 19 1 : tunables 120 60 8 : slabdata 53926 53926 0 : shrinker stat 18522624 8871000Hrm interesting is this one:
sock_inode_cache996784 996805 704 5 1 : tunables 54 27 8 : slabdata 199361 199361 0Most of the leaked dentries seem to be sockets. I didn't notice this earlier.
ITYM "all". You've got 2384 non-socket dentries, which is about what I'd expect on severely pressured busy system...
Quoted 3 lines
This was with the debugging patches applied btw.
So maybe we have a socket leak?
Looks like that. Note: /proc/slab_allocators won't help here; all allocations into that cache are done from sock_alloc_inode(), which is what will be shown. Not useful... Moreover, call chain is predictable several steps deeper than
that: sock_alloc_inode() (as ->alloc_inode()) from alloc_inode() from new_inode() from sock_alloc().
FWIW... One thing that might be useful here:
a) slab_set_creator(objp, cachep, address): no-op unless DEBUG_SLAB_LEAK set, void slab_set_creator(void *objp, struct kmem_cache *cachep, void *address)
{
if (cachep->flags & SLAB_STORE_USER)
*dbg_userword(cachep, objp) = address;
}otherwise (has to be function in mm/slab.c; exported).
b)
void slab_charge_here(void *objp, struct kmem_cache *cachep, void *address)
{
slab_set_creator(objp, cachep, __builtin_return_address(0));
}in mm/slab.c (exported)
c) #define slab_charge_caller(objp, cachep) \ slab_set_creator((objp), (cachep), __builtin_return_address(0))
Then we can do the following: in sock_alloc() have
slab_charge_caller(container_of(inode, struct socket_alloc, vfs_inode), sock_inode_cachep);
and _then_ /proc/slab_allocators will charge these guys to callers of sock_alloc(); if you'll need to pursue it further, you can always slap more slab_charge_...() where needed.
Re: dcache leak in 2.6.16-git8 II
Quoted 1 line · Al Viro
FWIW... One thing that might be useful here:
Here's what I had in mind:
Allow explictly mark allocated objects as "allocated here", so that they'll show up that way for all slab debugging purposes. New helpers:
slab_charge_here(objp, cachep)
slab_charge_caller(objp, cachep)
mark object as allocated resp. by place where we have ...charge_here() called and by the caller of function that calls slab_charge_caller().
It's useful when call chain leading to allocation in given cache always ends the same way, making normal caller accounting uninformative. E.g. allocation of struct socket is always done via sock_alloc() => new_inode() => alloc_inode() => sock_alloc_inode() => kmem_cache_alloc(). The last step has no chance to give any useful information about the caller; adding slab_charge_caller() in sock_alloc() will give us much more useful picture.
----
include/linux/slab.h +14 -0
@@ -151,6 +151,16 @@ static inline void *kcalloc(size_t n, siextern void kfree (const void *);extern unsigned int ksize (const void *); +#ifndef CONFIG_DEBUG_SLAB +#define slab_set_creator (objp, cachep, address) +#define slab_charge_here (objp, cachep) +#else +extern void slab_set_creator (void *objp,struct kmem_cache *cachep,void *address); +extern void slab_charge_here (void *objp,struct kmem_cache *cachep); +#endif +#define slab_charge_caller (objp, cachep) \ + slab_set_creator((objp), (cachep), __builtin_return_address(0)) +#ifdef CONFIG_NUMA extern void *kmem_cache_alloc_node (kmem_cache_t *,gfp_t flags,int node);extern void *kmalloc_node (size_t size,gfp_t flags,int node);
@@ -189,6 +199,10 @@ void kfree(const void *m);unsigned int ksize (const void *m);unsigned int kmem_cache_size (struct kmem_cache *c); +#define slab_set_creator (objp, cachep, address) +#define slab_charge_here (objp, cachep) +#define slab_charge_caller (objp, cachep) +static inline void *kcalloc (size_t n,size_t size,gfp_t flags) {return __kzalloc (n * size, flags);
mm/slab.c +17 -0
@@ -3144,6 +3144,23 @@ void *kmem_cache_zalloc(struct kmem_cach }EXPORT_SYMBOL (kmem_cache_zalloc); +#ifdef CONFIG_DEBUG_SLAB +void slab_set_creator (void *objp,struct kmem_cache *cachep,void *address) +{ +if (cachep->flags &SLAB_STORE_USER ) + *dbg_userword (cachep, objp) = address; +} + +EXPORT_SYMBOL (slab_set_creator); + +void slab_charge_here (void *objp,struct kmem_cache *cachep) +{ +slab_set_creator (objp, cachep,__builtin_return_address (0 )); +} +EXPORT_SYMBOL (slab_charge_here); + +#endif +/** * kmem_ptr_validate - check if an untrusted pointer might * be a slab entry.
net/socket.c +3 -0
@@ -517,6 +517,9 @@ static struct socket *sock_alloc(void)if (!inode)return NULL ; + slab_charge_caller(container_of(inode, struct socket_alloc, vfs_inode), + sock_inode_cachep); + sock =SOCKET_I (inode); inode->i_mode =S_IFSOCK |S_IRWXUGO ;
Re: dcache leak in 2.6.16-git8 II
BTW, it allows even funnier stuff: instead of "I'd been allocated by <place>" you can do "I'd passed through <place>". E.g. if object has different states you can slap slab_charge_here() in state transitions and /proc/slab_allocators will count them separately, showing how many objects are in which state, etc.