* [PATCH] f2fs: add a modify discard command function
@ 2017-02-27 7:19 Yunlei He
2017-02-27 23:08 ` Jaegeuk Kim
0 siblings, 1 reply; 5+ messages in thread
From: Yunlei He @ 2017-02-27 7:19 UTC (permalink / raw)
To: jaegeuk, yuchao0, linux-f2fs-devel
This patch add a function to modify discard command if one segment
reuse before discard. Split this segment from multi-segments discard
range, and discard the left bigger range.
Signed-off-by: Yunlei He <heyunlei@huawei.com>
---
fs/f2fs/segment.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 9006d8e..5af736b 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
kmem_cache_free(discard_cmd_slab, dc);
}
+static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)
+{
+ block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
+
+ if (dc->lstart + dc->len <= end_block) {
+ __remove_discard_cmd(sbi, dc);
+ return;
+ }
+
+ if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {
+ dc->lstart = end_block;
+ dc->len -= (end_block - dc->lstart);
+ } else
+ dc->len = blkaddr - dc->lstart;
+}
+
/* This should be covered by global mutex, &sit_i->sentry_lock */
void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
{
@@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
if (dc->state == D_SUBMIT)
wait_for_completion_io(&dc->wait);
else
- __remove_discard_cmd(sbi, dc);
+ __modify_discard_cmd(sbi, dc, blkaddr);
}
}
blk_finish_plug(&plug);
--
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] f2fs: add a modify discard command function
2017-02-27 7:19 [PATCH] f2fs: add a modify discard command function Yunlei He
@ 2017-02-27 23:08 ` Jaegeuk Kim
2017-02-28 1:51 ` heyunlei
0 siblings, 1 reply; 5+ messages in thread
From: Jaegeuk Kim @ 2017-02-27 23:08 UTC (permalink / raw)
To: Yunlei He; +Cc: linux-f2fs-devel
On 02/27, Yunlei He wrote:
> This patch add a function to modify discard command if one segment
> reuse before discard. Split this segment from multi-segments discard
> range, and discard the left bigger range.
Now MAX_DISCARD_BLOCKS() is set to section size, so there will be no
multi-sections discard range. Am I missing some cases?
Thanks,
>
> Signed-off-by: Yunlei He <heyunlei@huawei.com>
> ---
> fs/f2fs/segment.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 9006d8e..5af736b 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
> kmem_cache_free(discard_cmd_slab, dc);
> }
>
> +static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)
> +{
> + block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
> +
> + if (dc->lstart + dc->len <= end_block) {
> + __remove_discard_cmd(sbi, dc);
> + return;
> + }
> +
> + if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {
> + dc->lstart = end_block;
> + dc->len -= (end_block - dc->lstart);
> + } else
> + dc->len = blkaddr - dc->lstart;
> +}
> +
> /* This should be covered by global mutex, &sit_i->sentry_lock */
> void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
> {
> @@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
> if (dc->state == D_SUBMIT)
> wait_for_completion_io(&dc->wait);
> else
> - __remove_discard_cmd(sbi, dc);
> + __modify_discard_cmd(sbi, dc, blkaddr);
> }
> }
> blk_finish_plug(&plug);
> --
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] f2fs: add a modify discard command function
2017-02-27 23:08 ` Jaegeuk Kim
@ 2017-02-28 1:51 ` heyunlei
2017-03-01 19:48 ` Jaegeuk Kim
0 siblings, 1 reply; 5+ messages in thread
From: heyunlei @ 2017-02-28 1:51 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: linux-f2fs-devel
Hi Jaegeuk,
On 2017/2/28 7:08, Jaegeuk Kim wrote:
> On 02/27, Yunlei He wrote:
>> This patch add a function to modify discard command if one segment
>> reuse before discard. Split this segment from multi-segments discard
>> range, and discard the left bigger range.
>
> Now MAX_DISCARD_BLOCKS() is set to section size, so there will be no
> multi-sections discard range. Am I missing some cases?
I think MAX_DISCARD_BLOCKS() just limit small discard and fstrim, f2fs
can still send multi-segments discard range if prefree segments is continuous.
Thanks.
>
> Thanks,
>
>>
>> Signed-off-by: Yunlei He <heyunlei@huawei.com>
>> ---
>> fs/f2fs/segment.c | 18 +++++++++++++++++-
>> 1 file changed, 17 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>> index 9006d8e..5af736b 100644
>> --- a/fs/f2fs/segment.c
>> +++ b/fs/f2fs/segment.c
>> @@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
>> kmem_cache_free(discard_cmd_slab, dc);
>> }
>>
>> +static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)
>> +{
>> + block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
>> +
>> + if (dc->lstart + dc->len <= end_block) {
>> + __remove_discard_cmd(sbi, dc);
>> + return;
>> + }
>> +
>> + if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {
>> + dc->lstart = end_block;
>> + dc->len -= (end_block - dc->lstart);
>> + } else
>> + dc->len = blkaddr - dc->lstart;
>> +}
>> +
>> /* This should be covered by global mutex, &sit_i->sentry_lock */
>> void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
>> {
>> @@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
>> if (dc->state == D_SUBMIT)
>> wait_for_completion_io(&dc->wait);
>> else
>> - __remove_discard_cmd(sbi, dc);
>> + __modify_discard_cmd(sbi, dc, blkaddr);
>> }
>> }
>> blk_finish_plug(&plug);
>> --
>> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] f2fs: add a modify discard command function
2017-02-28 1:51 ` heyunlei
@ 2017-03-01 19:48 ` Jaegeuk Kim
2017-03-02 2:07 ` heyunlei
0 siblings, 1 reply; 5+ messages in thread
From: Jaegeuk Kim @ 2017-03-01 19:48 UTC (permalink / raw)
To: heyunlei; +Cc: linux-f2fs-devel
On 02/28, heyunlei wrote:
> Hi Jaegeuk,
>
> On 2017/2/28 7:08, Jaegeuk Kim wrote:
> > On 02/27, Yunlei He wrote:
> > > This patch add a function to modify discard command if one segment
> > > reuse before discard. Split this segment from multi-segments discard
> > > range, and discard the left bigger range.
> >
> > Now MAX_DISCARD_BLOCKS() is set to section size, so there will be no
> > multi-sections discard range. Am I missing some cases?
>
> I think MAX_DISCARD_BLOCKS() just limit small discard and fstrim, f2fs
>
> can still send multi-segments discard range if prefree segments is continuous.
Got it.
Comments below.
> > > Signed-off-by: Yunlei He <heyunlei@huawei.com>
> > > ---
> > > fs/f2fs/segment.c | 18 +++++++++++++++++-
> > > 1 file changed, 17 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> > > index 9006d8e..5af736b 100644
> > > --- a/fs/f2fs/segment.c
> > > +++ b/fs/f2fs/segment.c
> > > @@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
> > > kmem_cache_free(discard_cmd_slab, dc);
> > > }
> > >
> > > +static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)
How about modifying the name "modify" to "punch"?
> > > +{
> > > + block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
> > > +
> > > + if (dc->lstart + dc->len <= end_block) {
> > > + __remove_discard_cmd(sbi, dc);
> > > + return;
> > > + }
> > > +
> > > + if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {
The blkaddr is larger than or equal to dc->lstart all the time, resulting in
overflow?
Thanks,
> > > + dc->lstart = end_block;
> > > + dc->len -= (end_block - dc->lstart);
> > > + } else
> > > + dc->len = blkaddr - dc->lstart;
> > > +}
> > > +
> > > /* This should be covered by global mutex, &sit_i->sentry_lock */
> > > void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
> > > {
> > > @@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
> > > if (dc->state == D_SUBMIT)
> > > wait_for_completion_io(&dc->wait);
> > > else
> > > - __remove_discard_cmd(sbi, dc);
> > > + __modify_discard_cmd(sbi, dc, blkaddr);
> > > }
> > > }
> > > blk_finish_plug(&plug);
> > > --
> > > 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] f2fs: add a modify discard command function
2017-03-01 19:48 ` Jaegeuk Kim
@ 2017-03-02 2:07 ` heyunlei
0 siblings, 0 replies; 5+ messages in thread
From: heyunlei @ 2017-03-02 2:07 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: linux-f2fs-devel
Hi Jaegeuk,
On 2017/3/2 3:48, Jaegeuk Kim wrote:
> On 02/28, heyunlei wrote:
>> Hi Jaegeuk,
>>
>> On 2017/2/28 7:08, Jaegeuk Kim wrote:
>>> On 02/27, Yunlei He wrote:
>>>> This patch add a function to modify discard command if one segment
>>>> reuse before discard. Split this segment from multi-segments discard
>>>> range, and discard the left bigger range.
>>>
>>> Now MAX_DISCARD_BLOCKS() is set to section size, so there will be no
>>> multi-sections discard range. Am I missing some cases?
>>
>> I think MAX_DISCARD_BLOCKS() just limit small discard and fstrim, f2fs
>>
>> can still send multi-segments discard range if prefree segments is continuous.
>
> Got it.
> Comments below.
>
>>>> Signed-off-by: Yunlei He <heyunlei@huawei.com>
>>>> ---
>>>> fs/f2fs/segment.c | 18 +++++++++++++++++-
>>>> 1 file changed, 17 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>>>> index 9006d8e..5af736b 100644
>>>> --- a/fs/f2fs/segment.c
>>>> +++ b/fs/f2fs/segment.c
>>>> @@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
>>>> kmem_cache_free(discard_cmd_slab, dc);
>>>> }
>>>>
>>>> +static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)
>
> How about modifying the name "modify" to "punch"?
>
>>>> +{
>>>> + block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
>>>> +
>>>> + if (dc->lstart + dc->len <= end_block) {
>>>> + __remove_discard_cmd(sbi, dc);
>>>> + return;
>>>> + }
>>>> +
>>>> + if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {
>
> The blkaddr is larger than or equal to dc->lstart all the time, resulting in
> overflow?
Yes, here should be if (blkaddr - dc->lstart < dc->lstart + dc->len - end_block)
>
> Thanks,
>
>>>> + dc->lstart = end_block;
>>>> + dc->len -= (end_block - dc->lstart);
>>>> + } else
>>>> + dc->len = blkaddr - dc->lstart;
>>>> +}
>>>> +
>>>> /* This should be covered by global mutex, &sit_i->sentry_lock */
>>>> void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
>>>> {
>>>> @@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
>>>> if (dc->state == D_SUBMIT)
>>>> wait_for_completion_io(&dc->wait);
>>>> else
>>>> - __remove_discard_cmd(sbi, dc);
>>>> + __modify_discard_cmd(sbi, dc, blkaddr);
>>>> }
>>>> }
>>>> blk_finish_plug(&plug);
>>>> --
>>>> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-03-02 2:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-27 7:19 [PATCH] f2fs: add a modify discard command function Yunlei He
2017-02-27 23:08 ` Jaegeuk Kim
2017-02-28 1:51 ` heyunlei
2017-03-01 19:48 ` Jaegeuk Kim
2017-03-02 2:07 ` heyunlei
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.