mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Yu <yuchao0@huawei.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
Cc: <linux-f2fs-devel@lists.sourceforge.net>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] f2fs: refactor ->page_mkwrite() flow
Date: Thu, 27 Sep 2018 13:48:08 +0800	[thread overview]
Message-ID: <3bed1658-e24a-c114-3079-62f444c613bc@huawei.com> (raw)
In-Reply-To: <20180927050509.GA72357@jaegeuk-macbookpro.roam.corp.google.com>

On 2018/9/27 13:05, Jaegeuk Kim wrote:
> This makes xfstests/083 stuck. So, I'll drop it for a while.

Alright, let me check that case again.

Thanks,

> 
> On 09/26, Chao Yu wrote:
>> From: Chao Yu <yuchao0@huawei.com>
>>
>> Thread A				Thread B
>> - f2fs_vm_page_mkwrite
>> 					- f2fs_setattr
>> 					 - down_write(i_mmap_sem)
>> 					 - truncate_setsize
>> 					 - f2fs_truncate
>> 					 - up_write(i_mmap_sem)
>>  - f2fs_reserve_block
>>  reserve NEW_ADDR
>>  - skip dirty page due to truncation
>>
>> 1. we don't need to rserve new block address for a truncated page.
>> 2. dn.data_blkaddr is used out of node page lock coverage.
>>
>> Refactor ->page_mkwrite() flow to fix above issues:
>> - use __do_map_lock() to avoid racing checkpoint()
>> - lock data page in prior to dnode page
>> - cover f2fs_reserve_block with i_mmap_sem lock
>> - access dn.data_blkaddr under dnode lock
>>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>>  fs/f2fs/file.c | 29 ++++++++++++++---------------
>>  1 file changed, 14 insertions(+), 15 deletions(-)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index 6f02c8daff76..fcb4788b48aa 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -47,7 +47,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
>>  	struct page *page = vmf->page;
>>  	struct inode *inode = file_inode(vmf->vma->vm_file);
>>  	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>> -	struct dnode_of_data dn;
>> +	struct dnode_of_data dn = { .node_changed = false };
>>  	int err;
>>  
>>  	if (unlikely(f2fs_cp_error(sbi))) {
>> @@ -59,19 +59,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
>>  
>>  	f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
>>  
>> -	/* block allocation */
>> -	f2fs_lock_op(sbi);
>> -	set_new_dnode(&dn, inode, NULL, NULL, 0);
>> -	err = f2fs_reserve_block(&dn, page->index);
>> -	if (err) {
>> -		f2fs_unlock_op(sbi);
>> -		goto out;
>> -	}
>> -	f2fs_put_dnode(&dn);
>> -	f2fs_unlock_op(sbi);
>> -
>> -	f2fs_balance_fs(sbi, dn.node_changed);
>> -
>>  	file_update_time(vmf->vma->vm_file);
>>  	down_read(&F2FS_I(inode)->i_mmap_sem);
>>  	lock_page(page);
>> @@ -108,12 +95,24 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
>>  	/* fill the page */
>>  	f2fs_wait_on_page_writeback(page, DATA, false);
>>  
>> +	/* block allocation */
>> +	__do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true);
>> +	set_new_dnode(&dn, inode, NULL, NULL, 0);
>> +	err = f2fs_reserve_block(&dn, page->index);
>> +	if (err)
>> +		goto out_unlock;
>> +
>>  	/* wait for GCed page writeback via META_MAPPING */
>>  	f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
>>  
>> +	f2fs_put_dnode(&dn);
>> +out_unlock:
>> +	__do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false);
>>  out_sem:
>>  	up_read(&F2FS_I(inode)->i_mmap_sem);
>> -out:
>> +
>> +	f2fs_balance_fs(sbi, dn.node_changed);
>> +
>>  	sb_end_pagefault(inode->i_sb);
>>  	f2fs_update_time(sbi, REQ_TIME);
>>  err:
>> -- 
>> 2.18.0
> 
> .
> 


      reply	other threads:[~2018-09-27  5:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-26 14:45 Chao Yu
2018-09-27  5:05 ` Jaegeuk Kim
2018-09-27  5:48   ` Chao Yu [this message]

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=3bed1658-e24a-c114-3079-62f444c613bc@huawei.com \
    --to=yuchao0@huawei.com \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /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®