2010-03-24 14:27:09

by jing zhang

[permalink] [raw]
Subject: [PATCH] ext4: page_cache pages not released in ext4_mb_load_buddy()

From: Jing Zhang <[email protected]>

Date: Wed Mar 24 20:38:48 2010

If ext4_mb_init_cache() returns error, there is no page_cache_release() issued.

Cc: Theodore Ts'o <[email protected]>
Cc: Andreas Dilger <[email protected]>
Cc: Dave Kleikamp <[email protected]>
Signed-off-by: Jing Zhang <[email protected]>

---

--- linux-2.6.32/fs/ext4/mballoc.c 2009-12-03 11:51:22.000000000 +0800
+++ ext4_mm_leak/mballoc-9.c 2010-03-24 22:24:56.000000000 +0800
@@ -1132,8 +1132,6 @@ repeat_load_buddy:
e4b->bd_buddy = page_address(page) + (poff * sb->s_blocksize);
mark_page_accessed(page);

- BUG_ON(e4b->bd_bitmap_page == NULL);
- BUG_ON(e4b->bd_buddy_page == NULL);

return 0;

@@ -1142,6 +1140,8 @@ err:
page_cache_release(e4b->bd_bitmap_page);
if (e4b->bd_buddy_page)
page_cache_release(e4b->bd_buddy_page);
+ if (page)
+ page_cache_release(page);
e4b->bd_buddy = NULL;
e4b->bd_bitmap = NULL;


2010-03-24 16:49:53

by Aneesh Kumar K.V

[permalink] [raw]
Subject: Re: [PATCH] ext4: page_cache pages not released in ext4_mb_load_buddy()

On Wed, 24 Mar 2010 22:21:01 +0800, jing zhang <[email protected]> wrote:
> From: Jing Zhang <[email protected]>
>
> Date: Wed Mar 24 20:38:48 2010
>
> If ext4_mb_init_cache() returns error, there is no page_cache_release() issued.
>
> Cc: Theodore Ts'o <[email protected]>
> Cc: Andreas Dilger <[email protected]>
> Cc: Dave Kleikamp <[email protected]>
> Signed-off-by: Jing Zhang <[email protected]>
>
> ---
>
> --- linux-2.6.32/fs/ext4/mballoc.c 2009-12-03 11:51:22.000000000 +0800
> +++ ext4_mm_leak/mballoc-9.c 2010-03-24 22:24:56.000000000 +0800
> @@ -1132,8 +1132,6 @@ repeat_load_buddy:
> e4b->bd_buddy = page_address(page) + (poff * sb->s_blocksize);
> mark_page_accessed(page);
>
> - BUG_ON(e4b->bd_bitmap_page == NULL);
> - BUG_ON(e4b->bd_buddy_page == NULL);

Why remove these ?

>
> return 0;
>
> @@ -1142,6 +1140,8 @@ err:
> page_cache_release(e4b->bd_bitmap_page);
> if (e4b->bd_buddy_page)
> page_cache_release(e4b->bd_buddy_page);
> + if (page)
> + page_cache_release(page);
> e4b->bd_buddy = NULL;
> e4b->bd_bitmap = NULL;

Can you add a comment which says on error page will point to the page
cache page which haven't been assigned to neither bd_bitmap_page or
bd_buddy_page

But good catch !!

-aneesh

2010-03-25 14:02:45

by jing zhang

[permalink] [raw]
Subject: Re: [PATCH] ext4: page_cache pages not released in ext4_mb_load_buddy()

2010/3/25, Aneesh Kumar K. V <[email protected]>:
> On Wed, 24 Mar 2010 22:21:01 +0800, jing zhang <[email protected]> wrote:
>> From: Jing Zhang <[email protected]>
>>
>> Date: Wed Mar 24 20:38:48 2010
>>
>> If ext4_mb_init_cache() returns error, there is no page_cache_release()
>> issued.
>>
>> Cc: Theodore Ts'o <[email protected]>
>> Cc: Andreas Dilger <[email protected]>
>> Cc: Dave Kleikamp <[email protected]>
>> Signed-off-by: Jing Zhang <[email protected]>
>>
>> ---
>>
>> --- linux-2.6.32/fs/ext4/mballoc.c 2009-12-03 11:51:22.000000000 +0800
>> +++ ext4_mm_leak/mballoc-9.c 2010-03-24 22:24:56.000000000 +0800
>> @@ -1132,8 +1132,6 @@ repeat_load_buddy:
>> e4b->bd_buddy = page_address(page) + (poff * sb->s_blocksize);
>> mark_page_accessed(page);
>>
>> - BUG_ON(e4b->bd_bitmap_page == NULL);
>> - BUG_ON(e4b->bd_buddy_page == NULL);
>
> Why remove these ?

Just before return successfully, both bitmap page and buddy page are assigned.
If not either, EIO will branch.

>
>>
>> return 0;
>>
>> @@ -1142,6 +1140,8 @@ err:
>> page_cache_release(e4b->bd_bitmap_page);
>> if (e4b->bd_buddy_page)
>> page_cache_release(e4b->bd_buddy_page);
>> + if (page)
>> + page_cache_release(page);
>> e4b->bd_buddy = NULL;
>> e4b->bd_bitmap = NULL;
>
> Can you add a comment which says on error page will point to the page
> cache page which haven't been assigned to neither bd_bitmap_page or
> bd_buddy_page

+ if (page)
+ /* we have to release page here in case that
+ * ext4_mb_init_cache() returns error when preparing
+ * either bitmap_ or buddy_page.
+ */
+ page_cache_release(page);

>
> But good catch !!
>
> -aneesh
>

Is that ok, Aneesh?

- zj

2010-03-26 08:04:56

by Aneesh Kumar K.V

[permalink] [raw]
Subject: Re: [PATCH] ext4: page_cache pages not released in ext4_mb_load_buddy()

On Thu, 25 Mar 2010 22:02:44 +0800, jing zhang <[email protected]> wrote:
> 2010/3/25, Aneesh Kumar K. V <[email protected]>:
> > On Wed, 24 Mar 2010 22:21:01 +0800, jing zhang <[email protected]> wrote:
> >> From: Jing Zhang <[email protected]>
> >>
> >> Date: Wed Mar 24 20:38:48 2010
> >>
> >> If ext4_mb_init_cache() returns error, there is no page_cache_release()
> >> issued.
> >>
> >> Cc: Theodore Ts'o <[email protected]>
> >> Cc: Andreas Dilger <[email protected]>
> >> Cc: Dave Kleikamp <[email protected]>
> >> Signed-off-by: Jing Zhang <[email protected]>
> >>
> >> ---
> >>
> >> --- linux-2.6.32/fs/ext4/mballoc.c 2009-12-03 11:51:22.000000000 +0800
> >> +++ ext4_mm_leak/mballoc-9.c 2010-03-24 22:24:56.000000000 +0800
> >> @@ -1132,8 +1132,6 @@ repeat_load_buddy:
> >> e4b->bd_buddy = page_address(page) + (poff * sb->s_blocksize);
> >> mark_page_accessed(page);
> >>
> >> - BUG_ON(e4b->bd_bitmap_page == NULL);
> >> - BUG_ON(e4b->bd_buddy_page == NULL);
> >
> > Why remove these ?
>
> Just before return successfully, both bitmap page and buddy page are assigned.
> If not either, EIO will branch.
>
> >
> >>
> >> return 0;
> >>
> >> @@ -1142,6 +1140,8 @@ err:
> >> page_cache_release(e4b->bd_bitmap_page);
> >> if (e4b->bd_buddy_page)
> >> page_cache_release(e4b->bd_buddy_page);
> >> + if (page)
> >> + page_cache_release(page);
> >> e4b->bd_buddy = NULL;
> >> e4b->bd_bitmap = NULL;
> >
> > Can you add a comment which says on error page will point to the page
> > cache page which haven't been assigned to neither bd_bitmap_page or
> > bd_buddy_page
>
> + if (page)
> + /* we have to release page here in case that
> + * ext4_mb_init_cache() returns error when preparing
> + * either bitmap_ or buddy_page.
> + */
> + page_cache_release(page);
>
> >
> > But good catch !!
> >
> > -aneesh
> >
>
> Is that ok, Aneesh?

looks good

-aneesh