Bug 57101 - Observed memory leak while accessing /proc/fs/fscache/stats
Summary: Observed memory leak while accessing /proc/fs/fscache/stats
Status: CLOSED CODE_FIX
Alias: None
Product: File System
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: fs_other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-25 08:03 UTC by Shyju
Modified: 2013-12-10 06:02 UTC (History)
3 users (show)

See Also:
Kernel Version: 3.9.0-rc8
Tree: Mainline
Regression: No


Attachments

Description Shyju 2013-04-25 08:03:19 UTC
Hi,
Observed memory leak while accessing /proc/fs/fscache/stats 

Kernel Version : 3.9.0-rc8 (Kmemleak enabled)
Platform : ATCA board(X86)
Steps to reproduce the memory leak
1. Build a Kmemleak enabled kernel
2. mount -t debugfs nodev /sys/kernel/debug/
3. cat /proc/fs/fscache/stats
4. echo scan > /sys/kernel/debug/kmemleak
5. cat /sys/kernel/debug/kmemleak
Its independent of the hardware. Can be reproduced on PC as well

Step 5 will give the following memory leak information
cat /sys/kernel/debug/kmemleak
unreferenced object 0xecd04320 (size 32):
  comm "cat", pid 2457, jiffies 103889 (age 17.664s)
  hex dump (first 32 bytes):
    70 09 23 c1 d0 09 23 c1 b0 09 23 c1 90 13 f4 f8  p.#...#...#.....
    00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff  ................
  backtrace:
    [<c11ec610>] create_object+0x100/0x400
    [<c16150f3>] kmemleak_alloc+0x73/0x120
    [<c11e42ec>] kmem_cache_alloc+0x1bc/0x310
    [<c1232633>] single_open+0x33/0xf0
    [<f8f4137f>] fscache_stats_open+0x1f/0x30 [fscache]
    [<c128c491>] proc_reg_open+0xe1/0x230
    [<c11efef6>] do_dentry_open+0x446/0x550
    [<c11f01c4>] finish_open+0x34/0x80
    [<c120dab1>] do_last+0x8e1/0x1a90
    [<c120ed66>] path_openat+0x106/0x7c0
    [<c12102ca>] do_filp_open+0x3a/0xd0
    [<c11f24c3>] do_sys_open+0x1a3/0x370
    [<c11f26c1>] sys_open+0x31/0x50
    [<c164a086>] sysenter_do_call+0x12/0x28
    [<ffffffff>] 0xffffffff

Shyju
Comment 1 Anurup M 2013-04-25 08:06:08 UTC
The kernel memory leak observed is when the proc file /proc/fs/fscache/stats is read.
The reason is that in fscache_stats_open, single_open is called and respective release function is not called during release.
Hence fix with correct release function - single_release. The patch is as below

diff -uprN -X linux-3.9-rc8-vanilla/Documentation/dontdiff linux-3.9-rc8-vanilla/fs/fscache/stats.c linux-3.9-rc8.mod/fs/fscache/stats.c 
--- linux-3.9-rc8-vanilla/fs/fscache/stats.c        2013-04-22 03:08:45.000000000 +0530 
+++ linux-3.9-rc8.mod/fs/fscache/stats.c        2013-04-24 23:03:31.531296160 +0530 
@@ -287,5 +287,5 @@ const struct file_operations fscache_sta 
         .open                = fscache_stats_open, 
         .read                = seq_read, 
         .llseek                = seq_lseek, 
-        .release        = seq_release, 
+        .release        = single_release, 
 };

--Anurup M
Comment 2 Anurup M 2013-04-25 08:13:50 UTC
The mail with the patch has been send to LKML

--Anurup M
Comment 3 Anurup M 2013-05-01 06:48:16 UTC
The issue is fixed and merged to mainline. 
please see git commit: ec686c92
@shyju,
Please valdiate and close the bug..
Comment 4 Shyju 2013-12-10 06:02:33 UTC
It has been done. Merged in kernel stable trees by Greg

Note You need to log in before you can comment on or make changes to this bug.