udf: avoid redundant memcpy when writing data in ICB
PATCH 1/1 udf: avoid redundant memcpy when writing data in ICB
We have already copied the changed data of page to extent area in ICB when call ->write_end() of adinicb aops, so we do not need to copy them another time in ->writepage() of adinicb aops. SetPageUptodate is redundant too, so it's better to remove these redundant codes.
Also it looks more reasonable to set inode dirty after extent area are modified, we'd better move mark_inode_dirty() from ->writepage() to ->write_end().
--- fs/udf/file.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
fs/udf/file.c +2 -10
@@ -65,17 +65,7 @@ static int udf_adinicb_readpage(struct file *file, struct page *page)static int udf_adinicb_writepage (struct page *page,struct writeback_control *wbc) { -struct inode *inode = page->mapping->host; -char *kaddr; -struct udf_inode_info *iinfo =UDF_I (inode); -BUG_ON (!PageLocked (page)); - - kaddr =kmap (page); -memcpy (iinfo->i_ext.i_data + iinfo->i_lenEAttr, kaddr, inode->i_size); -mark_inode_dirty (inode); -SetPageUptodate (page); -kunmap (page);unlock_page (page);return 0 ;
@@ -115,6 +105,8 @@ static int udf_adinicb_write_end(struct file *file, kaddr + offset, copied);kunmap_atomic (kaddr); +mark_inode_dirty (inode); +return simple_write_end (file, mapping, pos, len, copied, page, fsdata); }
Signature · 1 line
1.7.9.5
Quoted 7 lines · Chao Yu
We have already copied the changed data of page to extent area in ICB when call ->write_end() of adinicb aops, so we do not need to copy them another time in ->writepage() of adinicb aops. SetPageUptodate is redundant too, so it's better to remove these redundant codes.
Also it looks more reasonable to set inode dirty after extent area are modified, we'd better move
mark_inode_dirty()from ->writepage() to ->write_end().
This doesn't look right. The copy is there because the page can be
modified via mmap as well, not only via buffered write... So if anything, we may be able to remove the copy in udf_adinicb_write_end() (actually using directly simple_write_end() for that), not the one in udf_adinicb_write_begin().
Honza
Quoted 41 lines
Signed-off-by Chao Yu <[email protected]>--- fs/udf/file.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)fs/udf/file.c +2
-10@@ -65,17 +65,7 @@ static int udf_adinicb_readpage(struct file *file, struct page *page)static int udf_adinicb_writepage (struct page *page,struct writeback_control *wbc) { -struct inode *inode = page->mapping->host; -char *kaddr; -struct udf_inode_info *iinfo =UDF_I (inode); -BUG_ON (!PageLocked (page)); - - kaddr =kmap (page); -memcpy (iinfo->i_ext.i_data + iinfo->i_lenEAttr, kaddr, inode->i_size); -mark_inode_dirty (inode); -SetPageUptodate (page); -kunmap (page);unlock_page (page);return 0 ;@@ -115,6 +105,8 @@ static int udf_adinicb_write_end(struct file *file, kaddr + offset, copied);kunmap_atomic (kaddr); +mark_inode_dirty (inode); +return simple_write_end (file, mapping, pos, len, copied, page, fsdata); }Signature · 1 line
1.7.9.5
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 13 lines
-----Original Message-----
From: Jan Kara [mailto:[email protected]]
Sent: Monday, July 14, 2014 4:46 PM
To: Chao Yu
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] udf: avoid redundant memcpy when writing data in ICBQuoted 5 lines · Chao Yu
We have already copied the changed data of page to extent area in ICB when call ->write_end() of adinicb aops, so we do not need to copy them another time in ->writepage() of adinicb aops. SetPageUptodate is redundant too, so it's better to remove these redundant codes.
Quoted 4 lines
Quoted 2 lines
Also it looks more reasonable to set inode dirty after extent area are modified, we'd better move
mark_inode_dirty()from ->writepage() to ->write_end().This doesn't look right. The copy is there because the page can be
modified via mmap as well, not only via buffered write... So if anything,
You're right, I have made a mistake that I have not considered the 'mmap' case, Thank you for reminding me about that. :)
Quoted 3 lines
we may be able to remove the copy in
udf_adinicb_write_end()(actually using directlysimple_write_end()for that), not the one inudf_adinicb_write_begin().
Agreed, valid data within i_size will be copied to ICB cache when we writeback the page by invoking udf_adinicb_writepage, so the copy in udf_adinicb_write_end is redundant. So our patch should be modified like the following one, is this right?
--- fs/udf/file.c | 10 ---------- 1 file changed, 10 deletions(-)
fs/udf/file.c +0 -10
@@ -105,16 +105,6 @@ static int udf_adinicb_write_end(struct file *file, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { - struct inode *inode = mapping->host; -unsigned offset = pos & (PAGE_CACHE_SIZE -1 ); -char *kaddr; -struct udf_inode_info *iinfo =UDF_I (inode); - - kaddr =kmap_atomic (page); -memcpy (iinfo->i_ext.i_data + iinfo->i_lenEAttr + offset, - kaddr + offset, copied); -kunmap_atomic (kaddr); - return simple_write_end(file, mapping, pos, len, copied, page, fsdata); }
Signature · 1 line
2.0.1.474.g72c7794
Quoted 46 lines
Honza
Quoted 38 lines
Signed-off-by Chao Yu <[email protected]>--- fs/udf/file.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)fs/udf/file.c +2
-11@@ -65,17 +65,7 @@ static int udf_adinicb_readpage(struct file *file, struct page *page)static int udf_adinicb_writepage (struct page *page,struct writeback_control *wbc) { -struct inode *inode = page->mapping->host; -char *kaddr; -struct udf_inode_info *iinfo =UDF_I (inode); -BUG_ON (!PageLocked (page)); - - kaddr =kmap (page); -memcpy (iinfo->i_ext.i_data + iinfo->i_lenEAttr, kaddr, inode->i_size); -mark_inode_dirty (inode); -SetPageUptodate (page); -kunmap (page);unlock_page (page);return 0 ;@@ -115,6 +105,8 @@ static int udf_adinicb_write_end(struct file *file, kaddr + offset, copied);kunmap_atomic (kaddr); +mark_inode_dirty (inode); +return simple_write_end (file, mapping, pos, len, copied, page, fsdata); } --Quoted 3 lines
1.7.9.5
--
Jan Kara <[email protected]>
SUSE Labs, CR
Quoted 43 lines · Chao Yu
Quoted 13 lines
-----Original Message-----
From: Jan Kara [mailto:[email protected]]
Sent: Monday, July 14, 2014 4:46 PM
To: Chao Yu
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] udf: avoid redundant memcpy when writing data in ICBQuoted 5 lines · Chao Yu
We have already copied the changed data of page to extent area in ICB when call ->write_end() of adinicb aops, so we do not need to copy them another time in ->writepage() of adinicb aops. SetPageUptodate is redundant too, so it's better to remove these redundant codes.
Quoted 4 lines
Quoted 2 lines
Also it looks more reasonable to set inode dirty after extent area are modified, we'd better move
mark_inode_dirty()from ->writepage() to ->write_end().This doesn't look right. The copy is there because the page can be
modified via mmap as well, not only via buffered write... So if anything,You're right, I have made a mistake that I have not considered the 'mmap' case, Thank you for reminding me about that. :)
Quoted 3 lines
we may be able to remove the copy in
udf_adinicb_write_end()(actually using directlysimple_write_end()for that), not the one inudf_adinicb_write_begin().Agreed, valid data within
i_sizewill be copied to ICB cache when we writeback the page by invokingudf_adinicb_writepage, so the copy inudf_adinicb_write_endis redundant. So our patch should be modified like the following one, is this right?--- fs/udf/file.c | 10 ---------- 1 file changed, 10 deletions(-)fs/udf/file.c +0
-2@@ -105,16 +105,6 @@ static int udf_adinicb_write_end(struct file *file, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { - struct inode *inode = mapping->host; -unsigned offset = pos & (PAGE_CACHE_SIZE -1 );
fs/udf/file.c static int udf_adinicb_write_end(struct file *file, · line 109
Quoted 10 lines
fs/udf/file.c +0
-8-char *kaddr; -struct udf_inode_info *iinfo =UDF_I (inode); - - kaddr =kmap_atomic (page); -memcpy (iinfo->i_ext.i_data + iinfo->i_lenEAttr + offset, - kaddr + offset, copied); -kunmap_atomic (kaddr); -return simple_write_end (file, mapping, pos, len, copied, page, fsdata); }
You can completely remove udf_adinicb_write_end() function and just usesimple_write_end() in udf_adinicb_aops.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR