All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix memory leak for page count
@ 2020-07-17 10:22 robbieko
  2020-07-17 12:00 ` Filipe Manana
  0 siblings, 1 reply; 4+ messages in thread
From: robbieko @ 2020-07-17 10:22 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Robbie Ko

From: Robbie Ko <robbieko@synology.com>

When lock_delalloc_page, we first lock the page and then
check that the page dirty, if the page is not dirty, we
will return -EAGAIN but all pages must be freed, otherwise
page leak.

Signed-off-by: Robbie Ko <robbieko@synology.com>
---
 fs/btrfs/extent_io.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 68c96057ad2d..34d55b1e2a88 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1951,7 +1951,7 @@ static int __process_pages_contig(struct address_space *mapping,
 	struct page *pages[16];
 	unsigned ret;
 	int err = 0;
-	int i;
+	int i, j;
 
 	if (page_ops & PAGE_LOCK) {
 		ASSERT(page_ops == PAGE_LOCK);
@@ -1999,7 +1999,8 @@ static int __process_pages_contig(struct address_space *mapping,
 				if (!PageDirty(pages[i]) ||
 				    pages[i]->mapping != mapping) {
 					unlock_page(pages[i]);
-					put_page(pages[i]);
+					for (j = i; j < ret; j++)
+						put_page(pages[j]);
 					err = -EAGAIN;
 					goto out;
 				}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: fix memory leak for page count
  2020-07-17 10:22 [PATCH] btrfs: fix memory leak for page count robbieko
@ 2020-07-17 12:00 ` Filipe Manana
  2020-07-17 12:27   ` Nikolay Borisov
  2020-07-20  1:27   ` Robbie Ko
  0 siblings, 2 replies; 4+ messages in thread
From: Filipe Manana @ 2020-07-17 12:00 UTC (permalink / raw)
  To: robbieko; +Cc: linux-btrfs

On Fri, Jul 17, 2020 at 11:23 AM robbieko <robbieko@synology.com> wrote:
>
> From: Robbie Ko <robbieko@synology.com>
>
> When lock_delalloc_page, we first lock the page and then
> check that the page dirty, if the page is not dirty, we
> will return -EAGAIN but all pages must be freed, otherwise
> page leak.

"When lock_delalloc_page" -> When locking pages for delalloc

We check if it's dirty and if the mapping still matches.

Btw, you can make line length closer to 75 characters, it makes things
a bit more readable.

The subject is also a bit confusing:

"btrfs: fix memory leak for page count"

something along the lines "btrfs: fix page leaks after failure to lock
page for delalloc" would be more clear to me at least,
it gives a clue about where the problem is.

>
> Signed-off-by: Robbie Ko <robbieko@synology.com>

The code looks correct, thanks.

Reviewed-by: Filipe Manana <fdmanana@suse.com>

> ---
>  fs/btrfs/extent_io.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 68c96057ad2d..34d55b1e2a88 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -1951,7 +1951,7 @@ static int __process_pages_contig(struct address_space *mapping,
>         struct page *pages[16];
>         unsigned ret;
>         int err = 0;
> -       int i;
> +       int i, j;
>
>         if (page_ops & PAGE_LOCK) {
>                 ASSERT(page_ops == PAGE_LOCK);
> @@ -1999,7 +1999,8 @@ static int __process_pages_contig(struct address_space *mapping,
>                                 if (!PageDirty(pages[i]) ||
>                                     pages[i]->mapping != mapping) {
>                                         unlock_page(pages[i]);
> -                                       put_page(pages[i]);
> +                                       for (j = i; j < ret; j++)
> +                                               put_page(pages[j]);
>                                         err = -EAGAIN;
>                                         goto out;
>                                 }
> --
> 2.17.1
>


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: fix memory leak for page count
  2020-07-17 12:00 ` Filipe Manana
@ 2020-07-17 12:27   ` Nikolay Borisov
  2020-07-20  1:27   ` Robbie Ko
  1 sibling, 0 replies; 4+ messages in thread
From: Nikolay Borisov @ 2020-07-17 12:27 UTC (permalink / raw)
  To: fdmanana, robbieko; +Cc: linux-btrfs



On 17.07.20 г. 15:00 ч., Filipe Manana wrote:
> On Fri, Jul 17, 2020 at 11:23 AM robbieko <robbieko@synology.com> wrote:
>>
>> From: Robbie Ko <robbieko@synology.com>
>>
>> When lock_delalloc_page, we first lock the page and then
>> check that the page dirty, if the page is not dirty, we
>> will return -EAGAIN but all pages must be freed, otherwise
>> page leak.
> 
> "When lock_delalloc_page" -> When locking pages for delalloc
> 
> We check if it's dirty and if the mapping still matches.
> 
> Btw, you can make line length closer to 75 characters, it makes things
> a bit more readable.
> 
> The subject is also a bit confusing:
> 
> "btrfs: fix memory leak for page count"
> 
> something along the lines "btrfs: fix page leaks after failure to lock
> page for delalloc" would be more clear to me at least,
> it gives a clue about where the problem is.
> 
>>
>> Signed-off-by: Robbie Ko <robbieko@synology.com>
> 
> The code looks correct, thanks.
> 
> Reviewed-by: Filipe Manana <fdmanana@suse.com>
> 
>> ---
>>  fs/btrfs/extent_io.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
>> index 68c96057ad2d..34d55b1e2a88 100644
>> --- a/fs/btrfs/extent_io.c
>> +++ b/fs/btrfs/extent_io.c
>> @@ -1951,7 +1951,7 @@ static int __process_pages_contig(struct address_space *mapping,
>>         struct page *pages[16];
>>         unsigned ret;
>>         int err = 0;
>> -       int i;
>> +       int i, j;
>>
>>         if (page_ops & PAGE_LOCK) {
>>                 ASSERT(page_ops == PAGE_LOCK);
>> @@ -1999,7 +1999,8 @@ static int __process_pages_contig(struct address_space *mapping,
>>                                 if (!PageDirty(pages[i]) ||
>>                                     pages[i]->mapping != mapping) {
>>                                         unlock_page(pages[i]);
>> -                                       put_page(pages[i]);
>> +                                       for (j = i; j < ret; j++)
>> +                                               put_page(pages[j]);

nit: You don't need to introduce another variable, you can simply reuse
i from its current value:
for(; i < ret; i++)
  put_pages(pages[j]

If 'j' is to be used I'da rather have it defined in the 'if' branch so
it's lifespan is clearly visible.

>>                                         err = -EAGAIN;
>>                                         goto out;
>>                                 }
>> --
>> 2.17.1
>>
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: fix memory leak for page count
  2020-07-17 12:00 ` Filipe Manana
  2020-07-17 12:27   ` Nikolay Borisov
@ 2020-07-20  1:27   ` Robbie Ko
  1 sibling, 0 replies; 4+ messages in thread
From: Robbie Ko @ 2020-07-20  1:27 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs


Filipe Manana 於 2020/7/17 下午8:00 寫道:
> On Fri, Jul 17, 2020 at 11:23 AM robbieko <robbieko@synology.com> wrote:
>> From: Robbie Ko <robbieko@synology.com>
>>
>> When lock_delalloc_page, we first lock the page and then
>> check that the page dirty, if the page is not dirty, we
>> will return -EAGAIN but all pages must be freed, otherwise
>> page leak.
> "When lock_delalloc_page" -> When locking pages for delalloc
>
> We check if it's dirty and if the mapping still matches.
>
> Btw, you can make line length closer to 75 characters, it makes things
> a bit more readable.
>
> The subject is also a bit confusing:
>
> "btrfs: fix memory leak for page count"
>
> something along the lines "btrfs: fix page leaks after failure to lock
> page for delalloc" would be more clear to me at least,
> it gives a clue about where the problem is.

OK, I will resend patch.

Thanks.

>> Signed-off-by: Robbie Ko <robbieko@synology.com>
> The code looks correct, thanks.
>
> Reviewed-by: Filipe Manana <fdmanana@suse.com>
>
>> ---
>>   fs/btrfs/extent_io.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
>> index 68c96057ad2d..34d55b1e2a88 100644
>> --- a/fs/btrfs/extent_io.c
>> +++ b/fs/btrfs/extent_io.c
>> @@ -1951,7 +1951,7 @@ static int __process_pages_contig(struct address_space *mapping,
>>          struct page *pages[16];
>>          unsigned ret;
>>          int err = 0;
>> -       int i;
>> +       int i, j;
>>
>>          if (page_ops & PAGE_LOCK) {
>>                  ASSERT(page_ops == PAGE_LOCK);
>> @@ -1999,7 +1999,8 @@ static int __process_pages_contig(struct address_space *mapping,
>>                                  if (!PageDirty(pages[i]) ||
>>                                      pages[i]->mapping != mapping) {
>>                                          unlock_page(pages[i]);
>> -                                       put_page(pages[i]);
>> +                                       for (j = i; j < ret; j++)
>> +                                               put_page(pages[j]);
>>                                          err = -EAGAIN;
>>                                          goto out;
>>                                  }
>> --
>> 2.17.1
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-20  1:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 10:22 [PATCH] btrfs: fix memory leak for page count robbieko
2020-07-17 12:00 ` Filipe Manana
2020-07-17 12:27   ` Nikolay Borisov
2020-07-20  1:27   ` Robbie Ko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.