* [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages
@ 2025-01-16 17:19 Jaegeuk Kim
2025-01-16 17:19 ` [PATCH 1/2] f2fs: add a sysfs entry to request " Jaegeuk Kim
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2025-01-16 17:19 UTC (permalink / raw)
To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim
If users clearly know which file-backed pages to reclaim in system view, they
can use this ioctl() to register in advance and reclaim all at once later.
Change log from v4:
- fix range handling
Change log from v3:
- cover partial range
Change log from v2:
- add more boundary checks
- de-register the range, if len is zero
Jaegeuk Kim (1):
f2fs: add a sysfs entry to request donate file-backed pages
Yi Sun (1):
f2fs: Optimize f2fs_truncate_data_blocks_range()
Documentation/ABI/testing/sysfs-fs-f2fs | 7 ++++++
fs/f2fs/f2fs.h | 2 ++
fs/f2fs/file.c | 29 +++++++++++++++++++++----
fs/f2fs/shrinker.c | 27 +++++++++++++++++++++++
fs/f2fs/sysfs.c | 8 +++++++
5 files changed, 69 insertions(+), 4 deletions(-)
--
2.48.0.rc2.279.g1de40edade-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] f2fs: add a sysfs entry to request donate file-backed pages
2025-01-16 17:19 [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages Jaegeuk Kim
@ 2025-01-16 17:19 ` Jaegeuk Kim
2025-01-16 17:19 ` [PATCH 2/2] f2fs: Optimize f2fs_truncate_data_blocks_range() Jaegeuk Kim
2025-01-17 7:58 ` [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages Christoph Hellwig
2 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2025-01-16 17:19 UTC (permalink / raw)
To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim
1. ioctl(fd1, F2FS_IOC_DONATE_RANGE, {0,3});
2. ioctl(fd2, F2FS_IOC_DONATE_RANGE, {1,2});
3. ioctl(fd3, F2FS_IOC_DONATE_RANGE, {3,1});
4. echo 3 > /sys/fs/f2fs/blk/donate_caches
will reclaim 3 page cache ranges, registered by #1, #2, and #3.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
Documentation/ABI/testing/sysfs-fs-f2fs | 7 +++++++
fs/f2fs/f2fs.h | 2 ++
fs/f2fs/shrinker.c | 27 +++++++++++++++++++++++++
fs/f2fs/sysfs.c | 8 ++++++++
4 files changed, 44 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index 3e1630c70d8a..6f9d8b8889fd 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -828,3 +828,10 @@ Date: November 2024
Contact: "Chao Yu" <chao@kernel.org>
Description: It controls max read extent count for per-inode, the value of threshold
is 10240 by default.
+
+What: /sys/fs/f2fs/<disk>/donate_caches
+Date: December 2024
+Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
+Description: It reclaims the certian file-backed pages registered by
+ ioctl(F2FS_IOC_DONATE_RANGE).
+ For example, writing N tries to drop N address spaces in LRU.
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 951fbc3f94c7..399ddd10a94f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1637,6 +1637,7 @@ struct f2fs_sb_info {
/* control donate caches */
unsigned int donate_files;
+ unsigned int donate_caches;
/* basic filesystem units */
unsigned int log_sectors_per_block; /* log2 sectors per block */
@@ -4259,6 +4260,7 @@ unsigned long f2fs_shrink_count(struct shrinker *shrink,
struct shrink_control *sc);
unsigned long f2fs_shrink_scan(struct shrinker *shrink,
struct shrink_control *sc);
+void f2fs_donate_caches(struct f2fs_sb_info *sbi);
void f2fs_join_shrinker(struct f2fs_sb_info *sbi);
void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
diff --git a/fs/f2fs/shrinker.c b/fs/f2fs/shrinker.c
index 83d6fb97dcae..22f62813910b 100644
--- a/fs/f2fs/shrinker.c
+++ b/fs/f2fs/shrinker.c
@@ -130,6 +130,33 @@ unsigned long f2fs_shrink_scan(struct shrinker *shrink,
return freed;
}
+void f2fs_donate_caches(struct f2fs_sb_info *sbi)
+{
+ struct inode *inode;
+ struct f2fs_inode_info *fi;
+ int nfiles = sbi->donate_caches;
+
+ while (nfiles--) {
+ spin_lock(&sbi->inode_lock[DONATE_INODE]);
+ if (list_empty(&sbi->inode_list[DONATE_INODE])) {
+ spin_unlock(&sbi->inode_lock[DONATE_INODE]);
+ break;
+ }
+ fi = list_first_entry(&sbi->inode_list[DONATE_INODE],
+ struct f2fs_inode_info, gdonate_list);
+ list_move_tail(&fi->gdonate_list, &sbi->inode_list[DONATE_INODE]);
+ inode = igrab(&fi->vfs_inode);
+ spin_unlock(&sbi->inode_lock[DONATE_INODE]);
+
+ if (!inode)
+ continue;
+
+ invalidate_inode_pages2_range(inode->i_mapping,
+ fi->donate_start, fi->donate_end);
+ iput(inode);
+ }
+}
+
void f2fs_join_shrinker(struct f2fs_sb_info *sbi)
{
spin_lock(&f2fs_list_lock);
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 6b99dc49f776..f81190fabdd3 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -811,6 +811,12 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return count;
}
+ if (!strcmp(a->attr.name, "donate_caches")) {
+ sbi->donate_caches = min(t, sbi->donate_files);
+ f2fs_donate_caches(sbi);
+ return count;
+ }
+
*ui = (unsigned int)t;
return count;
@@ -1030,6 +1036,7 @@ F2FS_SBI_GENERAL_RW_ATTR(max_victim_search);
F2FS_SBI_GENERAL_RW_ATTR(migration_granularity);
F2FS_SBI_GENERAL_RW_ATTR(migration_window_granularity);
F2FS_SBI_GENERAL_RW_ATTR(dir_level);
+F2FS_SBI_GENERAL_RW_ATTR(donate_caches);
#ifdef CONFIG_F2FS_IOSTAT
F2FS_SBI_GENERAL_RW_ATTR(iostat_enable);
F2FS_SBI_GENERAL_RW_ATTR(iostat_period_ms);
@@ -1178,6 +1185,7 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(migration_granularity),
ATTR_LIST(migration_window_granularity),
ATTR_LIST(dir_level),
+ ATTR_LIST(donate_caches),
ATTR_LIST(ram_thresh),
ATTR_LIST(ra_nid_pages),
ATTR_LIST(dirty_nats_ratio),
--
2.48.0.rc2.279.g1de40edade-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] f2fs: Optimize f2fs_truncate_data_blocks_range()
2025-01-16 17:19 [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages Jaegeuk Kim
2025-01-16 17:19 ` [PATCH 1/2] f2fs: add a sysfs entry to request " Jaegeuk Kim
@ 2025-01-16 17:19 ` Jaegeuk Kim
2025-01-17 7:58 ` [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages Christoph Hellwig
2 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2025-01-16 17:19 UTC (permalink / raw)
To: linux-kernel, linux-f2fs-devel; +Cc: Yi Sun, Jaegeuk Kim
From: Yi Sun <yi.sun@unisoc.com>
Function f2fs_invalidate_blocks() can process consecutive
blocks at a time, so f2fs_truncate_data_blocks_range() is
optimized to use the new functionality of
f2fs_invalidate_blocks().
Add two variables @blkstart and @blklen, @blkstart records
the first address of the consecutive blocks, and @blkstart
records the number of consecutive blocks.
Signed-off-by: Yi Sun <yi.sun@unisoc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/file.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 902f8f50cc27..6572970a988a 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -621,8 +621,11 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
int cluster_index = 0, valid_blocks = 0;
int cluster_size = F2FS_I(dn->inode)->i_cluster_size;
bool released = !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks);
+ block_t blkstart;
+ int blklen = 0;
addr = get_dnode_addr(dn->inode, dn->node_page) + ofs;
+ blkstart = le32_to_cpu(*addr);
/* Assumption: truncation starts with cluster */
for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) {
@@ -638,26 +641,44 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
}
if (blkaddr == NULL_ADDR)
- continue;
+ goto next;
f2fs_set_data_blkaddr(dn, NULL_ADDR);
if (__is_valid_data_blkaddr(blkaddr)) {
if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE))
- continue;
+ goto next;
if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr,
DATA_GENERIC_ENHANCE))
- continue;
+ goto next;
if (compressed_cluster)
valid_blocks++;
}
- f2fs_invalidate_blocks(sbi, blkaddr, 1);
+ if (blkstart + blklen == blkaddr) {
+ blklen++;
+ } else {
+ f2fs_invalidate_blocks(sbi, blkstart, blklen);
+ blkstart = blkaddr;
+ blklen = 1;
+ }
if (!released || blkaddr != COMPRESS_ADDR)
nr_free++;
+
+ continue;
+
+next:
+ if (blklen)
+ f2fs_invalidate_blocks(sbi, blkstart, blklen);
+
+ blkstart = le32_to_cpu(*(addr + 1));
+ blklen = 0;
}
+ if (blklen)
+ f2fs_invalidate_blocks(sbi, blkstart, blklen);
+
if (compressed_cluster)
f2fs_i_compr_blocks_update(dn->inode, valid_blocks, false);
--
2.48.0.rc2.279.g1de40edade-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages
2025-01-16 17:19 [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages Jaegeuk Kim
2025-01-16 17:19 ` [PATCH 1/2] f2fs: add a sysfs entry to request " Jaegeuk Kim
2025-01-16 17:19 ` [PATCH 2/2] f2fs: Optimize f2fs_truncate_data_blocks_range() Jaegeuk Kim
@ 2025-01-17 7:58 ` Christoph Hellwig
2025-01-17 16:40 ` Jaegeuk Kim
2 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2025-01-17 7:58 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: linux-kernel, linux-f2fs-devel, linux-fsdevel
Still NAC for sneaking in an almost undocumented MM feature into
a file system ioctl. Especially while a discussion on that is still
ongoin.
And it's still bad that you don't even bother to Cc fsdevel on this,
nor linux-api or in this case the mm list.
On Thu, Jan 16, 2025 at 05:19:42PM +0000, Jaegeuk Kim wrote:
> If users clearly know which file-backed pages to reclaim in system view, they
> can use this ioctl() to register in advance and reclaim all at once later.
>
> Change log from v4:
> - fix range handling
>
> Change log from v3:
> - cover partial range
>
> Change log from v2:
> - add more boundary checks
> - de-register the range, if len is zero
>
> Jaegeuk Kim (1):
> f2fs: add a sysfs entry to request donate file-backed pages
>
> Yi Sun (1):
> f2fs: Optimize f2fs_truncate_data_blocks_range()
>
> Documentation/ABI/testing/sysfs-fs-f2fs | 7 ++++++
> fs/f2fs/f2fs.h | 2 ++
> fs/f2fs/file.c | 29 +++++++++++++++++++++----
> fs/f2fs/shrinker.c | 27 +++++++++++++++++++++++
> fs/f2fs/sysfs.c | 8 +++++++
> 5 files changed, 69 insertions(+), 4 deletions(-)
>
> --
> 2.48.0.rc2.279.g1de40edade-goog
>
>
---end quoted text---
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages
2025-01-17 7:58 ` [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages Christoph Hellwig
@ 2025-01-17 16:40 ` Jaegeuk Kim
0 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2025-01-17 16:40 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-kernel, linux-f2fs-devel, linux-fsdevel
On 01/16, Christoph Hellwig wrote:
> Still NAC for sneaking in an almost undocumented MM feature into
> a file system ioctl. Especially while a discussion on that is still
> ongoin.
>
> And it's still bad that you don't even bother to Cc fsdevel on this,
> nor linux-api or in this case the mm list.
Well, I don't want to bother other groups for random APIs, unless I, myself, am
super confident this is feasible for generic API.
But, let me try to listen to other opinions.
>
> On Thu, Jan 16, 2025 at 05:19:42PM +0000, Jaegeuk Kim wrote:
> > If users clearly know which file-backed pages to reclaim in system view, they
> > can use this ioctl() to register in advance and reclaim all at once later.
> >
> > Change log from v4:
> > - fix range handling
> >
> > Change log from v3:
> > - cover partial range
> >
> > Change log from v2:
> > - add more boundary checks
> > - de-register the range, if len is zero
> >
> > Jaegeuk Kim (1):
> > f2fs: add a sysfs entry to request donate file-backed pages
> >
> > Yi Sun (1):
> > f2fs: Optimize f2fs_truncate_data_blocks_range()
> >
> > Documentation/ABI/testing/sysfs-fs-f2fs | 7 ++++++
> > fs/f2fs/f2fs.h | 2 ++
> > fs/f2fs/file.c | 29 +++++++++++++++++++++----
> > fs/f2fs/shrinker.c | 27 +++++++++++++++++++++++
> > fs/f2fs/sysfs.c | 8 +++++++
> > 5 files changed, 69 insertions(+), 4 deletions(-)
> >
> > --
> > 2.48.0.rc2.279.g1de40edade-goog
> >
> >
> ---end quoted text---
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-17 16:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-16 17:19 [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages Jaegeuk Kim
2025-01-16 17:19 ` [PATCH 1/2] f2fs: add a sysfs entry to request " Jaegeuk Kim
2025-01-16 17:19 ` [PATCH 2/2] f2fs: Optimize f2fs_truncate_data_blocks_range() Jaegeuk Kim
2025-01-17 7:58 ` [PATCH 0/2 v5] add ioctl/sysfs to donate file-backed pages Christoph Hellwig
2025-01-17 16:40 ` Jaegeuk Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox