optimize IPU
cover optimize IPU
For IPU, there is no need to read dnode, these three patches are to fix this issue.
patch 1): Reconstruct code in do_write_data_page, code logic stays unchanged, patch 2): Under high-probability IPU scenario, we check extent_tree first patch 3): Unlock dnode before IPU
Hou Pengyang (3):
f2fs: reconstruct code to write a data page
f2fs: lookup extent cache first under IPU scenario
f2fs: unlock dnode before IPU
fs/f2fs/data.c | 94 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 22 deletions(-)
Signature · 6 lines
2.10.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 1/3 f2fs: reconstruct code to write a data page
This patch introduces two functions:
1) f2fs_encrypt_page -- encrypt data page before submit_bio
2) do_rewrite_data_page -- IPU rewrite
The two functions are extraced from do_write_data_page, logic in do_write_data_page stays unchanged.
--- fs/f2fs/data.c | 66 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 22 deletions(-)
fs/f2fs/data.c +44 -22
@@ -1302,26 +1302,11 @@ static int f2fs_read_data_pages(struct file *file,return f2fs_mpage_readpages (mapping, pages,NULL , nr_pages); } -int do_write_data_page (struct f2fs_io_info *fio) +static int f2fs_encrypt_page (struct f2fs_io_info *fio,struct page *page) { -struct page *page = fio->page;struct inode *inode = page->mapping->host; -struct dnode_of_data dn;int err =0 ; -set_new_dnode (&dn, inode,NULL ,NULL ,0 ); - err =get_dnode_of_data (&dn, page->index,LOOKUP_NODE ); -if (err) -return err; - - fio->old_blkaddr = dn.data_blkaddr; - -/* This page is already truncated */ -if (fio->old_blkaddr ==NULL_ADDR ) { -ClearPageUptodate (page); - goto out_writepage; - } -if (f2fs_encrypted_inode (inode) &&S_ISREG (inode->i_mode)) {gfp_t gfp_flags =GFP_NOFS ;
@@ -1343,9 +1328,50 @@ int do_write_data_page(struct f2fs_io_info *fio) err =0 ; goto retry_encrypt; } - goto out_writepage; +return err; } } +return err; +} + +static int do_rewrite_data_page (struct f2fs_io_info *fio,struct page *page) +{ +struct inode *inode = page->mapping->host; +int err; + +f2fs_bug_on (F2FS_P_SB (page), !fio->cp_rwsem_locked); + +f2fs_unlock_op (F2FS_I_SB (inode)); + fio->cp_rwsem_locked = false; + err =rewrite_data_page (fio); +set_inode_flag (inode,FI_UPDATE_WRITE ); +trace_f2fs_do_write_data_page (page,IPU ); +return err; + +} + +int do_write_data_page (struct f2fs_io_info *fio) +{ +struct page *page = fio->page; +struct inode *inode = page->mapping->host; +struct dnode_of_data dn; +int err =0 ; + +set_new_dnode (&dn, inode,NULL ,NULL ,0 ); + err =get_dnode_of_data (&dn, page->index,LOOKUP_NODE ); +if (err) +return err; + + fio->old_blkaddr = dn.data_blkaddr; + +/* This page is already truncated */ +if (fio->old_blkaddr ==NULL_ADDR ) { +ClearPageUptodate (page); + goto out_writepage; + } + +if (f2fs_encrypt_page (fio, page)) + goto out_writepage;set_page_writeback (page);
@@ -1357,11 +1383,7 @@ int do_write_data_page(struct f2fs_io_info *fio) !is_cold_data(page) && !IS_ATOMIC_WRITTEN_PAGE(page) && need_inplace_update(inode, fio))) { - f2fs_unlock_op(F2FS_I_SB(inode)); - fio->cp_rwsem_locked = false; - err = rewrite_data_page(fio); - set_inode_flag(inode, FI_UPDATE_WRITE); - trace_f2fs_do_write_data_page(page, IPU); + err = do_rewrite_data_page(fio, page); } else {write_data_page (&dn, fio);trace_f2fs_do_write_data_page (page,OPU );
Signature · 6 lines
2.10.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 2/3 f2fs: lookup extent cache first under IPU scenario
In reply to Hou PengyangIf a page is cold, NOT atomit written and need_ipu now, there is a high probability that IPU should be adapted. For IPU, we try to check extent tree to get the block index first, instead of reading the dnode page, where may lead to an useless dnode IO, since no need to update the dnode index for IPU.
--- fs/f2fs/data.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
fs/f2fs/data.c +26 -0
@@ -1355,8 +1355,34 @@ int do_write_data_page(struct f2fs_io_info *fio)struct page *page = fio->page;struct inode *inode = page->mapping->host;struct dnode_of_data dn; +struct extent_info ei = {0 ,0 ,0 };int err =0 ; +/* +* If a page is cold, NOT atomit written and need_ipu now, there is +* a high probability that IPU should be adapted. For IPU, we try to +* check extent tree to get the block index first, instead of reading +* the dnode page, where may lead to an useless dnode IO, since no need to +* update the dnode index for IPU. +*/ +if (unlikely (!is_cold_data (page) && + !IS_ATOMIC_WRITTEN_PAGE (page) && +need_inplace_update (inode, fio) && +f2fs_lookup_extent_cache (inode, page->index, &ei))) { + + fio->old_blkaddr = ei.blk + page->index - ei.fofs; + +if (fio->old_blkaddr !=NEW_ADDR && + fio->old_blkaddr !=NULL_ADDR ) { + err =f2fs_encrypt_page (fio, page); +if (err) +return err; +set_page_writeback (page); + err =do_rewrite_data_page (fio, page); +return err; + } + } +set_new_dnode (&dn, inode,NULL ,NULL ,0 ); err =get_dnode_of_data (&dn, page->index,LOOKUP_NODE );if (err)
Signature · 6 lines
2.10.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Re: [PATCH 2/3] f2fs: lookup extent cache first under IPU scenario
Hi all,
Could we move IPU judgement outside cp_rwsem lock like below:
if (set ipu policy)
if (ipu success)
returnlock_op
opuunlock_op
And at same time when we write new checkpoint, we set ipu policy during whole cp, the process is like this:
....|----OPU----|----IPU(write cp)----|----OPU----|----IPU(write cp)----|....
Thanks.
Quoted 41 lines · Hou Pengyang
If a page is cold, NOT atomit written and
need_ipunow, there is a high probability that IPU should be adapted. For IPU, we try to check extent tree to get the block index first, instead of reading the dnode page, where may lead to an useless dnode IO, since no need to update the dnode index for IPU.Signed-off-by Hou Pengyang <[email protected]>--- fs/f2fs/data.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)fs/f2fs/data.c +19
-0@@ -1355,8 +1355,34 @@ int do_write_data_page(struct f2fs_io_info *fio)struct page *page = fio->page;struct inode *inode = page->mapping->host;struct dnode_of_data dn; +struct extent_info ei = {0 ,0 ,0 };int err =0 ; +/* +* If a page is cold, NOT atomit written and need_ipu now, there is +* a high probability that IPU should be adapted. For IPU, we try to +* check extent tree to get the block index first, instead of reading +* the dnode page, where may lead to an useless dnode IO, since no need to +* update the dnode index for IPU. +*/ +if (unlikely (!is_cold_data (page) && + !IS_ATOMIC_WRITTEN_PAGE (page) && +need_inplace_update (inode, fio) && +f2fs_lookup_extent_cache (inode, page->index, &ei))) { + + fio->old_blkaddr = ei.blk + page->index - ei.fofs; + +if (fio->old_blkaddr !=NEW_ADDR && + fio->old_blkaddr !=NULL_ADDR ) { + err =f2fs_encrypt_page (fio, page); +if (err)
fs/f2fs/data.c int do_write_data_page(struct f2fs_io_info *fio) · line 1388
Quoted 10 lines
fs/f2fs/data.c +7
-0+return err; +set_page_writeback (page); + err =do_rewrite_data_page (fio, page); +return err; + } + } +set_new_dnode (&dn, inode,NULL ,NULL ,0 ); err =get_dnode_of_data (&dn, page->index,LOOKUP_NODE );if (err)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 3/3 f2fs: unlock dnode before IPU
In reply to Hou Pengyang--- fs/f2fs/data.c | 2 ++ 1 file changed, 2 insertions(+)
fs/f2fs/data.c +2 -0
@@ -1409,7 +1409,9 @@ int do_write_data_page(struct f2fs_io_info *fio) !is_cold_data(page) && !IS_ATOMIC_WRITTEN_PAGE(page) && need_inplace_update(inode, fio))) { + f2fs_put_dnode(&dn); err = do_rewrite_data_page(fio, page); + return err; } else {write_data_page (&dn, fio);trace_f2fs_do_write_data_page (page,OPU );
Signature · 6 lines
2.10.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot