From nobody Tue Dec 16 06:06:35 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 815E5213E61 for ; Tue, 14 Jan 2025 22:42:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736894568; cv=none; b=TIdK1WesQVj1LN+4ZMAsMrmR+gk2cc+SXgoapXfXw8OE5gWTO7cFXLTjEjewAiycFAVvbgwMfv9fpQ1a9GeNmoTZWg7OZTHLDXA/HgQHSY7pT60xz6Ne2vRzv8apgui8ORovZt64LRKqk1PZ7zVlqQ9VaIkeD/GRYnhm08FfZ8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736894568; c=relaxed/simple; bh=vF8IahqEZetwH8Sob50rBERa1bugGes6l5eS2+8oBww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I+pJ4SFS35liJatSomjpDZem8uNCwVz8eX7g4BcrKBkh7/kb+xWEIxhCQ+mlQjbYkfiJigXNZnG/FkgtO+wS1WrRgX7pBTvSyIpCRilF4XkHboc6n/HAYkDMmuCADhKznzxuO7M4wsG09QmsOfu4xbGn1qerpdTIvA8T4m5TC3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g62vtBl3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g62vtBl3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0EA0C4CEDD; Tue, 14 Jan 2025 22:42:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736894567; bh=vF8IahqEZetwH8Sob50rBERa1bugGes6l5eS2+8oBww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g62vtBl3IkwJwSxJpPYDtjXsF7/D96SITCQNPTB3akb3sWjqYkHmm0pZDQ54viHcR fDf0zAyY95J24yY3wtk2W4B5qY9SWdimLaNeN60YPZbO7uzysNey6HUWsrEmunK3bS ZL/6wSLPQEq+vMdx3ToEwpdKczWAiaI3qxCjFFwifLFLKUNMP6Gmqrt8uSTW+iTBcN 98gfno34Vpg5oPsxLhjIThHeBlo7bZYUNMzyJOxuaVnD1SD8yMoJEFMSMEg+2MYoC5 L/okrhp0PZ2sTfAnMwJF9I6Qkhs4qmLuyixAFPX7hpg6y+DI0vML6sgDb/XYDTso3F xdpLW18rzmIyQ== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 1/2] f2fs: register inodes which is able to donate pages Date: Tue, 14 Jan 2025 22:39:54 +0000 Message-ID: <20250114224242.1630478-2-jaegeuk@kernel.org> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog In-Reply-To: <20250114224242.1630478-1-jaegeuk@kernel.org> References: <20250114224242.1630478-1-jaegeuk@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch introduces an inode list to keep the page cache ranges that users can donate pages together. #define F2FS_IOC_DONATE_RANGE _IOW(F2FS_IOCTL_MAGIC, 27, \ struct f2fs_donate_range) struct f2fs_donate_range { __u64 start; __u64 len; }; e.g., ioctl(F2FS_IOC_DONATE_RANGE, &range); Signed-off-by: Jaegeuk Kim --- fs/f2fs/debug.c | 3 +++ fs/f2fs/f2fs.h | 12 ++++++++- fs/f2fs/file.c | 52 +++++++++++++++++++++++++++++++++++++++ fs/f2fs/inode.c | 14 +++++++++++ fs/f2fs/super.c | 1 + include/uapi/linux/f2fs.h | 7 ++++++ 6 files changed, 88 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index 468828288a4a..16c2dfb4f595 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -164,6 +164,7 @@ static void update_general_status(struct f2fs_sb_info *= sbi) si->ndirty_imeta =3D get_pages(sbi, F2FS_DIRTY_IMETA); si->ndirty_dirs =3D sbi->ndirty_inode[DIR_INODE]; si->ndirty_files =3D sbi->ndirty_inode[FILE_INODE]; + si->ndonate_files =3D sbi->donate_files; si->nquota_files =3D sbi->nquota_files; si->ndirty_all =3D sbi->ndirty_inode[DIRTY_META]; si->aw_cnt =3D atomic_read(&sbi->atomic_files); @@ -501,6 +502,8 @@ static int stat_show(struct seq_file *s, void *v) si->compr_inode, si->compr_blocks); seq_printf(s, " - Swapfile Inode: %u\n", si->swapfile_inode); + seq_printf(s, " - Donate Inode: %u\n", + si->ndonate_files); seq_printf(s, " - Orphan/Append/Update Inode: %u, %u, %u\n", si->orphans, si->append, si->update); seq_printf(s, "\nMain area: %d segs, %d secs %d zones\n", diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 4bfe162eefd3..951fbc3f94c7 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -850,6 +850,11 @@ struct f2fs_inode_info { #endif struct list_head dirty_list; /* dirty list for dirs and files */ struct list_head gdirty_list; /* linked in global dirty list */ + + /* linked in global inode list for cache donation */ + struct list_head gdonate_list; + loff_t donate_start, donate_end; /* inclusive */ + struct task_struct *atomic_write_task; /* store atomic write task */ struct extent_tree *extent_tree[NR_EXTENT_CACHES]; /* cached extent_tree entry */ @@ -1274,6 +1279,7 @@ enum inode_type { DIR_INODE, /* for dirty dir inode */ FILE_INODE, /* for dirty regular/symlink inode */ DIRTY_META, /* for all dirtied inode metadata */ + DONATE_INODE, /* for all inode to donate pages */ NR_INODE_TYPE, }; =20 @@ -1629,6 +1635,9 @@ struct f2fs_sb_info { unsigned int warm_data_age_threshold; unsigned int last_age_weight; =20 + /* control donate caches */ + unsigned int donate_files; + /* basic filesystem units */ unsigned int log_sectors_per_block; /* log2 sectors per block */ unsigned int log_blocksize; /* log2 block size */ @@ -3984,7 +3993,8 @@ struct f2fs_stat_info { unsigned long long allocated_data_blocks; int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; int ndirty_data, ndirty_qdata; - unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; + unsigned int ndirty_dirs, ndirty_files, ndirty_all; + unsigned int nquota_files, ndonate_files; int nats, dirty_nats, sits, dirty_sits; int free_nids, avail_nids, alloc_nids; int total_count, utilization; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 81764b10840b..c43d64898d8b 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2429,6 +2429,55 @@ static int f2fs_ioc_shutdown(struct file *filp, unsi= gned long arg) return ret; } =20 +static int f2fs_ioc_donate_range(struct file *filp, unsigned long arg) +{ + struct inode *inode =3D file_inode(filp); + struct mnt_idmap *idmap =3D file_mnt_idmap(filp); + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + struct f2fs_donate_range range; + int ret; + + if (copy_from_user(&range, (struct f2fs_donate_range __user *)arg, + sizeof(range))) + return -EFAULT; + + if (!inode_owner_or_capable(idmap, inode)) + return -EACCES; + + if (!S_ISREG(inode->i_mode)) + return -EINVAL; + + if (unlikely((range.start + range.len) >> PAGE_SHIFT > + max_file_blocks(inode))) + return -EINVAL; + + ret =3D mnt_want_write_file(filp); + if (ret) + return ret; + + inode_lock(inode); + + if (f2fs_is_atomic_file(inode)) + goto out; + + spin_lock(&sbi->inode_lock[DONATE_INODE]); + if (list_empty(&F2FS_I(inode)->gdonate_list)) { + list_add_tail(&F2FS_I(inode)->gdonate_list, + &sbi->inode_list[DONATE_INODE]); + sbi->donate_files++; + } else { + list_move_tail(&F2FS_I(inode)->gdonate_list, + &sbi->inode_list[DONATE_INODE]); + } + F2FS_I(inode)->donate_start =3D range.start; + F2FS_I(inode)->donate_end =3D range.start + range.len - 1; + spin_unlock(&sbi->inode_lock[DONATE_INODE]); +out: + inode_unlock(inode); + mnt_drop_write_file(filp); + return ret; +} + static int f2fs_ioc_fitrim(struct file *filp, unsigned long arg) { struct inode *inode =3D file_inode(filp); @@ -4458,6 +4507,8 @@ static long __f2fs_ioctl(struct file *filp, unsigned = int cmd, unsigned long arg) return -EOPNOTSUPP; case F2FS_IOC_SHUTDOWN: return f2fs_ioc_shutdown(filp, arg); + case F2FS_IOC_DONATE_RANGE: + return f2fs_ioc_donate_range(filp, arg); case FITRIM: return f2fs_ioc_fitrim(filp, arg); case FS_IOC_SET_ENCRYPTION_POLICY: @@ -5209,6 +5260,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned in= t cmd, unsigned long arg) case F2FS_IOC_RELEASE_VOLATILE_WRITE: case F2FS_IOC_ABORT_ATOMIC_WRITE: case F2FS_IOC_SHUTDOWN: + case F2FS_IOC_DONATE_RANGE: case FITRIM: case FS_IOC_SET_ENCRYPTION_POLICY: case FS_IOC_GET_ENCRYPTION_PWSALT: diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 7de33da8b3ea..f9fc58f313f2 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -804,6 +804,19 @@ int f2fs_write_inode(struct inode *inode, struct write= back_control *wbc) return 0; } =20 +static void f2fs_remove_donate_inode(struct inode *inode) +{ + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + + if (list_empty(&F2FS_I(inode)->gdonate_list)) + return; + + spin_lock(&sbi->inode_lock[DONATE_INODE]); + list_del_init(&F2FS_I(inode)->gdonate_list); + sbi->donate_files--; + spin_unlock(&sbi->inode_lock[DONATE_INODE]); +} + /* * Called at the last iput() if i_nlink is zero */ @@ -838,6 +851,7 @@ void f2fs_evict_inode(struct inode *inode) =20 f2fs_bug_on(sbi, get_dirty_pages(inode)); f2fs_remove_dirty_inode(inode); + f2fs_remove_donate_inode(inode); =20 if (!IS_DEVICE_ALIASING(inode)) f2fs_destroy_extent_tree(inode); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index fc7d463dee15..ef639a6d82e5 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1441,6 +1441,7 @@ static struct inode *f2fs_alloc_inode(struct super_bl= ock *sb) spin_lock_init(&fi->i_size_lock); INIT_LIST_HEAD(&fi->dirty_list); INIT_LIST_HEAD(&fi->gdirty_list); + INIT_LIST_HEAD(&fi->gdonate_list); init_f2fs_rwsem(&fi->i_gc_rwsem[READ]); init_f2fs_rwsem(&fi->i_gc_rwsem[WRITE]); init_f2fs_rwsem(&fi->i_xattr_sem); diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h index f7aaf8d23e20..cd38a7c166e6 100644 --- a/include/uapi/linux/f2fs.h +++ b/include/uapi/linux/f2fs.h @@ -44,6 +44,8 @@ #define F2FS_IOC_COMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 24) #define F2FS_IOC_START_ATOMIC_REPLACE _IO(F2FS_IOCTL_MAGIC, 25) #define F2FS_IOC_GET_DEV_ALIAS_FILE _IOR(F2FS_IOCTL_MAGIC, 26, __u32) +#define F2FS_IOC_DONATE_RANGE _IOW(F2FS_IOCTL_MAGIC, 27, \ + struct f2fs_donate_range) =20 /* * should be same as XFS_IOC_GOINGDOWN. @@ -97,4 +99,9 @@ struct f2fs_comp_option { __u8 log_cluster_size; }; =20 +struct f2fs_donate_range { + __u64 start; + __u64 len; +}; + #endif /* _UAPI_LINUX_F2FS_H */ --=20 2.48.0.rc2.279.g1de40edade-goog