f2fs: fix a missing discard prefree segments
PATCH v2 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +5 -1
@@ -916,7 +916,11 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) dirty_i->nr_dirty[PRE ] -= end - start; -if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD )) +continue ; + +if (force && start * sbi->blocks_per_seg >= cpc->trim_start && + end * sbi->blocks_per_seg <= cpc->trim_end)continue ;if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) {
Signature · 9 lines
2.10.1 ------------------------------------------------------------------------------ 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
PATCH v2 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/data.c +4 -1
@@ -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_SIZE -1 )) && (pos + len) >=i_size_read (inode)) +return 0 ; +if (blkaddr ==NEW_ADDR ) {zero_user_segment (page,0 ,PAGE_SIZE );SetPageUptodate (page);
@@ -1768,7 +1771,7 @@ static int f2fs_write_end(struct file *file,* let generic_perform_write() try to copy data again through copied=0. */ if (!PageUptodate (page)) { -if (unlikely (copied !=PAGE_SIZE )) +if (unlikely (copied != len)) copied =0 ;else SetPageUptodate (page);
Signature · 9 lines
2.10.1 ------------------------------------------------------------------------------ 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
maintainerRe: [PATCH 2/2 v2] f2fs: add a case of no need to read a page in write begin
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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)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_SIZE -1 )) && (pos + len) >=i_size_read (inode))
I added here:
zero_user_segment(page, 0, PAGE_SIZE);
Otherwise, xfstests/f2fs/001 gives a failure.
Thanks,
Quoted 28 lines
fs/f2fs/data.c +3
-1+return 0 ; +if (blkaddr ==NEW_ADDR ) {zero_user_segment (page,0 ,PAGE_SIZE );SetPageUptodate (page);@@ -1768,7 +1771,7 @@ static int f2fs_write_end(struct file *file,* let generic_perform_write() try to copy data again through copied=0. */ if (!PageUptodate (page)) { -if (unlikely (copied !=PAGE_SIZE )) +if (unlikely (copied != len)) copied =0 ;else SetPageUptodate (page);Signature · 13 lines
2.10.1 ------------------------------------------------------------------------------ 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 _______________________________________________ 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
Re: [PATCH 2/2 v2] f2fs: add a case of no need to read a page in write begin
Quoted 17 lines · Jaegeuk Kim
Quoted 16 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/f2fs/data.c +0
-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 ;
Quoted 4 lines
fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 1718
Quoted 1 line
fs/f2fs/data.c +1
-0+if (!(pos & (PAGE_SIZE -1 )) && (pos + len) >=i_size_read (inode))I added here:
zero_user_segment(page, 0, PAGE_SIZE);
Only need to zeroout in range of [len, page_size] in the page.
Thanks,
Quoted 23 lines
Otherwise, xfstests/f2fs/001 gives a failure.
Thanks,
Quoted 18 lines
fs/f2fs/data.c +3
-1+return 0 ; +if (blkaddr ==NEW_ADDR ) {zero_user_segment (page,0 ,PAGE_SIZE );SetPageUptodate (page);@@ -1768,7 +1771,7 @@ static int f2fs_write_end(struct file *file,* let generic_perform_write() try to copy data again through copied=0. */ if (!PageUptodate (page)) { -if (unlikely (copied !=PAGE_SIZE )) +if (unlikely (copied != len)) copied =0 ;else SetPageUptodate (page);Signature · 1 line
2.10.1
Quoted 13 lines
Quoted 10 lines
------------------------------------------------------------------------------
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
_______________________________________________
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
maintainerRe: [PATCH 2/2 v2] f2fs: add a case of no need to read a page in write begin
Quoted 18 lines · Chao Yu
Quoted 17 lines · Jaegeuk Kim
Quoted 16 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/f2fs/data.c +0
-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 ;
Quoted 6 lines
Quoted 4 lines
fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 1718
Quoted 1 line
fs/f2fs/data.c +1
-0+if (!(pos & (PAGE_SIZE -1 )) && (pos + len) >=i_size_read (inode))I added here:
zero_user_segment(page, 0, PAGE_SIZE);Only need to zeroout in range of [len,
page_size] in the page.
Yup, fixed.
Thanks,
Quoted 39 lines
Thanks,
Quoted 36 lines
Otherwise, xfstests/f2fs/001 gives a failure.
Thanks,
Quoted 28 lines
fs/f2fs/data.c +3
-1+return 0 ; +if (blkaddr ==NEW_ADDR ) {zero_user_segment (page,0 ,PAGE_SIZE );SetPageUptodate (page);@@ -1768,7 +1771,7 @@ static int f2fs_write_end(struct file *file,* let generic_perform_write() try to copy data again through copied=0. */ if (!PageUptodate (page)) { -if (unlikely (copied !=PAGE_SIZE )) +if (unlikely (copied != len)) copied =0 ;else SetPageUptodate (page);Signature · 13 lines
2.10.1 ------------------------------------------------------------------------------ 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 _______________________________________________ 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
Hi Jaegeuk, Yunlei,
Quoted 4 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.
From v1 patch, I guess originally Yunlei wants to skip clearing prefree segments
which is not be included in fstrim range, now v2 patch doesn't follow the original intention.
So I guess below modification is enough:
- if (force || !test_opt(sbi, DISCARD))
+ if (!test_opt(sbi, DISCARD))
Only we should consider is whether we would send redundant discards though fstrim when small discard is on.
Thoughts?
Quoted 14 lines
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/segment.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/f2fs/segment.c +0
-0@@ -916,7 +916,11 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) dirty_i->nr_dirty[PRE ] -= end - start;
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 926
Quoted 10 lines
fs/f2fs/segment.c +5
-1-if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD )) +continue ; + +if (force && start * sbi->blocks_per_seg >= cpc->trim_start && + end * sbi->blocks_per_seg <= cpc->trim_end)continue ;if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) {
------------------------------------------------------------------------------
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
Quoted 15 lines · Chao Yu
Hi Jaegeuk, Yunlei,
Quoted 4 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.
From v1 patch, I guess originally Yunlei wants to skip clearing prefree segments
which is not be included in fstrim range, now v2 patch doesn't follow the original intention.
So I guess below modification is enough:
fs/f2fs/segment.c +1
-1-if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD ))
Quoted 2 lines
Only we should consider is whether we would send redundant discards though fstrim when small discard is on.
Oh, below condition has handling redundant case, sorry for my wrong understanding.
if (force && start * sbi->blocks_per_seg >= cpc->trim_start &&
end * sbi->blocks_per_seg <= cpc->trim_end) continue;
But should fix end boundary judegment as below:
(end - 1) * sbi->blocks_per_seg <= cpc->trim_end
Thanks,
Quoted 25 lines
Thoughts?
Quoted 22 lines
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/segment.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/f2fs/segment.c +5
-1@@ -916,7 +916,11 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) dirty_i->nr_dirty[PRE ] -= end - start; -if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD )) +continue ; + +if (force && start * sbi->blocks_per_seg >= cpc->trim_start && + end * sbi->blocks_per_seg <= cpc->trim_end)continue ;
Quoted 2 lines
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 926
Quoted 2 lines
fs/f2fs/segment.c +0
-0if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) {
------------------------------------------------------------------------------
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
Hi Chao,
Quoted 21 lines · Chao Yu
Quoted 15 lines · Chao Yu
Hi Jaegeuk, Yunlei,
Quoted 4 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.
From v1 patch, I guess originally Yunlei wants to skip clearing prefree segments
which is not be included in fstrim range, now v2 patch doesn't follow the original intention.
So I guess below modification is enough:
fs/f2fs/segment.c +1
-1-if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD ))Quoted 2 lines
Only we should consider is whether we would send redundant discards though fstrim when small discard is on.
Oh, below condition has handling redundant case, sorry for my wrong understanding.
Quoted 6 lines
if (force && start *
sbi->blocks_per_seg>=cpc->trim_start&&end * sbi->blocks_per_seg <= cpc->trim_end) continue;But should fix end boundary judegment as below:
(end - 1) *sbi->blocks_per_seg<=cpc->trim_end
For example: if start=0, end=2, it means that the first and second segment is prefree, but the third segment is not.
start block address of first segment = 0 * 512 = start * 512 end block address of secnod segment = (3-1) * 512 = end * 512
So, boundary judgement has no problem?
Thanks.
Quoted 28 lines
Thanks,
Quoted 25 lines
Thoughts?
Quoted 22 lines
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/segment.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/f2fs/segment.c +5
-1@@ -916,7 +916,11 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) dirty_i->nr_dirty[PRE ] -= end - start; -if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD )) +continue ; + +if (force && start * sbi->blocks_per_seg >= cpc->trim_start && + end * sbi->blocks_per_seg <= cpc->trim_end)continue ;
Quoted 6 lines
Quoted 2 lines
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 926
Quoted 2 lines
fs/f2fs/segment.c +0
-0if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) {.
------------------------------------------------------------------------------
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
Quoted 28 lines · heyunlei
Hi Chao,
Quoted 25 lines · Chao Yu
Quoted 15 lines · Chao Yu
Hi Jaegeuk, Yunlei,
Quoted 4 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.
From v1 patch, I guess originally Yunlei wants to skip clearing prefree segments
which is not be included in fstrim range, now v2 patch doesn't follow the original intention.
So I guess below modification is enough:
fs/f2fs/segment.c +1
-1-if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD ))Quoted 2 lines
Only we should consider is whether we would send redundant discards though fstrim when small discard is on.
Oh, below condition has handling redundant case, sorry for my wrong understanding.
if (force && start *
sbi->blocks_per_seg>=cpc->trim_start&&end * sbi->blocks_per_seg <= cpc->trim_end) continue;
Quoted 8 lines
Quoted 2 lines
But should fix end boundary judegment as below:
(end - 1) *sbi->blocks_per_seg<=cpc->trim_endFor example: if start=0, end=2, it means that the first and second segment is prefree, but the third segment is not.
start block address of first segment = 0 * 512 = start * 512 end block address of secnod segment = (3-1) * 512 = end * 512
IIRC, if we want to trim [0, 1] segment during fstrim, and #0, #1 segment is prefree, so in fstrim:
start = 0
end = 2trim_start = 0trim_end = 1
So we should use (end - 1) to match trim_end, is that right?
Thanks,
Quoted 41 lines
So, boundary judgement has no problem?
Thanks.
Quoted 28 lines
Thanks,
Quoted 25 lines
Thoughts?
Quoted 22 lines
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/segment.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/f2fs/segment.c +5
-1@@ -916,7 +916,11 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) dirty_i->nr_dirty[PRE ] -= end - start; -if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD )) +continue ; + +if (force && start * sbi->blocks_per_seg >= cpc->trim_start && + end * sbi->blocks_per_seg <= cpc->trim_end)continue ;Quoted 6 lines
Quoted 2 lines
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 926
Quoted 2 lines
fs/f2fs/segment.c +0
-0if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) {.
Quoted 2 lines
.
------------------------------------------------------------------------------
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
Hi Chao,
Quoted 38 lines · Chao Yu
Quoted 28 lines · heyunlei
Hi Chao,
Quoted 25 lines · Chao Yu
Quoted 15 lines · Chao Yu
Hi Jaegeuk, Yunlei,
Quoted 4 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.
From v1 patch, I guess originally Yunlei wants to skip clearing prefree segments
which is not be included in fstrim range, now v2 patch doesn't follow the original intention.
So I guess below modification is enough:
fs/f2fs/segment.c +1
-1-if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD ))Quoted 2 lines
Only we should consider is whether we would send redundant discards though fstrim when small discard is on.
Oh, below condition has handling redundant case, sorry for my wrong understanding.
if (force && start *
sbi->blocks_per_seg>=cpc->trim_start&&end * sbi->blocks_per_seg <= cpc->trim_end) continue;Quoted 8 lines
Quoted 2 lines
But should fix end boundary judegment as below:
(end - 1) *sbi->blocks_per_seg<=cpc->trim_endFor example: if start=0, end=2, it means that the first and second segment is prefree, but the third segment is not.
start block address of first segment = 0 * 512 = start * 512 end block address of secnod segment = (3-1) * 512 = end * 512
Quoted 8 lines
IIRC, if we want to trim [0, 1] segment during fstrim, and #0, #1 segment is prefree, so in fstrim:
start = 0
end = 2trim_start= 0trim_end= 1So we should use (end - 1) to match
trim_end, is that right?
Yeah, you are right! I'll send a new version.
Thanks,
Quoted 44 lines
Thanks,
Quoted 41 lines
So, boundary judgement has no problem?
Thanks.
Quoted 34 lines
Thanks,
Quoted 25 lines
Thoughts?
Quoted 22 lines
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/segment.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/f2fs/segment.c +5
-1@@ -916,7 +916,11 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) dirty_i->nr_dirty[PRE ] -= end - start; -if (force || !test_opt (sbi,DISCARD )) +if (!test_opt (sbi,DISCARD )) +continue ; + +if (force && start * sbi->blocks_per_seg >= cpc->trim_start && + end * sbi->blocks_per_seg <= cpc->trim_end)continue ;Quoted 2 lines
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 926
Quoted 2 lines
fs/f2fs/segment.c +0
-0if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) {.
Quoted 6 lines
Quoted 2 lines
.
.
------------------------------------------------------------------------------
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