[lkml]   [2011]   [Apr]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectRe: [PATCH 165/173] ramfs: fix memleak on no-mmu arch
On Mon, 25 Apr 2011, Willy Tarreau wrote:

> review patch. If anyone has any objections, please let us know.
> ------------------
> From: Bob Liu <>
> commit b836aec53e2bce71de1d5415313380688c851477 upstream.
> On no-mmu arch, there is a memleak during shmem test. The cause of this
> memleak is ramfs_nommu_expand_for_mapping() added page refcount to 2
> which makes iput() can't free that pages.
> Signed-off-by: Bob Liu <>
> Acked-by: Hugh Dickins <>
> Signed-off-by: David Howells <>
> Signed-off-by: Andrew Morton <>
> Signed-off-by: Linus Torvalds <>
> Signed-off-by: Greg Kroah-Hartman <>
> ---
> fs/ramfs/file-nommu.c | 1 +
> 1 file changed, 1 insertion(+)
> --- a/fs/ramfs/file-nommu.c
> +++ b/fs/ramfs/file-nommu.c
> @@ -111,6 +111,7 @@ int ramfs_nommu_expand_for_mapping(struc
> SetPageDirty(page);
> unlock_page(page);
> + put_page(page);
> }
> return 0;

I'm not absolutely certain, but I rather think this patch should NOT
be included: I never looked to see when the bug it fixes crept in,
but now I'm thinking it may have been 2678958e1225 "ramfs-nommu:
use generic lru cache", which did not go in until 2.6.30 -
__lru_cache_add adding the unbalanced page_cache_get.

Whereas the "SetPageDirty" you can see above is not in
I think you'd do well to include the patch below which introduced it.
(It may give you a reject because __pagevec_lru_add was enhanced to
__pagevec_lru_add_file by the time that patch went in.)

Yes, the pages Enrik reports as being wrongly discarded, would not
have been discarded if their reference counts were too high:
I do believe you need Enrik's patch instead of Bob's patch.


commit 020fe22ff14320927f394de222cbb11708bcc7a8
Author: Enrik Berkhan <>
Date: Fri Mar 13 13:51:56 2009 -0700

nommu: ramfs: pages allocated to an inode's pagecache may get wrongly discarded

The pages attached to a ramfs inode's pagecache by truncation from nothing
- as done by SYSV SHM for example - may get discarded under memory

The problem is that the pages are not marked dirty. Anything that creates
data in an MMU-based ramfs will cause the pages holding that data will
cause the set_page_dirty() aop to be called.

For the NOMMU-based mmap, set_page_dirty() may be called by write(), but
it won't be called by page-writing faults on writable mmaps, and it isn't
called by ramfs_nommu_expand_for_mapping() when a file is being truncated
from nothing to allocate a contiguous run.

The solution is to mark the pages dirty at the point of allocation by the
truncation code.

Signed-off-by: Enrik Berkhan <>
Signed-off-by: David Howells <>
Cc: Peter Zijlstra <>
Cc: Nick Piggin <>
Cc: Johannes Weiner <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>

diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index b9b567a..90d72be 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -114,6 +114,9 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
if (!pagevec_add(&lru_pvec, page))

+ /* prevent the page from being discarded on memory pressure */
+ SetPageDirty(page);

 \ /
  Last update: 2011-04-26 02:39    [W:0.343 / U:51.088 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site