All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix to round down start offset of fallocate for pin file
       [not found] <CGME20260622023853epcas1p3d15698d1e456cc549da18ac2674e1f5f@epcas1p3.samsung.com>
@ 2026-06-22  2:38   ` Sunmin Jeong
  0 siblings, 0 replies; 6+ messages in thread
From: Sunmin Jeong @ 2026-06-22  2:38 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: linux-f2fs-devel, linux-kernel, Sunmin Jeong, Yunji Kang,
	Yeongjin Gil, Sungjong Seo

Currently, the length of fallocate for pin file is section-aligned to
keep allocated sections from being selected as victims of GC. However,
for the case that the start offset of fallocate is not aligned in
section, the allocated sections can't be fully utilized. It's because a
new section is allocated by f2fs_allocate_pinning_section() after using
blks_per_sec blocks regardless of the start offset. As a result, several
unexpected dirty segments may be created, including blocks assigned to
the pinned file.

To address this issue, let's round down the start offset of fallocate
to the length of section.

The reproducing scenario is as below

chunk=$(((2<<20)+4096)) # 2MB + 4KB
touch test
f2fs_io pinfile set test
f2fs_io fallocate 0 0 $chunk test
f2fs_io fallocate 0 $chunk $chunk test
f2fs_io fallocate 0 $((chunk*2)) $chunk test
f2fs_io fiemap 0 $((chunk*3)) test

Fiemap: offset = 0 len = 12288
    logical addr.    physical addr.   length           flags
0   0000000000000000 000000068c600000 0000000000400000 00001088
1   0000000000400000 000000003d400000 0000000000001000 00001088
2   0000000000401000 00000003eb200000 0000000000200000 00001088
3   0000000000601000 00000005e4200000 0000000000001000 00001088
4   0000000000602000 0000000605400000 0000000000200000 00001089

Reviewed-by: Yunji Kang <yunji0.kang@samsung.com>
Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
---
 fs/f2fs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 2c4880f24b54..3954aea43bd9 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1906,8 +1906,13 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
 
 	if (f2fs_is_pinned_file(inode)) {
 		block_t sec_blks = CAP_BLKS_PER_SEC(sbi);
-		block_t sec_len = roundup(map.m_len, sec_blks);
+		block_t sec_len;
 
+		if (map.m_lblk % sec_blks) {
+			map.m_lblk = rounddown(map.m_lblk, sec_blks);
+			map.m_len = pg_end - map.m_lblk;
+		}
+		sec_len = roundup(map.m_len, sec_blks);
 		map.m_len = sec_blks;
 next_alloc:
 		f2fs_down_write(&sbi->pin_sem);
-- 
2.25.1


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

* [f2fs-dev] [PATCH] f2fs: fix to round down start offset of fallocate for pin file
@ 2026-06-22  2:38   ` Sunmin Jeong
  0 siblings, 0 replies; 6+ messages in thread
From: Sunmin Jeong @ 2026-06-22  2:38 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, Sungjong Seo

Currently, the length of fallocate for pin file is section-aligned to
keep allocated sections from being selected as victims of GC. However,
for the case that the start offset of fallocate is not aligned in
section, the allocated sections can't be fully utilized. It's because a
new section is allocated by f2fs_allocate_pinning_section() after using
blks_per_sec blocks regardless of the start offset. As a result, several
unexpected dirty segments may be created, including blocks assigned to
the pinned file.

To address this issue, let's round down the start offset of fallocate
to the length of section.

The reproducing scenario is as below

chunk=$(((2<<20)+4096)) # 2MB + 4KB
touch test
f2fs_io pinfile set test
f2fs_io fallocate 0 0 $chunk test
f2fs_io fallocate 0 $chunk $chunk test
f2fs_io fallocate 0 $((chunk*2)) $chunk test
f2fs_io fiemap 0 $((chunk*3)) test

Fiemap: offset = 0 len = 12288
    logical addr.    physical addr.   length           flags
0   0000000000000000 000000068c600000 0000000000400000 00001088
1   0000000000400000 000000003d400000 0000000000001000 00001088
2   0000000000401000 00000003eb200000 0000000000200000 00001088
3   0000000000601000 00000005e4200000 0000000000001000 00001088
4   0000000000602000 0000000605400000 0000000000200000 00001089

Reviewed-by: Yunji Kang <yunji0.kang@samsung.com>
Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
---
 fs/f2fs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 2c4880f24b54..3954aea43bd9 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1906,8 +1906,13 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
 
 	if (f2fs_is_pinned_file(inode)) {
 		block_t sec_blks = CAP_BLKS_PER_SEC(sbi);
-		block_t sec_len = roundup(map.m_len, sec_blks);
+		block_t sec_len;
 
+		if (map.m_lblk % sec_blks) {
+			map.m_lblk = rounddown(map.m_lblk, sec_blks);
+			map.m_len = pg_end - map.m_lblk;
+		}
+		sec_len = roundup(map.m_len, sec_blks);
 		map.m_len = sec_blks;
 next_alloc:
 		f2fs_down_write(&sbi->pin_sem);
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: fix to round down start offset of fallocate for pin file
  2026-06-22  2:38   ` [f2fs-dev] " Sunmin Jeong
@ 2026-06-22  3:14     ` Chao Yu
  -1 siblings, 0 replies; 6+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2026-06-22  3:14 UTC (permalink / raw)
  To: Sunmin Jeong, jaegeuk; +Cc: linux-kernel, linux-f2fs-devel, Sungjong Seo

On 6/22/26 10:38, Sunmin Jeong wrote:
> Currently, the length of fallocate for pin file is section-aligned to
> keep allocated sections from being selected as victims of GC. However,
> for the case that the start offset of fallocate is not aligned in
> section, the allocated sections can't be fully utilized. It's because a
> new section is allocated by f2fs_allocate_pinning_section() after using
> blks_per_sec blocks regardless of the start offset. As a result, several
> unexpected dirty segments may be created, including blocks assigned to
> the pinned file.
> 
> To address this issue, let's round down the start offset of fallocate
> to the length of section.

It's good catch!

> 
> The reproducing scenario is as below
> 
> chunk=$(((2<<20)+4096)) # 2MB + 4KB
> touch test
> f2fs_io pinfile set test
> f2fs_io fallocate 0 0 $chunk test
> f2fs_io fallocate 0 $chunk $chunk test
> f2fs_io fallocate 0 $((chunk*2)) $chunk test
> f2fs_io fiemap 0 $((chunk*3)) test
> 
> Fiemap: offset = 0 len = 12288
>      logical addr.    physical addr.   length           flags
> 0   0000000000000000 000000068c600000 0000000000400000 00001088
> 1   0000000000400000 000000003d400000 0000000000001000 00001088
> 2   0000000000401000 00000003eb200000 0000000000200000 00001088
> 3   0000000000601000 00000005e4200000 0000000000001000 00001088
> 4   0000000000602000 0000000605400000 0000000000200000 00001089
> 

Fixes and Cc stable line.

> Reviewed-by: Yunji Kang <yunji0.kang@samsung.com>
> Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
> ---
>   fs/f2fs/file.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 2c4880f24b54..3954aea43bd9 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1906,8 +1906,13 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
>   
>   	if (f2fs_is_pinned_file(inode)) {
>   		block_t sec_blks = CAP_BLKS_PER_SEC(sbi);
> -		block_t sec_len = roundup(map.m_len, sec_blks);
> +		block_t sec_len;
>   
> +		if (map.m_lblk % sec_blks) {
> +			map.m_lblk = rounddown(map.m_lblk, sec_blks);
> +			map.m_len = pg_end - map.m_lblk;

If pg_end is aligned to sec_blks, but off_end is non-zero, is there off-by-one issue?

Thanks,

> +		}
> +		sec_len = roundup(map.m_len, sec_blks);
>   		map.m_len = sec_blks;
>   next_alloc:
>   		f2fs_down_write(&sbi->pin_sem);



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [PATCH] f2fs: fix to round down start offset of fallocate for pin file
@ 2026-06-22  3:14     ` Chao Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2026-06-22  3:14 UTC (permalink / raw)
  To: Sunmin Jeong, jaegeuk
  Cc: chao, linux-f2fs-devel, linux-kernel, Yunji Kang, Yeongjin Gil,
	Sungjong Seo

On 6/22/26 10:38, Sunmin Jeong wrote:
> Currently, the length of fallocate for pin file is section-aligned to
> keep allocated sections from being selected as victims of GC. However,
> for the case that the start offset of fallocate is not aligned in
> section, the allocated sections can't be fully utilized. It's because a
> new section is allocated by f2fs_allocate_pinning_section() after using
> blks_per_sec blocks regardless of the start offset. As a result, several
> unexpected dirty segments may be created, including blocks assigned to
> the pinned file.
> 
> To address this issue, let's round down the start offset of fallocate
> to the length of section.

It's good catch!

> 
> The reproducing scenario is as below
> 
> chunk=$(((2<<20)+4096)) # 2MB + 4KB
> touch test
> f2fs_io pinfile set test
> f2fs_io fallocate 0 0 $chunk test
> f2fs_io fallocate 0 $chunk $chunk test
> f2fs_io fallocate 0 $((chunk*2)) $chunk test
> f2fs_io fiemap 0 $((chunk*3)) test
> 
> Fiemap: offset = 0 len = 12288
>      logical addr.    physical addr.   length           flags
> 0   0000000000000000 000000068c600000 0000000000400000 00001088
> 1   0000000000400000 000000003d400000 0000000000001000 00001088
> 2   0000000000401000 00000003eb200000 0000000000200000 00001088
> 3   0000000000601000 00000005e4200000 0000000000001000 00001088
> 4   0000000000602000 0000000605400000 0000000000200000 00001089
> 

Fixes and Cc stable line.

> Reviewed-by: Yunji Kang <yunji0.kang@samsung.com>
> Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
> ---
>   fs/f2fs/file.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 2c4880f24b54..3954aea43bd9 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1906,8 +1906,13 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
>   
>   	if (f2fs_is_pinned_file(inode)) {
>   		block_t sec_blks = CAP_BLKS_PER_SEC(sbi);
> -		block_t sec_len = roundup(map.m_len, sec_blks);
> +		block_t sec_len;
>   
> +		if (map.m_lblk % sec_blks) {
> +			map.m_lblk = rounddown(map.m_lblk, sec_blks);
> +			map.m_len = pg_end - map.m_lblk;

If pg_end is aligned to sec_blks, but off_end is non-zero, is there off-by-one issue?

Thanks,

> +		}
> +		sec_len = roundup(map.m_len, sec_blks);
>   		map.m_len = sec_blks;
>   next_alloc:
>   		f2fs_down_write(&sbi->pin_sem);


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

* RE: [PATCH] f2fs: fix to round down start offset of fallocate for pin file
  2026-06-22  3:14     ` Chao Yu
@ 2026-06-22  3:34       ` Sunmin Jeong
  -1 siblings, 0 replies; 6+ messages in thread
From: Sunmin Jeong @ 2026-06-22  3:34 UTC (permalink / raw)
  To: 'Chao Yu', jaegeuk
  Cc: linux-f2fs-devel, linux-kernel, 'Yunji Kang',
	'Yeongjin	Gil', 'Sungjong Seo'

>On 6/22/26 10:38, Sunmin Jeong wrote:
>> Currently, the length of fallocate for pin file is section-aligned to
>> keep allocated sections from being selected as victims of GC. However,
>> for the case that the start offset of fallocate is not aligned in
>> section, the allocated sections can't be fully utilized. It's because
>> a new section is allocated by f2fs_allocate_pinning_section() after
>> using blks_per_sec blocks regardless of the start offset. As a result,
>> several unexpected dirty segments may be created, including blocks
>> assigned to the pinned file.
>>
>> To address this issue, let's round down the start offset of fallocate
>> to the length of section.
>
>It's good catch!
>
>>
>> The reproducing scenario is as below
>>
>> chunk=$(((2<<20)+4096)) # 2MB + 4KB
>> touch test
>> f2fs_io pinfile set test
>> f2fs_io fallocate 0 0 $chunk test
>> f2fs_io fallocate 0 $chunk $chunk test f2fs_io fallocate 0
>> $((chunk*2)) $chunk test f2fs_io fiemap 0 $((chunk*3)) test
>>
>> Fiemap: offset = 0 len = 12288
>>      logical addr.    physical addr.   length           flags
>> 0   0000000000000000 000000068c600000 0000000000400000 00001088
>> 1   0000000000400000 000000003d400000 0000000000001000 00001088
>> 2   0000000000401000 00000003eb200000 0000000000200000 00001088
>> 3   0000000000601000 00000005e4200000 0000000000001000 00001088
>> 4   0000000000602000 0000000605400000 0000000000200000 00001089
>>
>
>Fixes and Cc stable line.
>
>> Reviewed-by: Yunji Kang <yunji0.kang@samsung.com>
>> Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
>> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
>> Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
>> ---
>>   fs/f2fs/file.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index
>> 2c4880f24b54..3954aea43bd9 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -1906,8 +1906,13 @@ static int f2fs_expand_inode_data(struct inode
>> *inode, loff_t offset,
>>
>>   	if (f2fs_is_pinned_file(inode)) {
>>   		block_t sec_blks = CAP_BLKS_PER_SEC(sbi);
>> -		block_t sec_len = roundup(map.m_len, sec_blks);
>> +		block_t sec_len;
>>
>> +		if (map.m_lblk % sec_blks) {
>> +			map.m_lblk = rounddown(map.m_lblk, sec_blks);
>> +			map.m_len = pg_end - map.m_lblk;
>
>If pg_end is aligned to sec_blks, but off_end is non-zero, is there off-by-
>one issue?
>
>Thanks,

Thanks for your quick reply.
I'll send a v2 patch.

>
>> +		}
>> +		sec_len = roundup(map.m_len, sec_blks);
>>   		map.m_len = sec_blks;
>>   next_alloc:
>>   		f2fs_down_write(&sbi->pin_sem);



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

* Re: [f2fs-dev] [PATCH] f2fs: fix to round down start offset of fallocate for pin file
@ 2026-06-22  3:34       ` Sunmin Jeong
  0 siblings, 0 replies; 6+ messages in thread
From: Sunmin Jeong @ 2026-06-22  3:34 UTC (permalink / raw)
  To: 'Chao Yu', jaegeuk
  Cc: 'Sungjong Seo', linux-kernel, linux-f2fs-devel

>On 6/22/26 10:38, Sunmin Jeong wrote:
>> Currently, the length of fallocate for pin file is section-aligned to
>> keep allocated sections from being selected as victims of GC. However,
>> for the case that the start offset of fallocate is not aligned in
>> section, the allocated sections can't be fully utilized. It's because
>> a new section is allocated by f2fs_allocate_pinning_section() after
>> using blks_per_sec blocks regardless of the start offset. As a result,
>> several unexpected dirty segments may be created, including blocks
>> assigned to the pinned file.
>>
>> To address this issue, let's round down the start offset of fallocate
>> to the length of section.
>
>It's good catch!
>
>>
>> The reproducing scenario is as below
>>
>> chunk=$(((2<<20)+4096)) # 2MB + 4KB
>> touch test
>> f2fs_io pinfile set test
>> f2fs_io fallocate 0 0 $chunk test
>> f2fs_io fallocate 0 $chunk $chunk test f2fs_io fallocate 0
>> $((chunk*2)) $chunk test f2fs_io fiemap 0 $((chunk*3)) test
>>
>> Fiemap: offset = 0 len = 12288
>>      logical addr.    physical addr.   length           flags
>> 0   0000000000000000 000000068c600000 0000000000400000 00001088
>> 1   0000000000400000 000000003d400000 0000000000001000 00001088
>> 2   0000000000401000 00000003eb200000 0000000000200000 00001088
>> 3   0000000000601000 00000005e4200000 0000000000001000 00001088
>> 4   0000000000602000 0000000605400000 0000000000200000 00001089
>>
>
>Fixes and Cc stable line.
>
>> Reviewed-by: Yunji Kang <yunji0.kang@samsung.com>
>> Reviewed-by: Yeongjin Gil <youngjin.gil@samsung.com>
>> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
>> Signed-off-by: Sunmin Jeong <s_min.jeong@samsung.com>
>> ---
>>   fs/f2fs/file.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index
>> 2c4880f24b54..3954aea43bd9 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -1906,8 +1906,13 @@ static int f2fs_expand_inode_data(struct inode
>> *inode, loff_t offset,
>>
>>   	if (f2fs_is_pinned_file(inode)) {
>>   		block_t sec_blks = CAP_BLKS_PER_SEC(sbi);
>> -		block_t sec_len = roundup(map.m_len, sec_blks);
>> +		block_t sec_len;
>>
>> +		if (map.m_lblk % sec_blks) {
>> +			map.m_lblk = rounddown(map.m_lblk, sec_blks);
>> +			map.m_len = pg_end - map.m_lblk;
>
>If pg_end is aligned to sec_blks, but off_end is non-zero, is there off-by-
>one issue?
>
>Thanks,

Thanks for your quick reply.
I'll send a v2 patch.

>
>> +		}
>> +		sec_len = roundup(map.m_len, sec_blks);
>>   		map.m_len = sec_blks;
>>   next_alloc:
>>   		f2fs_down_write(&sbi->pin_sem);




_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

end of thread, other threads:[~2026-06-22  3:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20260622023853epcas1p3d15698d1e456cc549da18ac2674e1f5f@epcas1p3.samsung.com>
2026-06-22  2:38 ` [PATCH] f2fs: fix to round down start offset of fallocate for pin file Sunmin Jeong
2026-06-22  2:38   ` [f2fs-dev] " Sunmin Jeong
2026-06-22  3:14   ` Chao Yu via Linux-f2fs-devel
2026-06-22  3:14     ` Chao Yu
2026-06-22  3:34     ` Sunmin Jeong
2026-06-22  3:34       ` [f2fs-dev] " Sunmin Jeong

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.