mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix to adjust appropirate defragment pg_end
@ 2024-03-22  6:03 Zhiguo Niu
  2024-03-23  3:02 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Zhiguo Niu @ 2024-03-22  6:03 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>
---
 fs/f2fs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 128e53d..0e7eac6 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2609,7 +2609,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
 	int err;
 
 	pg_start = range->start >> PAGE_SHIFT;
-	pg_end = (range->start + range->len) >> PAGE_SHIFT;
+	pg_end = min_t(pgoff_t,
+			(range->start + range->len) >> PAGE_SHIFT,
+			DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
 
 	f2fs_balance_fs(sbi, true);
 
-- 
1.9.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] f2fs: fix to adjust appropirate defragment pg_end
  2024-03-22  6:03 [PATCH] f2fs: fix to adjust appropirate defragment pg_end Zhiguo Niu
@ 2024-03-23  3:02 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2024-03-23  3:02 UTC (permalink / raw)
  To: Zhiguo Niu, jaegeuk
  Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, ke.wang, hongyu.jin

On 2024/3/22 14:03, 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>
> ---
>   fs/f2fs/file.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 128e53d..0e7eac6 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -2609,7 +2609,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
>   	int err;
>   
>   	pg_start = range->start >> PAGE_SHIFT;
> -	pg_end = (range->start + range->len) >> PAGE_SHIFT;
> +	pg_end = min_t(pgoff_t,
> +			(range->start + range->len) >> PAGE_SHIFT,
> +			DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));

I guess we may check i_size w/ inode lock, it can avoid racing w/ append write
or truncate.

Thanks,

>   
>   	f2fs_balance_fs(sbi, true);
>   

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-23  3:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22  6:03 [PATCH] f2fs: fix to adjust appropirate defragment pg_end Zhiguo Niu
2024-03-23  3:02 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®