Commit 279d6df2 authored by Hou Pengyang's avatar Hou Pengyang Committed by Jaegeuk Kim

f2fs: release cp and dnode lock before IPU

We don't need to rewrite the page under cp_rwsem and dnode locks.
Signed-off-by: default avatarHou Pengyang <houpengyang@huawei.com>
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 9a744b92
...@@ -1368,12 +1368,17 @@ int do_write_data_page(struct f2fs_io_info *fio) ...@@ -1368,12 +1368,17 @@ int do_write_data_page(struct f2fs_io_info *fio)
if (valid_ipu_blkaddr(fio)) { if (valid_ipu_blkaddr(fio)) {
ipu_force = true; ipu_force = true;
fio->need_lock = false;
goto got_it; goto got_it;
} }
} }
if (fio->need_lock)
f2fs_lock_op(fio->sbi);
err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE); err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE);
if (err) if (err)
return err; goto out;
fio->old_blkaddr = dn.data_blkaddr; fio->old_blkaddr = dn.data_blkaddr;
...@@ -1394,22 +1399,26 @@ int do_write_data_page(struct f2fs_io_info *fio) ...@@ -1394,22 +1399,26 @@ int do_write_data_page(struct f2fs_io_info *fio)
* it had better in-place writes for updated data. * it had better in-place writes for updated data.
*/ */
if (ipu_force || (valid_ipu_blkaddr(fio) && need_inplace_update(fio))) { if (ipu_force || (valid_ipu_blkaddr(fio) && need_inplace_update(fio))) {
f2fs_bug_on(fio->sbi, !fio->cp_rwsem_locked); f2fs_put_dnode(&dn);
f2fs_unlock_op(fio->sbi); if (fio->need_lock)
fio->cp_rwsem_locked = false; f2fs_unlock_op(fio->sbi);
err = rewrite_data_page(fio); err = rewrite_data_page(fio);
trace_f2fs_do_write_data_page(fio->page, IPU); trace_f2fs_do_write_data_page(fio->page, IPU);
set_inode_flag(inode, FI_UPDATE_WRITE); set_inode_flag(inode, FI_UPDATE_WRITE);
} else { return err;
write_data_page(&dn, fio);
trace_f2fs_do_write_data_page(page, OPU);
set_inode_flag(inode, FI_APPEND_WRITE);
if (page->index == 0)
set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN);
} }
/* LFS mode write path */
write_data_page(&dn, fio);
trace_f2fs_do_write_data_page(page, OPU);
set_inode_flag(inode, FI_APPEND_WRITE);
if (page->index == 0)
set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN);
out_writepage: out_writepage:
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
out:
if (fio->need_lock)
f2fs_unlock_op(fio->sbi);
return err; return err;
} }
...@@ -1434,7 +1443,7 @@ static int __write_data_page(struct page *page, bool *submitted, ...@@ -1434,7 +1443,7 @@ static int __write_data_page(struct page *page, bool *submitted,
.page = page, .page = page,
.encrypted_page = NULL, .encrypted_page = NULL,
.submitted = false, .submitted = false,
.cp_rwsem_locked = true, .need_lock = true,
}; };
trace_f2fs_writepage(page, DATA); trace_f2fs_writepage(page, DATA);
...@@ -1470,6 +1479,7 @@ static int __write_data_page(struct page *page, bool *submitted, ...@@ -1470,6 +1479,7 @@ static int __write_data_page(struct page *page, bool *submitted,
/* Dentry blocks are controlled by checkpoint */ /* Dentry blocks are controlled by checkpoint */
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
fio.need_lock = false;
err = do_write_data_page(&fio); err = do_write_data_page(&fio);
goto done; goto done;
} }
...@@ -1487,13 +1497,12 @@ static int __write_data_page(struct page *page, bool *submitted, ...@@ -1487,13 +1497,12 @@ static int __write_data_page(struct page *page, bool *submitted,
if (!err) if (!err)
goto out; goto out;
} }
f2fs_lock_op(sbi);
if (err == -EAGAIN) if (err == -EAGAIN)
err = do_write_data_page(&fio); err = do_write_data_page(&fio);
if (F2FS_I(inode)->last_disk_size < psize) if (F2FS_I(inode)->last_disk_size < psize)
F2FS_I(inode)->last_disk_size = psize; F2FS_I(inode)->last_disk_size = psize;
if (fio.cp_rwsem_locked)
f2fs_unlock_op(sbi);
done: done:
if (err && err != -ENOENT) if (err && err != -ENOENT)
goto redirty_out; goto redirty_out;
......
...@@ -803,7 +803,7 @@ struct f2fs_io_info { ...@@ -803,7 +803,7 @@ struct f2fs_io_info {
struct page *page; /* page to be written */ struct page *page; /* page to be written */
struct page *encrypted_page; /* encrypted page */ struct page *encrypted_page; /* encrypted page */
bool submitted; /* indicate IO submission */ bool submitted; /* indicate IO submission */
bool cp_rwsem_locked; /* indicate cp_rwsem is held */ bool need_lock; /* indicate we need to lock cp_rwsem */
}; };
#define is_read_io(rw) ((rw) == READ) #define is_read_io(rw) ((rw) == READ)
......
...@@ -717,6 +717,7 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type, ...@@ -717,6 +717,7 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
.old_blkaddr = NULL_ADDR, .old_blkaddr = NULL_ADDR,
.page = page, .page = page,
.encrypted_page = NULL, .encrypted_page = NULL,
.need_lock = true,
}; };
bool is_dirty = PageDirty(page); bool is_dirty = PageDirty(page);
int err; int err;
......
...@@ -312,6 +312,7 @@ static int __commit_inmem_pages(struct inode *inode, ...@@ -312,6 +312,7 @@ static int __commit_inmem_pages(struct inode *inode,
fio.page = page; fio.page = page;
fio.old_blkaddr = NULL_ADDR; fio.old_blkaddr = NULL_ADDR;
fio.encrypted_page = NULL; fio.encrypted_page = NULL;
fio.need_lock = false,
err = do_write_data_page(&fio); err = do_write_data_page(&fio);
if (err) { if (err) {
unlock_page(page); unlock_page(page);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment