linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite()
@ 2019-12-06  3:31 Chao Yu
  2019-12-06  4:08 ` Jaegeuk Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2019-12-06  3:31 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-kernel, linux-f2fs-devel

As Dinosaur Huang reported, there is a potential deadlock in between
GC and mkwrite():

Thread A			Thread B
- do_page_mkwrite
 - f2fs_vm_page_mkwrite
  - lock_page
				- f2fs_balance_fs
                                 - mutex_lock(gc_mutex)
				 - f2fs_gc
				  - do_garbage_collect
				   - ra_data_block
				    - grab_cache_page
  - f2fs_balance_fs
   - mutex_lock(gc_mutex)

In order to fix this, we just move f2fs_balance_fs() out of page lock's
coverage in f2fs_vm_page_mkwrite().

Reported-by: Dinosaur Huang <dinosaur.huang@unisoc.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c0560d62dbee..ed3290225506 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -67,6 +67,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 
 	f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
 
+	f2fs_balance_fs(sbi, true);
+
 	file_update_time(vmf->vma->vm_file);
 	down_read(&F2FS_I(inode)->i_mmap_sem);
 	lock_page(page);
@@ -120,8 +122,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 out_sem:
 	up_read(&F2FS_I(inode)->i_mmap_sem);
 
-	f2fs_balance_fs(sbi, dn.node_changed);
-
 	sb_end_pagefault(inode->i_sb);
 err:
 	return block_page_mkwrite_return(err);
-- 
2.18.0.rc1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite()
  2019-12-06  3:31 [f2fs-dev] [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite() Chao Yu
@ 2019-12-06  4:08 ` Jaegeuk Kim
  2019-12-06  4:32   ` Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Jaegeuk Kim @ 2019-12-06  4:08 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel

Hi Chao,

I was testing this.

https://github.com/jaegeuk/f2fs/commit/76be33b9f1fce70dd2d3f04f66d0f78b418fe3f5

On 12/06, Chao Yu wrote:
> As Dinosaur Huang reported, there is a potential deadlock in between
> GC and mkwrite():
> 
> Thread A			Thread B
> - do_page_mkwrite
>  - f2fs_vm_page_mkwrite
>   - lock_page
> 				- f2fs_balance_fs
>                                  - mutex_lock(gc_mutex)
> 				 - f2fs_gc
> 				  - do_garbage_collect
> 				   - ra_data_block
> 				    - grab_cache_page
>   - f2fs_balance_fs
>    - mutex_lock(gc_mutex)
> 
> In order to fix this, we just move f2fs_balance_fs() out of page lock's
> coverage in f2fs_vm_page_mkwrite().
> 
> Reported-by: Dinosaur Huang <dinosaur.huang@unisoc.com>
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  fs/f2fs/file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index c0560d62dbee..ed3290225506 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -67,6 +67,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
>  
>  	f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
>  
> +	f2fs_balance_fs(sbi, true);
> +
>  	file_update_time(vmf->vma->vm_file);
>  	down_read(&F2FS_I(inode)->i_mmap_sem);
>  	lock_page(page);
> @@ -120,8 +122,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
>  out_sem:
>  	up_read(&F2FS_I(inode)->i_mmap_sem);
>  
> -	f2fs_balance_fs(sbi, dn.node_changed);
> -
>  	sb_end_pagefault(inode->i_sb);
>  err:
>  	return block_page_mkwrite_return(err);
> -- 
> 2.18.0.rc1


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite()
  2019-12-06  4:08 ` Jaegeuk Kim
@ 2019-12-06  4:32   ` Chao Yu
  0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2019-12-06  4:32 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-kernel, linux-f2fs-devel

Hi Jaeguek,

On 2019/12/6 12:08, Jaegeuk Kim wrote:
> Hi Chao,
> 
> I was testing this.
> 
> https://github.com/jaegeuk/f2fs/commit/76be33b9f1fce70dd2d3f04f66d0f78b418fe3f5

The patch looks good.

BTW, do you mind adding below call stack into your patch? I guess it
describes this ABBA deadlock with more details. :)

Thanks,

> 
> On 12/06, Chao Yu wrote:
>> As Dinosaur Huang reported, there is a potential deadlock in between
>> GC and mkwrite():
>>
>> Thread A			Thread B
>> - do_page_mkwrite
>>  - f2fs_vm_page_mkwrite
>>   - lock_page
>> 				- f2fs_balance_fs
>>                                  - mutex_lock(gc_mutex)
>> 				 - f2fs_gc
>> 				  - do_garbage_collect
>> 				   - ra_data_block
>> 				    - grab_cache_page
>>   - f2fs_balance_fs
>>    - mutex_lock(gc_mutex)
>>
>> In order to fix this, we just move f2fs_balance_fs() out of page lock's
>> coverage in f2fs_vm_page_mkwrite().
>>
>> Reported-by: Dinosaur Huang <dinosaur.huang@unisoc.com>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>>  fs/f2fs/file.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index c0560d62dbee..ed3290225506 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -67,6 +67,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
>>  
>>  	f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
>>  
>> +	f2fs_balance_fs(sbi, true);
>> +
>>  	file_update_time(vmf->vma->vm_file);
>>  	down_read(&F2FS_I(inode)->i_mmap_sem);
>>  	lock_page(page);
>> @@ -120,8 +122,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
>>  out_sem:
>>  	up_read(&F2FS_I(inode)->i_mmap_sem);
>>  
>> -	f2fs_balance_fs(sbi, dn.node_changed);
>> -
>>  	sb_end_pagefault(inode->i_sb);
>>  err:
>>  	return block_page_mkwrite_return(err);
>> -- 
>> 2.18.0.rc1
> .
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

end of thread, other threads:[~2019-12-06  4:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06  3:31 [f2fs-dev] [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite() Chao Yu
2019-12-06  4:08 ` Jaegeuk Kim
2019-12-06  4:32   ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).