* [f2fs-dev] [PATCH] f2fs: readahead node block in F2FS_GET_BLOCK_PRECACHE mode
[not found] <CGME20250917055237epcas1p2faa1b3d6555ffc5179c700e7a2afd448@epcas1p2.samsung.com>
@ 2025-09-17 5:52 ` Yunji Kang
2025-09-18 2:09 ` Chao Yu via Linux-f2fs-devel
0 siblings, 1 reply; 4+ messages in thread
From: Yunji Kang @ 2025-09-17 5:52 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: Sungjong Seo, linux-kernel, linux-f2fs-devel
In f2fs_precache_extents(), For large files, It requires reading many
node blocks. Instead of reading each node block with synchronous I/O,
this patch applies readahead so that node blocks can be fetched in
advance.
It reduces the overhead of repeated sync reads and improves efficiency
when precaching extents of large files.
I created a file with the same largest extent and executed the test.
For this experiment, I set the file's largest extent with an offset of 0
and a size of 1GB. I configured the remaining area with 100MB extents.
5GB test file:
dd if=/dev/urandom of=test1 bs=1m count=5120
cp test1 test2
fsync test1
dd if=test1 of=test2 bs=1m skip=1024 seek=1024 count=100 conv=notrunc
dd if=test1 of=test2 bs=1m skip=1224 seek=1224 count=100 conv=notrunc
...
dd if=test1 of=test2 bs=1m skip=5024 seek=5024 count=100 conv=notrunc
reboot
I also created 10GB and 20GB files with large extents using the same
method.
ioctl(F2FS_IOC_PRECACHE_EXTENTS) test results are as follows:
+-----------+---------+---------+-----------+
| File size | Before | After | Reduction |
+-----------+---------+---------+-----------+
| 5GB | 101.8ms | 72.1ms | 29.2% |
| 10GB | 222.9ms | 149.5ms | 32.9% |
| 20GB | 446.2ms | 276.3ms | 38.1% |
+-----------+---------+---------+-----------+
Tested on a 256GB mobile device with an SM8750 chipset.
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Reviewed-by: Sunmin Jeong <s_min.jeong@samsung.com>
Signed-off-by: Yunji Kang <yunji0.kang@samsung.com>
---
fs/f2fs/data.c | 3 +++
fs/f2fs/f2fs.h | 1 +
fs/f2fs/node.c | 4 +++-
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 7961e0ddfca3..ab3117e3b24a 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1572,6 +1572,9 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
pgofs = (pgoff_t)map->m_lblk;
end = pgofs + maxblocks;
+ if (flag == F2FS_GET_BLOCK_PRECACHE)
+ mode = LOOKUP_NODE_PRECACHE;
+
next_dnode:
if (map->m_may_create) {
if (f2fs_lfs_mode(sbi))
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9d3bc9633c1d..3ce41528d48e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -651,6 +651,7 @@ enum {
* look up a node with readahead called
* by get_data_block.
*/
+ LOOKUP_NODE_PRECACHE, /* look up a node for F2FS_GET_BLOCK_PRECACHE */
};
#define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO or flush count */
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 4254db453b2d..50be167e5c59 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -860,7 +860,9 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode)
set_nid(parent, offset[i - 1], nids[i], i == 1);
f2fs_alloc_nid_done(sbi, nids[i]);
done = true;
- } else if (mode == LOOKUP_NODE_RA && i == level && level > 1) {
+ } else if ((mode == LOOKUP_NODE_RA ||
+ (mode == LOOKUP_NODE_PRECACHE && offset[i - 1] % MAX_RA_NODE == 0))
+ && i == level && level > 1) {
nfolio[i] = f2fs_get_node_folio_ra(parent, offset[i - 1]);
if (IS_ERR(nfolio[i])) {
err = PTR_ERR(nfolio[i]);
--
2.34.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] 4+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: readahead node block in F2FS_GET_BLOCK_PRECACHE mode
2025-09-17 5:52 ` [f2fs-dev] [PATCH] f2fs: readahead node block in F2FS_GET_BLOCK_PRECACHE mode Yunji Kang
@ 2025-09-18 2:09 ` Chao Yu via Linux-f2fs-devel
2025-09-18 4:55 ` Yunji Kang
0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-09-18 2:09 UTC (permalink / raw)
To: Yunji Kang, jaegeuk; +Cc: linux-kernel, Sungjong Seo, linux-f2fs-devel
On 9/17/25 13:52, Yunji Kang wrote:
> In f2fs_precache_extents(), For large files, It requires reading many
> node blocks. Instead of reading each node block with synchronous I/O,
> this patch applies readahead so that node blocks can be fetched in
> advance.
>
> It reduces the overhead of repeated sync reads and improves efficiency
> when precaching extents of large files.
>
> I created a file with the same largest extent and executed the test.
> For this experiment, I set the file's largest extent with an offset of 0
> and a size of 1GB. I configured the remaining area with 100MB extents.
>
> 5GB test file:
> dd if=/dev/urandom of=test1 bs=1m count=5120
> cp test1 test2
> fsync test1
> dd if=test1 of=test2 bs=1m skip=1024 seek=1024 count=100 conv=notrunc
> dd if=test1 of=test2 bs=1m skip=1224 seek=1224 count=100 conv=notrunc
> ...
> dd if=test1 of=test2 bs=1m skip=5024 seek=5024 count=100 conv=notrunc
> reboot
>
> I also created 10GB and 20GB files with large extents using the same
> method.
>
> ioctl(F2FS_IOC_PRECACHE_EXTENTS) test results are as follows:
> +-----------+---------+---------+-----------+
> | File size | Before | After | Reduction |
> +-----------+---------+---------+-----------+
> | 5GB | 101.8ms | 72.1ms | 29.2% |
> | 10GB | 222.9ms | 149.5ms | 32.9% |
> | 20GB | 446.2ms | 276.3ms | 38.1% |
> +-----------+---------+---------+-----------+
> Tested on a 256GB mobile device with an SM8750 chipset.
>
> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> Reviewed-by: Sunmin Jeong <s_min.jeong@samsung.com>
> Signed-off-by: Yunji Kang <yunji0.kang@samsung.com>
> ---
> fs/f2fs/data.c | 3 +++
> fs/f2fs/f2fs.h | 1 +
> fs/f2fs/node.c | 4 +++-
> 3 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 7961e0ddfca3..ab3117e3b24a 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -1572,6 +1572,9 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
> pgofs = (pgoff_t)map->m_lblk;
> end = pgofs + maxblocks;
>
> + if (flag == F2FS_GET_BLOCK_PRECACHE)
> + mode = LOOKUP_NODE_PRECACHE;
> +
> next_dnode:
> if (map->m_may_create) {
> if (f2fs_lfs_mode(sbi))
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 9d3bc9633c1d..3ce41528d48e 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -651,6 +651,7 @@ enum {
> * look up a node with readahead called
> * by get_data_block.
> */
> + LOOKUP_NODE_PRECACHE, /* look up a node for F2FS_GET_BLOCK_PRECACHE */
> };
>
> #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO or flush count */
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index 4254db453b2d..50be167e5c59 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -860,7 +860,9 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode)
> set_nid(parent, offset[i - 1], nids[i], i == 1);
> f2fs_alloc_nid_done(sbi, nids[i]);
> done = true;
> - } else if (mode == LOOKUP_NODE_RA && i == level && level > 1) {
> + } else if ((mode == LOOKUP_NODE_RA ||
Does this change the logic for mode = LOOKUP_NODE_RA?
Not sure, do you mean this?
if ((i == level && level > 1) &&
(mode == LOOKUP_NODE_RA ||
(mode == LOOKUP_NODE_PRECACHE &&
offset[i - 1] % MAX_RA_NODE == 0)))
Thanks,
> + (mode == LOOKUP_NODE_PRECACHE && offset[i - 1] % MAX_RA_NODE == 0))
> + && i == level && level > 1) {
> nfolio[i] = f2fs_get_node_folio_ra(parent, offset[i - 1]);
> if (IS_ERR(nfolio[i])) {
> err = PTR_ERR(nfolio[i]);
_______________________________________________
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] 4+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: readahead node block in F2FS_GET_BLOCK_PRECACHE mode
2025-09-18 2:09 ` Chao Yu via Linux-f2fs-devel
@ 2025-09-18 4:55 ` Yunji Kang
2025-09-18 7:02 ` Chao Yu via Linux-f2fs-devel
0 siblings, 1 reply; 4+ messages in thread
From: Yunji Kang @ 2025-09-18 4:55 UTC (permalink / raw)
To: 'Chao Yu', jaegeuk
Cc: 'Sungjong Seo', linux-kernel, linux-f2fs-devel
> > In f2fs_precache_extents(), For large files, It requires reading many
> > node blocks. Instead of reading each node block with synchronous I/O,
> > this patch applies readahead so that node blocks can be fetched in
> > advance.
> >
> > It reduces the overhead of repeated sync reads and improves efficiency
> > when precaching extents of large files.
> >
> > I created a file with the same largest extent and executed the test.
> > For this experiment, I set the file's largest extent with an offset of
> > 0 and a size of 1GB. I configured the remaining area with 100MB extents.
> >
> > 5GB test file:
> > dd if=/dev/urandom of=test1 bs=1m count=5120 cp test1 test2 fsync
> > test1 dd if=test1 of=test2 bs=1m skip=1024 seek=1024 count=100
> > conv=notrunc dd if=test1 of=test2 bs=1m skip=1224 seek=1224 count=100
> > conv=notrunc ...
> > dd if=test1 of=test2 bs=1m skip=5024 seek=5024 count=100 conv=notrunc
> > reboot
> >
> > I also created 10GB and 20GB files with large extents using the same
> > method.
> >
> > ioctl(F2FS_IOC_PRECACHE_EXTENTS) test results are as follows:
> > +-----------+---------+---------+-----------+
> > | File size | Before | After | Reduction |
> > +-----------+---------+---------+-----------+
> > | 5GB | 101.8ms | 72.1ms | 29.2% |
> > | 10GB | 222.9ms | 149.5ms | 32.9% |
> > | 20GB | 446.2ms | 276.3ms | 38.1% |
> > +-----------+---------+---------+-----------+
> > Tested on a 256GB mobile device with an SM8750 chipset.
> >
> > Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> > Reviewed-by: Sunmin Jeong <s_min.jeong@samsung.com>
> > Signed-off-by: Yunji Kang <yunji0.kang@samsung.com>
> > ---
> > fs/f2fs/data.c | 3 +++
> > fs/f2fs/f2fs.h | 1 +
> > fs/f2fs/node.c | 4 +++-
> > 3 files changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index
> > 7961e0ddfca3..ab3117e3b24a 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -1572,6 +1572,9 @@ int f2fs_map_blocks(struct inode *inode, struct
> f2fs_map_blocks *map, int flag)
> > pgofs = (pgoff_t)map->m_lblk;
> > end = pgofs + maxblocks;
> >
> > + if (flag == F2FS_GET_BLOCK_PRECACHE)
> > + mode = LOOKUP_NODE_PRECACHE;
> > +
> > next_dnode:
> > if (map->m_may_create) {
> > if (f2fs_lfs_mode(sbi))
> > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index
> > 9d3bc9633c1d..3ce41528d48e 100644
> > --- a/fs/f2fs/f2fs.h
> > +++ b/fs/f2fs/f2fs.h
> > @@ -651,6 +651,7 @@ enum {
> > * look up a node with readahead called
> > * by get_data_block.
> > */
> > + LOOKUP_NODE_PRECACHE, /* look up a node for
> F2FS_GET_BLOCK_PRECACHE */
> > };
> >
> > #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO or flush
> count */
> > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index
> > 4254db453b2d..50be167e5c59 100644
> > --- a/fs/f2fs/node.c
> > +++ b/fs/f2fs/node.c
> > @@ -860,7 +860,9 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn,
> pgoff_t index, int mode)
> > set_nid(parent, offset[i - 1], nids[i], i == 1);
> > f2fs_alloc_nid_done(sbi, nids[i]);
> > done = true;
> > - } else if (mode == LOOKUP_NODE_RA && i == level && level > 1)
> {
> > + } else if ((mode == LOOKUP_NODE_RA ||
>
> Does this change the logic for mode = LOOKUP_NODE_RA?
>
> Not sure, do you mean this?
>
> if ((i == level && level > 1) &&
> (mode == LOOKUP_NODE_RA ||
> (mode == LOOKUP_NODE_PRECACHE &&
> offset[i - 1] % MAX_RA_NODE == 0)))
>
> Thanks,
>
> > + (mode == LOOKUP_NODE_PRECACHE && offset[i - 1] %
> MAX_RA_NODE == 0))
> > + && i == level && level > 1) {
> > nfolio[i] = f2fs_get_node_folio_ra(parent, offset[i -
> 1]);
> > if (IS_ERR(nfolio[i])) {
> > err = PTR_ERR(nfolio[i]);
I think the code has the same meaning.
The version you wrote looks more readable, so would it be okay if I change the patch with your code?
Also, I did not change the logic for mode = LOOKUP_NODE_RA; I only added a condition for when readahead is performed.
Thanks.
_______________________________________________
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] 4+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: readahead node block in F2FS_GET_BLOCK_PRECACHE mode
2025-09-18 4:55 ` Yunji Kang
@ 2025-09-18 7:02 ` Chao Yu via Linux-f2fs-devel
0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-09-18 7:02 UTC (permalink / raw)
To: Yunji Kang, jaegeuk
Cc: linux-kernel, 'Sungjong Seo', linux-f2fs-devel
On 9/18/25 12:55, Yunji Kang wrote:
>>> In f2fs_precache_extents(), For large files, It requires reading many
>>> node blocks. Instead of reading each node block with synchronous I/O,
>>> this patch applies readahead so that node blocks can be fetched in
>>> advance.
>>>
>>> It reduces the overhead of repeated sync reads and improves efficiency
>>> when precaching extents of large files.
>>>
>>> I created a file with the same largest extent and executed the test.
>>> For this experiment, I set the file's largest extent with an offset of
>>> 0 and a size of 1GB. I configured the remaining area with 100MB extents.
>>>
>>> 5GB test file:
>>> dd if=/dev/urandom of=test1 bs=1m count=5120 cp test1 test2 fsync
>>> test1 dd if=test1 of=test2 bs=1m skip=1024 seek=1024 count=100
>>> conv=notrunc dd if=test1 of=test2 bs=1m skip=1224 seek=1224 count=100
>>> conv=notrunc ...
>>> dd if=test1 of=test2 bs=1m skip=5024 seek=5024 count=100 conv=notrunc
>>> reboot
>>>
>>> I also created 10GB and 20GB files with large extents using the same
>>> method.
>>>
>>> ioctl(F2FS_IOC_PRECACHE_EXTENTS) test results are as follows:
>>> +-----------+---------+---------+-----------+
>>> | File size | Before | After | Reduction |
>>> +-----------+---------+---------+-----------+
>>> | 5GB | 101.8ms | 72.1ms | 29.2% |
>>> | 10GB | 222.9ms | 149.5ms | 32.9% |
>>> | 20GB | 446.2ms | 276.3ms | 38.1% |
>>> +-----------+---------+---------+-----------+
>>> Tested on a 256GB mobile device with an SM8750 chipset.
>>>
>>> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
>>> Reviewed-by: Sunmin Jeong <s_min.jeong@samsung.com>
>>> Signed-off-by: Yunji Kang <yunji0.kang@samsung.com>
>>> ---
>>> fs/f2fs/data.c | 3 +++
>>> fs/f2fs/f2fs.h | 1 +
>>> fs/f2fs/node.c | 4 +++-
>>> 3 files changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index
>>> 7961e0ddfca3..ab3117e3b24a 100644
>>> --- a/fs/f2fs/data.c
>>> +++ b/fs/f2fs/data.c
>>> @@ -1572,6 +1572,9 @@ int f2fs_map_blocks(struct inode *inode, struct
>> f2fs_map_blocks *map, int flag)
>>> pgofs = (pgoff_t)map->m_lblk;
>>> end = pgofs + maxblocks;
>>>
>>> + if (flag == F2FS_GET_BLOCK_PRECACHE)
>>> + mode = LOOKUP_NODE_PRECACHE;
>>> +
>>> next_dnode:
>>> if (map->m_may_create) {
>>> if (f2fs_lfs_mode(sbi))
>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index
>>> 9d3bc9633c1d..3ce41528d48e 100644
>>> --- a/fs/f2fs/f2fs.h
>>> +++ b/fs/f2fs/f2fs.h
>>> @@ -651,6 +651,7 @@ enum {
>>> * look up a node with readahead called
>>> * by get_data_block.
>>> */
>>> + LOOKUP_NODE_PRECACHE, /* look up a node for
>> F2FS_GET_BLOCK_PRECACHE */
>>> };
>>>
>>> #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO or flush
>> count */
>>> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index
>>> 4254db453b2d..50be167e5c59 100644
>>> --- a/fs/f2fs/node.c
>>> +++ b/fs/f2fs/node.c
>>> @@ -860,7 +860,9 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn,
>> pgoff_t index, int mode)
>>> set_nid(parent, offset[i - 1], nids[i], i == 1);
>>> f2fs_alloc_nid_done(sbi, nids[i]);
>>> done = true;
>>> - } else if (mode == LOOKUP_NODE_RA && i == level && level > 1)
>> {
>>> + } else if ((mode == LOOKUP_NODE_RA ||
>>
>> Does this change the logic for mode = LOOKUP_NODE_RA?
>>
>> Not sure, do you mean this?
>>
>> if ((i == level && level > 1) &&
>> (mode == LOOKUP_NODE_RA ||
>> (mode == LOOKUP_NODE_PRECACHE &&
>> offset[i - 1] % MAX_RA_NODE == 0)))
>>
>> Thanks,
>>
>>> + (mode == LOOKUP_NODE_PRECACHE && offset[i - 1] %
>> MAX_RA_NODE == 0))
>>> + && i == level && level > 1) {
>>> nfolio[i] = f2fs_get_node_folio_ra(parent, offset[i -
>> 1]);
>>> if (IS_ERR(nfolio[i])) {
>>> err = PTR_ERR(nfolio[i]);
>
> I think the code has the same meaning.
> The version you wrote looks more readable, so would it be okay if I change the patch with your code?
Sure, please go ahead.
>
> Also, I did not change the logic for mode = LOOKUP_NODE_RA; I only added a condition for when readahead is performed.
Oh, I see, I missed the parenthesis, sorry.
Thanks,
>
> Thanks.
>
_______________________________________________
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] 4+ messages in thread
end of thread, other threads:[~2025-09-18 7:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CGME20250917055237epcas1p2faa1b3d6555ffc5179c700e7a2afd448@epcas1p2.samsung.com>
2025-09-17 5:52 ` [f2fs-dev] [PATCH] f2fs: readahead node block in F2FS_GET_BLOCK_PRECACHE mode Yunji Kang
2025-09-18 2:09 ` Chao Yu via Linux-f2fs-devel
2025-09-18 4:55 ` Yunji Kang
2025-09-18 7:02 ` Chao Yu via Linux-f2fs-devel
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).