f2fs: fix a missing discard prefree segments
PATCH 1/2 f2fs: fix a missing discard prefree segments
If userspace issue a fstrim with a range not involve prefree segments, it will reuse these segments without discard. This patch fix it.
--- fs/f2fs/segment.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/f2fs/segment.c +6 -3
@@ -899,6 +899,9 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned int secno, start_segno;bool force = (cpc->reason ==CP_DISCARD ); +if (!test_opt (sbi,DISCARD )) +return ; +blk_start_plug (&plug);mutex_lock (&dirty_i->seglist_lock);
@@ -910,15 +913,15 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)break ; end =find_next_zero_bit (prefree_map,MAIN_SEGS (sbi), start +1 ); +if (force && start * sbi->blocks_per_seg >= cpc->trim_start && + end * sbi->blocks_per_seg <= cpc->trim_end) +continue ;for (i = start; i < end; i++)clear_bit (i, prefree_map); dirty_i->nr_dirty[PRE ] -= end - start; -if (force || !test_opt (sbi,DISCARD )) -continue ; -if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) {f2fs_issue_discard (sbi,START_BLOCK (sbi, start), (end - start) << sbi->log_blocks_per_seg);
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/2 f2fs: add a case of no need to read a page in write begin
If the range we write cover the whole valid data
in the last page, we do not need to read it.
--- fs/f2fs/data.c | 3 +++ 1 file changed, 3 insertions(+)
fs/f2fs/data.c +3 -0
@@ -1715,6 +1715,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,if (len ==PAGE_SIZE ||PageUptodate (page))return 0 ; +if (!(pos %PAGE_SHIFT ) && (pos + len) >i_size_read (inode)) +return 0 ; +if (blkaddr ==NEW_ADDR ) {zero_user_segment (page,0 ,PAGE_SIZE );SetPageUptodate (page);
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
Jaegeuk Kim
maintainerRe: [PATCH 2/2] f2fs: add a case of no need to read a page in write begin
Hi,
Quoted 13 lines · Yunlei He
If the range we write cover the whole valid data
in the last page, we do not need to read it.Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/data.c | 3 +++ 1 file changed, 3 insertions(+)fs/f2fs/data.c +0
-0
fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 1718
Quoted 4 lines
fs/f2fs/data.c +1
-0@@ -1715,6 +1715,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,if (len ==PAGE_SIZE ||PageUptodate (page))return 0 ; +if (!(pos %PAGE_SHIFT ) && (pos + len) >i_size_read (inode))
PAGE_SHIFT?
Do you mean like this?
if (!(pos % PAGE_MASK) && (pos + len) >= i_size_read(inode))
And, it needs to change f2fs_write_end() together.
/* Need to change comments */
if (!PageUptodate(page)) {
if (unlikely(copied != len)) <== like this?
copied = 0;
else
...Thanks,
Quoted 16 lines
fs/f2fs/data.c +2
-0+return 0 ; +if (blkaddr ==NEW_ADDR ) {zero_user_segment (page,0 ,PAGE_SIZE );SetPageUptodate (page);Signature · 10 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 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
Jaegeuk Kim
maintainerHi Yunlei,
Quoted 13 lines · Yunlei He
If userspace issue a fstrim with a range not involve prefree segments, it will reuse these segments without discard. This patch fix it.
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/segment.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fs/f2fs/segment.c +0
-0
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 903
Quoted 5 lines
fs/f2fs/segment.c +2
-0@@ -899,6 +899,9 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned int secno, start_segno;bool force = (cpc->reason ==CP_DISCARD ); +if (!test_opt (sbi,DISCARD )) +return ;
We need to clear the prefree bits, even if discard option was not set.
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 918
Quoted 11 lines
fs/f2fs/segment.c +4
-0+blk_start_plug (&plug);mutex_lock (&dirty_i->seglist_lock);@@ -910,15 +913,15 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)break ; end =find_next_zero_bit (prefree_map,MAIN_SEGS (sbi), start +1 ); +if (force && start * sbi->blocks_per_seg >= cpc->trim_start && + end * sbi->blocks_per_seg <= cpc->trim_end) +continue ;
ditto.
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 920
Quoted 8 lines
fs/f2fs/segment.c +0
-2for (i = start; i < end; i++)clear_bit (i, prefree_map); dirty_i->nr_dirty[PRE ] -= end - start; -if (force || !test_opt (sbi,DISCARD )) -continue ;
Why not just adding that condition here?
Thanks,
Quoted 15 lines
fs/f2fs/segment.c +0
-1-if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) {f2fs_issue_discard (sbi,START_BLOCK (sbi, start), (end - start) << sbi->log_blocks_per_seg);Signature · 10 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 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel