mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <yuchao0@huawei.com>
Cc: linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, chao@kernel.org
Subject: Re: [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite()
Date: Thu, 5 Dec 2019 20:08:23 -0800	[thread overview]
Message-ID: <20191206040823.GA33758@jaegeuk-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <20191206033100.36345-1-yuchao0@huawei.com>

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

  reply	other threads:[~2019-12-06  4:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06  3:31 Chao Yu
2019-12-06  4:08 ` Jaegeuk Kim [this message]
2019-12-06  4:32   ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191206040823.GA33758@jaegeuk-macbookpro.roam.corp.google.com \
    --to=jaegeuk@kernel.org \
    --cc=chao@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®