* [PATCH v3] f2fs: fix a missing discard prefree segments
@ 2016-12-21 9:27 Yunlei He
2016-12-21 18:04 ` Jaegeuk Kim
0 siblings, 1 reply; 4+ messages in thread
From: Yunlei He @ 2016-12-21 9:27 UTC (permalink / raw)
To: linux-f2fs-devel, jaegeuk, yuchao0; +Cc: heyunlei
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 <heyunlei@huawei.com>
---
fs/f2fs/segment.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 0738f48..e0fff28 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -916,9 +916,13 @@ 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 >= cpc->trim_start &&
+ (end -1) <= cpc->trim_end)
+ 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);
@@ -2263,7 +2267,8 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
f2fs_bug_on(sbi, sit_i->dirty_sentries);
out:
if (cpc->reason == CP_DISCARD) {
- for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
+ __u64 trim_start = cpc->trim_start;
+ for (; trim_start <= cpc->trim_end; trim_start++)
add_discard_addrs(sbi, cpc);
}
mutex_unlock(&sit_i->sentry_lock);
--
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] f2fs: fix a missing discard prefree segments
2016-12-21 9:27 [PATCH v3] f2fs: fix a missing discard prefree segments Yunlei He
@ 2016-12-21 18:04 ` Jaegeuk Kim
2016-12-22 1:54 ` heyunlei
0 siblings, 1 reply; 4+ messages in thread
From: Jaegeuk Kim @ 2016-12-21 18:04 UTC (permalink / raw)
To: Yunlei He; +Cc: heyunlei, linux-f2fs-devel
On 12/21, Yunlei He wrote:
> 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 <heyunlei@huawei.com>
> ---
> fs/f2fs/segment.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 0738f48..e0fff28 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -916,9 +916,13 @@ 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 >= cpc->trim_start &&
> + (end -1) <= cpc->trim_end)
> + 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);
> @@ -2263,7 +2267,8 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
> f2fs_bug_on(sbi, sit_i->dirty_sentries);
> out:
> if (cpc->reason == CP_DISCARD) {
> - for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
> + __u64 trim_start = cpc->trim_start;
> + for (; trim_start <= cpc->trim_end; trim_start++)
BTW, why do we need this?
The below add_discard_addrs() will use cpc->trim_start.
Thanks,
> add_discard_addrs(sbi, cpc);
> }
> mutex_unlock(&sit_i->sentry_lock);
> --
> 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
> Linux-f2fs-devel@lists.sourceforge.net
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] f2fs: fix a missing discard prefree segments
2016-12-21 18:04 ` Jaegeuk Kim
@ 2016-12-22 1:54 ` heyunlei
2016-12-22 2:21 ` Jaegeuk Kim
0 siblings, 1 reply; 4+ messages in thread
From: heyunlei @ 2016-12-22 1:54 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: heyunlei, linux-f2fs-devel
Hi Jaegeuk,
On 2016/12/22 2:04, Jaegeuk Kim wrote:
> On 12/21, Yunlei He wrote:
>> 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 <heyunlei@huawei.com>
>> ---
>> fs/f2fs/segment.c | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>> index 0738f48..e0fff28 100644
>> --- a/fs/f2fs/segment.c
>> +++ b/fs/f2fs/segment.c
>> @@ -916,9 +916,13 @@ 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 >= cpc->trim_start &&
>> + (end -1) <= cpc->trim_end)
>> + 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);
>> @@ -2263,7 +2267,8 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
>> f2fs_bug_on(sbi, sit_i->dirty_sentries);
>> out:
>> if (cpc->reason == CP_DISCARD) {
>> - for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
>> + __u64 trim_start = cpc->trim_start;
>> + for (; trim_start <= cpc->trim_end; trim_start++)
>
> BTW, why do we need this?
> The below add_discard_addrs() will use cpc->trim_start.
Here, we need to reserve the original value of cpc->trim_start, because
we will use it as a boundary judgement for skipping prefree segments
discard. How about this:
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 0738f48..30cd445 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -916,9 +916,13 @@ 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 >= cpc->trim_start &&
+ (end -1) <= cpc->trim_end)
+ 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);
@@ -2263,8 +2267,11 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
f2fs_bug_on(sbi, sit_i->dirty_sentries);
out:
if (cpc->reason == CP_DISCARD) {
+ __u64 trim_start = cpc->trim_start;
for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
add_discard_addrs(sbi, cpc);
+
+ cpc->trim_start = trim_start;
}
mutex_unlock(&sit_i->sentry_lock);
Thanks,
>
> Thanks,
>
>> add_discard_addrs(sbi, cpc);
>> }
>> mutex_unlock(&sit_i->sentry_lock);
>> --
>> 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
>> Linux-f2fs-devel@lists.sourceforge.net
>> 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] f2fs: fix a missing discard prefree segments
2016-12-22 1:54 ` heyunlei
@ 2016-12-22 2:21 ` Jaegeuk Kim
0 siblings, 0 replies; 4+ messages in thread
From: Jaegeuk Kim @ 2016-12-22 2:21 UTC (permalink / raw)
To: heyunlei; +Cc: heyunlei, linux-f2fs-devel
On 12/22, heyunlei wrote:
> Hi Jaegeuk,
>
> On 2016/12/22 2:04, Jaegeuk Kim wrote:
> > On 12/21, Yunlei He wrote:
> > > 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 <heyunlei@huawei.com>
> > > ---
> > > fs/f2fs/segment.c | 9 +++++++--
> > > 1 file changed, 7 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> > > index 0738f48..e0fff28 100644
> > > --- a/fs/f2fs/segment.c
> > > +++ b/fs/f2fs/segment.c
> > > @@ -916,9 +916,13 @@ 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 >= cpc->trim_start &&
> > > + (end -1) <= cpc->trim_end)
> > > + 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);
> > > @@ -2263,7 +2267,8 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
> > > f2fs_bug_on(sbi, sit_i->dirty_sentries);
> > > out:
> > > if (cpc->reason == CP_DISCARD) {
> > > - for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
> > > + __u64 trim_start = cpc->trim_start;
> > > + for (; trim_start <= cpc->trim_end; trim_start++)
> >
> > BTW, why do we need this?
> > The below add_discard_addrs() will use cpc->trim_start.
>
> Here, we need to reserve the original value of cpc->trim_start, because
> we will use it as a boundary judgement for skipping prefree segments
> discard. How about this:
Looks good to me. :)
Could you send v4?
Thanks,
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 0738f48..30cd445 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -916,9 +916,13 @@ 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 >= cpc->trim_start &&
> + (end -1) <= cpc->trim_end)
> + 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);
> @@ -2263,8 +2267,11 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
> f2fs_bug_on(sbi, sit_i->dirty_sentries);
> out:
> if (cpc->reason == CP_DISCARD) {
> + __u64 trim_start = cpc->trim_start;
> for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
> add_discard_addrs(sbi, cpc);
> +
> + cpc->trim_start = trim_start;
> }
> mutex_unlock(&sit_i->sentry_lock);
>
> Thanks,
>
> >
> > Thanks,
> >
> > > add_discard_addrs(sbi, cpc);
> > > }
> > > mutex_unlock(&sit_i->sentry_lock);
> > > --
> > > 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
> > > Linux-f2fs-devel@lists.sourceforge.net
> > > 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-12-22 2:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-21 9:27 [PATCH v3] f2fs: fix a missing discard prefree segments Yunlei He
2016-12-21 18:04 ` Jaegeuk Kim
2016-12-22 1:54 ` heyunlei
2016-12-22 2:21 ` Jaegeuk Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).