* [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED @ 2025-11-21 1:42 Jaegeuk Kim 2025-11-21 1:42 ` [PATCH 2/2] f2fs: add a tracepoint for readahead pages Jaegeuk Kim 2025-11-21 6:49 ` [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED Christoph Hellwig 0 siblings, 2 replies; 6+ messages in thread From: Jaegeuk Kim @ 2025-11-21 1:42 UTC (permalink / raw) To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim This patch boosts readahead for POSIX_FADV_WILLNEED. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> --- fs/f2fs/data.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 9 +++++--- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index a0433c8a4d84..d95974d79fb3 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2710,6 +2710,67 @@ static void f2fs_readahead(struct readahead_control *rac) f2fs_mpage_readpages(inode, rac, NULL); } +int f2fs_readahead_pages(struct file *file, loff_t offset, loff_t len) +{ + struct inode *inode = file_inode(file); + struct address_space *mapping = file->f_mapping; + pgoff_t start_index = offset >> PAGE_SHIFT; + loff_t endbyte = offset + len; + pgoff_t end_index; + unsigned long nrpages; + unsigned long ra_pages = (16 * 1024 * 1024) / PAGE_SIZE; + DEFINE_READAHEAD(ractl, NULL, &file->f_ra, mapping, start_index); + + if (!S_ISREG(inode->i_mode)) + return -EOPNOTSUPP; + + /* Should be read only. */ + if (!(file->f_mode & FMODE_READ)) + return -EBADF; + + /* Do not support compressed file for large folio. */ + if (f2fs_compressed_file(inode)) + return -EINVAL; + + if (!mapping || len < 0) + return -EINVAL; + + if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) + return -EINVAL; + + /* Load extent cache at the first readahead. */ + f2fs_precache_extents(inode); + + /* + * Careful about overflows. Len == 0 means "as much as possible". Use + * unsigned math because signed overflows are undefined and UBSan + * complains. + */ + if (!len || endbyte > i_size_read(inode) || endbyte < len) + endbyte = i_size_read(inode) - 1; + else + endbyte--; /* inclusive */ + + /* First and last PARTIAL page! */ + end_index = endbyte >> PAGE_SHIFT; + + if (start_index > end_index) + return 0; + + nrpages = end_index - start_index + 1; + + while (nrpages) { + unsigned long this_chunk = min(nrpages, ra_pages); + + ractl.ra->ra_pages = this_chunk; + + page_cache_sync_ra(&ractl, this_chunk << 1); + + nrpages -= this_chunk; + } + return 0; +} + int f2fs_encrypt_one_page(struct f2fs_io_info *fio) { struct inode *inode = fio_inode(fio); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 3340db04a7c2..934287cc5624 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4047,6 +4047,7 @@ int f2fs_init_bio_entry_cache(void); void f2fs_destroy_bio_entry_cache(void); void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, enum page_type type); +int f2fs_readahead_pages(struct file *file, loff_t offset, loff_t len); int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi); void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d7047ca6b98d..b6f71efd6d2a 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -5305,9 +5305,12 @@ static int f2fs_file_fadvise(struct file *filp, loff_t offset, loff_t len, filp->f_mode &= ~FMODE_RANDOM; spin_unlock(&filp->f_lock); return 0; - } else if (advice == POSIX_FADV_WILLNEED && offset == 0) { - /* Load extent cache at the first readahead. */ - f2fs_precache_extents(inode); + } else if (advice == POSIX_FADV_WILLNEED) { + if (offset == 0 && len == -1) { + f2fs_precache_extents(inode); + return 0; + } + return f2fs_readahead_pages(filp, offset, len); } err = generic_fadvise(filp, offset, len, advice); -- 2.52.0.487.g5c8c507ade-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] f2fs: add a tracepoint for readahead pages 2025-11-21 1:42 [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED Jaegeuk Kim @ 2025-11-21 1:42 ` Jaegeuk Kim 2025-11-21 6:49 ` [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED Christoph Hellwig 1 sibling, 0 replies; 6+ messages in thread From: Jaegeuk Kim @ 2025-11-21 1:42 UTC (permalink / raw) To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim This patch adds a tracepoint to track the f2fs_readahead_pages(). Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> --- fs/f2fs/data.c | 3 +++ include/trace/events/f2fs.h | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d95974d79fb3..c80d7960b652 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2757,6 +2757,8 @@ int f2fs_readahead_pages(struct file *file, loff_t offset, loff_t len) if (start_index > end_index) return 0; + trace_f2fs_readahead_pages_start(inode, start_index, end_index); + nrpages = end_index - start_index + 1; while (nrpages) { @@ -2768,6 +2770,7 @@ int f2fs_readahead_pages(struct file *file, loff_t offset, loff_t len) nrpages -= this_chunk; } + trace_f2fs_readahead_pages_end(inode, start_index, end_index); return 0; } diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h index d406b047c50b..bb98a9655ec9 100644 --- a/include/trace/events/f2fs.h +++ b/include/trace/events/f2fs.h @@ -618,6 +618,49 @@ TRACE_EVENT(f2fs_fadvise, __entry->advice) ); +DECLARE_EVENT_CLASS(f2fs__readahead_pages, + + TP_PROTO(struct inode *inode, pgoff_t start, pgoff_t end), + + TP_ARGS(inode, start, end), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(loff_t, size) + __field(pgoff_t, start) + __field(pgoff_t, end) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->size = inode->i_size; + __entry->start = start; + __entry->end = end; + ), + + TP_printk("dev = (%d,%d), ino = %lu, i_size = %lld start: %lu, end: %lu", + show_dev_ino(__entry), + (unsigned long long)__entry->size, + __entry->start, + __entry->end) +); + +DEFINE_EVENT(f2fs__readahead_pages, f2fs_readahead_pages_start, + + TP_PROTO(struct inode *inode, pgoff_t start, pgoff_t end), + + TP_ARGS(inode, start, end) +); + +DEFINE_EVENT(f2fs__readahead_pages, f2fs_readahead_pages_end, + + TP_PROTO(struct inode *inode, pgoff_t start, pgoff_t end), + + TP_ARGS(inode, start, end) +); + TRACE_EVENT(f2fs_map_blocks, TP_PROTO(struct inode *inode, struct f2fs_map_blocks *map, int flag, int ret), -- 2.52.0.487.g5c8c507ade-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED 2025-11-21 1:42 [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED Jaegeuk Kim 2025-11-21 1:42 ` [PATCH 2/2] f2fs: add a tracepoint for readahead pages Jaegeuk Kim @ 2025-11-21 6:49 ` Christoph Hellwig 2025-11-21 18:05 ` Jaegeuk Kim 1 sibling, 1 reply; 6+ messages in thread From: Christoph Hellwig @ 2025-11-21 6:49 UTC (permalink / raw) To: Jaegeuk Kim Cc: linux-kernel, linux-f2fs-devel, Matthew Wilcox, Andrew Morton, linux-fsdevel, linux-mm On Fri, Nov 21, 2025 at 01:42:01AM +0000, Jaegeuk Kim wrote: > This patch boosts readahead for POSIX_FADV_WILLNEED. How? That's not a good changelog. Also open coding the read-ahead logic is not a good idea. The only f2fs-specific bits are the compression check, and the extent precaching, but you surely should be able to share a read-ahead helper with common code instead of duplicating the logic. > > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> > --- > fs/f2fs/data.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ > fs/f2fs/f2fs.h | 1 + > fs/f2fs/file.c | 9 +++++--- > 3 files changed, 68 insertions(+), 3 deletions(-) > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index a0433c8a4d84..d95974d79fb3 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -2710,6 +2710,67 @@ static void f2fs_readahead(struct readahead_control *rac) > f2fs_mpage_readpages(inode, rac, NULL); > } > > +int f2fs_readahead_pages(struct file *file, loff_t offset, loff_t len) > +{ > + struct inode *inode = file_inode(file); > + struct address_space *mapping = file->f_mapping; > + pgoff_t start_index = offset >> PAGE_SHIFT; > + loff_t endbyte = offset + len; > + pgoff_t end_index; > + unsigned long nrpages; > + unsigned long ra_pages = (16 * 1024 * 1024) / PAGE_SIZE; > + DEFINE_READAHEAD(ractl, NULL, &file->f_ra, mapping, start_index); > + > + if (!S_ISREG(inode->i_mode)) > + return -EOPNOTSUPP; > + > + /* Should be read only. */ > + if (!(file->f_mode & FMODE_READ)) > + return -EBADF; > + > + /* Do not support compressed file for large folio. */ > + if (f2fs_compressed_file(inode)) > + return -EINVAL; > + > + if (!mapping || len < 0) > + return -EINVAL; > + > + if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) > + return -EINVAL; > + > + /* Load extent cache at the first readahead. */ > + f2fs_precache_extents(inode); > + > + /* > + * Careful about overflows. Len == 0 means "as much as possible". Use > + * unsigned math because signed overflows are undefined and UBSan > + * complains. > + */ > + if (!len || endbyte > i_size_read(inode) || endbyte < len) > + endbyte = i_size_read(inode) - 1; > + else > + endbyte--; /* inclusive */ > + > + /* First and last PARTIAL page! */ > + end_index = endbyte >> PAGE_SHIFT; > + > + if (start_index > end_index) > + return 0; > + > + nrpages = end_index - start_index + 1; > + > + while (nrpages) { > + unsigned long this_chunk = min(nrpages, ra_pages); > + > + ractl.ra->ra_pages = this_chunk; > + > + page_cache_sync_ra(&ractl, this_chunk << 1); > + > + nrpages -= this_chunk; > + } > + return 0; > +} > + > int f2fs_encrypt_one_page(struct f2fs_io_info *fio) > { > struct inode *inode = fio_inode(fio); > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 3340db04a7c2..934287cc5624 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -4047,6 +4047,7 @@ int f2fs_init_bio_entry_cache(void); > void f2fs_destroy_bio_entry_cache(void); > void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, > enum page_type type); > +int f2fs_readahead_pages(struct file *file, loff_t offset, loff_t len); > int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi); > void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); > void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index d7047ca6b98d..b6f71efd6d2a 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -5305,9 +5305,12 @@ static int f2fs_file_fadvise(struct file *filp, loff_t offset, loff_t len, > filp->f_mode &= ~FMODE_RANDOM; > spin_unlock(&filp->f_lock); > return 0; > - } else if (advice == POSIX_FADV_WILLNEED && offset == 0) { > - /* Load extent cache at the first readahead. */ > - f2fs_precache_extents(inode); > + } else if (advice == POSIX_FADV_WILLNEED) { > + if (offset == 0 && len == -1) { > + f2fs_precache_extents(inode); > + return 0; > + } > + return f2fs_readahead_pages(filp, offset, len); > } > > err = generic_fadvise(filp, offset, len, advice); > -- > 2.52.0.487.g5c8c507ade-goog > > ---end quoted text--- ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED 2025-11-21 6:49 ` [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED Christoph Hellwig @ 2025-11-21 18:05 ` Jaegeuk Kim 2026-01-22 8:34 ` Christoph Hellwig 0 siblings, 1 reply; 6+ messages in thread From: Jaegeuk Kim @ 2025-11-21 18:05 UTC (permalink / raw) To: Christoph Hellwig Cc: linux-kernel, linux-f2fs-devel, Matthew Wilcox, Andrew Morton, linux-fsdevel, linux-mm On 11/20, Christoph Hellwig wrote: > On Fri, Nov 21, 2025 at 01:42:01AM +0000, Jaegeuk Kim wrote: > > This patch boosts readahead for POSIX_FADV_WILLNEED. > > How? That's not a good changelog. > > Also open coding the read-ahead logic is not a good idea. The only > f2fs-specific bits are the compression check, and the extent precaching, > but you surely should be able to share a read-ahead helper with common > code instead of duplicating the logic. Ok, let me try to write up and post a generic version of the changes. > > > > > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> > > --- > > fs/f2fs/data.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ > > fs/f2fs/f2fs.h | 1 + > > fs/f2fs/file.c | 9 +++++--- > > 3 files changed, 68 insertions(+), 3 deletions(-) > > > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > > index a0433c8a4d84..d95974d79fb3 100644 > > --- a/fs/f2fs/data.c > > +++ b/fs/f2fs/data.c > > @@ -2710,6 +2710,67 @@ static void f2fs_readahead(struct readahead_control *rac) > > f2fs_mpage_readpages(inode, rac, NULL); > > } > > > > +int f2fs_readahead_pages(struct file *file, loff_t offset, loff_t len) > > +{ > > + struct inode *inode = file_inode(file); > > + struct address_space *mapping = file->f_mapping; > > + pgoff_t start_index = offset >> PAGE_SHIFT; > > + loff_t endbyte = offset + len; > > + pgoff_t end_index; > > + unsigned long nrpages; > > + unsigned long ra_pages = (16 * 1024 * 1024) / PAGE_SIZE; > > + DEFINE_READAHEAD(ractl, NULL, &file->f_ra, mapping, start_index); > > + > > + if (!S_ISREG(inode->i_mode)) > > + return -EOPNOTSUPP; > > + > > + /* Should be read only. */ > > + if (!(file->f_mode & FMODE_READ)) > > + return -EBADF; > > + > > + /* Do not support compressed file for large folio. */ > > + if (f2fs_compressed_file(inode)) > > + return -EINVAL; > > + > > + if (!mapping || len < 0) > > + return -EINVAL; > > + > > + if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) > > + return -EINVAL; > > + > > + /* Load extent cache at the first readahead. */ > > + f2fs_precache_extents(inode); > > + > > + /* > > + * Careful about overflows. Len == 0 means "as much as possible". Use > > + * unsigned math because signed overflows are undefined and UBSan > > + * complains. > > + */ > > + if (!len || endbyte > i_size_read(inode) || endbyte < len) > > + endbyte = i_size_read(inode) - 1; > > + else > > + endbyte--; /* inclusive */ > > + > > + /* First and last PARTIAL page! */ > > + end_index = endbyte >> PAGE_SHIFT; > > + > > + if (start_index > end_index) > > + return 0; > > + > > + nrpages = end_index - start_index + 1; > > + > > + while (nrpages) { > > + unsigned long this_chunk = min(nrpages, ra_pages); > > + > > + ractl.ra->ra_pages = this_chunk; > > + > > + page_cache_sync_ra(&ractl, this_chunk << 1); > > + > > + nrpages -= this_chunk; > > + } > > + return 0; > > +} > > + > > int f2fs_encrypt_one_page(struct f2fs_io_info *fio) > > { > > struct inode *inode = fio_inode(fio); > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > index 3340db04a7c2..934287cc5624 100644 > > --- a/fs/f2fs/f2fs.h > > +++ b/fs/f2fs/f2fs.h > > @@ -4047,6 +4047,7 @@ int f2fs_init_bio_entry_cache(void); > > void f2fs_destroy_bio_entry_cache(void); > > void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, > > enum page_type type); > > +int f2fs_readahead_pages(struct file *file, loff_t offset, loff_t len); > > int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi); > > void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); > > void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > > index d7047ca6b98d..b6f71efd6d2a 100644 > > --- a/fs/f2fs/file.c > > +++ b/fs/f2fs/file.c > > @@ -5305,9 +5305,12 @@ static int f2fs_file_fadvise(struct file *filp, loff_t offset, loff_t len, > > filp->f_mode &= ~FMODE_RANDOM; > > spin_unlock(&filp->f_lock); > > return 0; > > - } else if (advice == POSIX_FADV_WILLNEED && offset == 0) { > > - /* Load extent cache at the first readahead. */ > > - f2fs_precache_extents(inode); > > + } else if (advice == POSIX_FADV_WILLNEED) { > > + if (offset == 0 && len == -1) { > > + f2fs_precache_extents(inode); > > + return 0; > > + } > > + return f2fs_readahead_pages(filp, offset, len); > > } > > > > err = generic_fadvise(filp, offset, len, advice); > > -- > > 2.52.0.487.g5c8c507ade-goog > > > > > ---end quoted text--- ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED 2025-11-21 18:05 ` Jaegeuk Kim @ 2026-01-22 8:34 ` Christoph Hellwig 2026-01-22 23:26 ` Jaegeuk Kim 0 siblings, 1 reply; 6+ messages in thread From: Christoph Hellwig @ 2026-01-22 8:34 UTC (permalink / raw) To: Jaegeuk Kim Cc: Christoph Hellwig, linux-kernel, linux-f2fs-devel, Matthew Wilcox, Andrew Morton, linux-fsdevel, linux-mm On Fri, Nov 21, 2025 at 06:05:01PM +0000, Jaegeuk Kim wrote: > On 11/20, Christoph Hellwig wrote: > > On Fri, Nov 21, 2025 at 01:42:01AM +0000, Jaegeuk Kim wrote: > > > This patch boosts readahead for POSIX_FADV_WILLNEED. > > > > How? That's not a good changelog. > > > > Also open coding the read-ahead logic is not a good idea. The only > > f2fs-specific bits are the compression check, and the extent precaching, > > but you surely should be able to share a read-ahead helper with common > > code instead of duplicating the logic. > > Ok, let me try to write up and post a generic version of the changes. Did this go anywhere? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED 2026-01-22 8:34 ` Christoph Hellwig @ 2026-01-22 23:26 ` Jaegeuk Kim 0 siblings, 0 replies; 6+ messages in thread From: Jaegeuk Kim @ 2026-01-22 23:26 UTC (permalink / raw) To: Christoph Hellwig Cc: linux-kernel, linux-f2fs-devel, Matthew Wilcox, Andrew Morton, linux-fsdevel, linux-mm On 01/22, Christoph Hellwig wrote: > On Fri, Nov 21, 2025 at 06:05:01PM +0000, Jaegeuk Kim wrote: > > On 11/20, Christoph Hellwig wrote: > > > On Fri, Nov 21, 2025 at 01:42:01AM +0000, Jaegeuk Kim wrote: > > > > This patch boosts readahead for POSIX_FADV_WILLNEED. > > > > > > How? That's not a good changelog. > > > > > > Also open coding the read-ahead logic is not a good idea. The only > > > f2fs-specific bits are the compression check, and the extent precaching, > > > but you surely should be able to share a read-ahead helper with common > > > code instead of duplicating the logic. > > > > Ok, let me try to write up and post a generic version of the changes. > > Did this go anywhere? Here. https://lore.kernel.org/lkml/20251202013212.964298-1-jaegeuk@kernel.org/ ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-01-22 23:26 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-21 1:42 [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED Jaegeuk Kim 2025-11-21 1:42 ` [PATCH 2/2] f2fs: add a tracepoint for readahead pages Jaegeuk Kim 2025-11-21 6:49 ` [PATCH 1/2] f2fs: improve readahead for POSIX_FADV_WILLNEED Christoph Hellwig 2025-11-21 18:05 ` Jaegeuk Kim 2026-01-22 8:34 ` Christoph Hellwig 2026-01-22 23:26 ` Jaegeuk Kim
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox