* [PATCH V2] f2fs: fix to adjust appropirate defragment pg_end
@ 2024-03-25 5:56 Zhiguo Niu
2024-03-26 11:11 ` Chao Yu
0 siblings, 1 reply; 4+ messages in thread
From: Zhiguo Niu @ 2024-03-25 5:56 UTC (permalink / raw)
To: jaegeuk, chao
Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, zhiguo.niu, ke.wang,
hongyu.jin
A length that exceeds the real size of the inode may be
specified from user, although these out-of-range areas
are not mapped, but they still need to be check in
while loop, which is unnecessary.
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
---
v2: check i_size within inode lock according to Chao's suggestions
---
---
fs/f2fs/file.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 128e53d..cf63db7 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2608,9 +2608,6 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
bool fragmented = false;
int err;
- pg_start = range->start >> PAGE_SHIFT;
- pg_end = (range->start + range->len) >> PAGE_SHIFT;
-
f2fs_balance_fs(sbi, true);
inode_lock(inode);
@@ -2629,10 +2626,16 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
/* writeback all dirty pages in the range */
err = filemap_write_and_wait_range(inode->i_mapping, range->start,
- range->start + range->len - 1);
+ min_t(loff_t, range->start + range->len - 1,
+ i_size_read(inode) - 1));
if (err)
goto out;
+ pg_start = range->start >> PAGE_SHIFT;
+ pg_end = min_t(pgoff_t,
+ (range->start + range->len) >> PAGE_SHIFT,
+ DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
+
/*
* lookup mapping info in extent cache, skip defragmenting if physical
* block addresses are continuous.
--
1.9.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V2] f2fs: fix to adjust appropirate defragment pg_end
2024-03-25 5:56 [PATCH V2] f2fs: fix to adjust appropirate defragment pg_end Zhiguo Niu
@ 2024-03-26 11:11 ` Chao Yu
2024-03-27 1:26 ` Zhiguo Niu
0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2024-03-26 11:11 UTC (permalink / raw)
To: Zhiguo Niu, jaegeuk
Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, ke.wang, hongyu.jin
On 2024/3/25 13:56, Zhiguo Niu wrote:
> A length that exceeds the real size of the inode may be
> specified from user, although these out-of-range areas
> are not mapped, but they still need to be check in
> while loop, which is unnecessary.
>
> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
> ---
> v2: check i_size within inode lock according to Chao's suggestions
> ---
> ---
> fs/f2fs/file.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 128e53d..cf63db7 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -2608,9 +2608,6 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
> bool fragmented = false;
> int err;
>
> - pg_start = range->start >> PAGE_SHIFT;
> - pg_end = (range->start + range->len) >> PAGE_SHIFT;
> -
> f2fs_balance_fs(sbi, true);
>
> inode_lock(inode);
> @@ -2629,10 +2626,16 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
pg_start = range->start >> PAGE_SHIFT;
pg_end = min_t(pgoff_t, (range->start + range->len) >> PAGE_SHIFT,
DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
>
> /* writeback all dirty pages in the range */
> err = filemap_write_and_wait_range(inode->i_mapping, range->start,
> - range->start + range->len - 1);
> + min_t(loff_t, range->start + range->len - 1,
> + i_size_read(inode) - 1));
, pg_start << PAGE_SHIFT - 1, pg_end << PAGE_SHIFT - 1); ?
Thanks,
> if (err)
> goto out;
>
> + pg_start = range->start >> PAGE_SHIFT;
> + pg_end = min_t(pgoff_t,
> + (range->start + range->len) >> PAGE_SHIFT,
> + DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
> +
> /*
> * lookup mapping info in extent cache, skip defragmenting if physical
> * block addresses are continuous.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V2] f2fs: fix to adjust appropirate defragment pg_end
2024-03-26 11:11 ` Chao Yu
@ 2024-03-27 1:26 ` Zhiguo Niu
2024-03-27 7:38 ` Chao Yu
0 siblings, 1 reply; 4+ messages in thread
From: Zhiguo Niu @ 2024-03-27 1:26 UTC (permalink / raw)
To: Chao Yu
Cc: Zhiguo Niu, jaegeuk, linux-f2fs-devel, linux-kernel, ke.wang, hongyu.jin
On Tue, Mar 26, 2024 at 7:11 PM Chao Yu <chao@kernel.org> wrote:
>
> On 2024/3/25 13:56, Zhiguo Niu wrote:
> > A length that exceeds the real size of the inode may be
> > specified from user, although these out-of-range areas
> > are not mapped, but they still need to be check in
> > while loop, which is unnecessary.
> >
> > Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
> > ---
> > v2: check i_size within inode lock according to Chao's suggestions
> > ---
> > ---
> > fs/f2fs/file.c | 11 +++++++----
> > 1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > index 128e53d..cf63db7 100644
> > --- a/fs/f2fs/file.c
> > +++ b/fs/f2fs/file.c
> > @@ -2608,9 +2608,6 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
> > bool fragmented = false;
> > int err;
> >
> > - pg_start = range->start >> PAGE_SHIFT;
> > - pg_end = (range->start + range->len) >> PAGE_SHIFT;
> > -
> > f2fs_balance_fs(sbi, true);
> >
> > inode_lock(inode);
> > @@ -2629,10 +2626,16 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
>
> pg_start = range->start >> PAGE_SHIFT;
> pg_end = min_t(pgoff_t, (range->start + range->len) >> PAGE_SHIFT,
> DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
>
> >
> > /* writeback all dirty pages in the range */
> > err = filemap_write_and_wait_range(inode->i_mapping, range->start,
> > - range->start + range->len - 1);
> > + min_t(loff_t, range->start + range->len - 1,
> > + i_size_read(inode) - 1));
>
> , pg_start << PAGE_SHIFT - 1, pg_end << PAGE_SHIFT - 1); ?
should be pg_start << PAGE_SHIFT , pg_end << PAGE_SHIFT - 1)??
if range.start=0, pg_start is also 0, lstart in
filemap_write_and_wait_range is 0,
but pg_start << PAGE_SHIFT - 1 will get lstart=-1?
thanks!
>
> Thanks,
>
> > if (err)
> > goto out;
> >
> > + pg_start = range->start >> PAGE_SHIFT;
> > + pg_end = min_t(pgoff_t,
> > + (range->start + range->len) >> PAGE_SHIFT,
> > + DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
> > +
> > /*
> > * lookup mapping info in extent cache, skip defragmenting if physical
> > * block addresses are continuous.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V2] f2fs: fix to adjust appropirate defragment pg_end
2024-03-27 1:26 ` Zhiguo Niu
@ 2024-03-27 7:38 ` Chao Yu
0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2024-03-27 7:38 UTC (permalink / raw)
To: Zhiguo Niu
Cc: Zhiguo Niu, jaegeuk, linux-f2fs-devel, linux-kernel, ke.wang, hongyu.jin
On 2024/3/27 9:26, Zhiguo Niu wrote:
> On Tue, Mar 26, 2024 at 7:11 PM Chao Yu <chao@kernel.org> wrote:
>>
>> On 2024/3/25 13:56, Zhiguo Niu wrote:
>>> A length that exceeds the real size of the inode may be
>>> specified from user, although these out-of-range areas
>>> are not mapped, but they still need to be check in
>>> while loop, which is unnecessary.
>>>
>>> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
>>> ---
>>> v2: check i_size within inode lock according to Chao's suggestions
>>> ---
>>> ---
>>> fs/f2fs/file.c | 11 +++++++----
>>> 1 file changed, 7 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>>> index 128e53d..cf63db7 100644
>>> --- a/fs/f2fs/file.c
>>> +++ b/fs/f2fs/file.c
>>> @@ -2608,9 +2608,6 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
>>> bool fragmented = false;
>>> int err;
>>>
>>> - pg_start = range->start >> PAGE_SHIFT;
>>> - pg_end = (range->start + range->len) >> PAGE_SHIFT;
>>> -
>>> f2fs_balance_fs(sbi, true);
>>>
>>> inode_lock(inode);
>>> @@ -2629,10 +2626,16 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
>>
>> pg_start = range->start >> PAGE_SHIFT;
>> pg_end = min_t(pgoff_t, (range->start + range->len) >> PAGE_SHIFT,
>> DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
>>
>>>
>>> /* writeback all dirty pages in the range */
>>> err = filemap_write_and_wait_range(inode->i_mapping, range->start,
>>> - range->start + range->len - 1);
>>> + min_t(loff_t, range->start + range->len - 1,
>>> + i_size_read(inode) - 1));
>>
>> , pg_start << PAGE_SHIFT - 1, pg_end << PAGE_SHIFT - 1); ?
> should be pg_start << PAGE_SHIFT , pg_end << PAGE_SHIFT - 1)??
Oh, yes. :)
Thanks,
> if range.start=0, pg_start is also 0, lstart in
> filemap_write_and_wait_range is 0,
> but pg_start << PAGE_SHIFT - 1 will get lstart=-1?
> thanks!
>>
>> Thanks,
>>
>>> if (err)
>>> goto out;
>>>
>>> + pg_start = range->start >> PAGE_SHIFT;
>>> + pg_end = min_t(pgoff_t,
>>> + (range->start + range->len) >> PAGE_SHIFT,
>>> + DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
>>> +
>>> /*
>>> * lookup mapping info in extent cache, skip defragmenting if physical
>>> * block addresses are continuous.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-27 7:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-25 5:56 [PATCH V2] f2fs: fix to adjust appropirate defragment pg_end Zhiguo Niu
2024-03-26 11:11 ` Chao Yu
2024-03-27 1:26 ` Zhiguo Niu
2024-03-27 7:38 ` Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome