Linux filesystem development
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Naohiro Aota" <naohiro.aota@wdc.com>, <viro@zeniv.linux.org.uk>,
	<brauner@kernel.org>, <cem@kernel.org>, <hch@lst.de>
Cc: <djwong@kernel.org>, <dgc@kernel.org>, <jack@suse.cz>,
	<linux-xfs@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>,
	<bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<dlemoal@kernel.org>, "Hans Holmberg" <hans.holmberg@wdc.com>,
	"Anuj Gupta" <anuj20.g@samsung.com>,
	"Kanchan Joshi" <joshi.k@samsung.com>
Subject: Re: [PATCH 0/6] xfs: BPF data placement policy for zoned file systems
Date: Tue, 01 Dec 2026 04:56:50 +0000	[thread overview]
Message-ID: <DN94O5A0VHG4.20DQ0YGD1VAAA@gmail.com> (raw)
In-Reply-To: <20261201043452.3866039-1-naohiro.aota@wdc.com>

On Mon, Nov 30, 2026 at 08:34 PM Naohiro Aota <naohiro.aota@wdc.com> wrote:
> We can help GC by setting the file's lifetime hint, as zoned XFS
> separates file data into zones by the hint. But most applications do
> not set the hint, and changing the application code itself is often not
> realistic.
>
> This series adds a struct_ops, fs_dp_ops, whose file_open callback picks
> the hint when a file is opened, e.g. based on its name, path, or project
> ID.

You waited since ALPSS to send this?
Sorry, but the whole thing is an overkill if 'hint' is the only goal. 
Here is a much simpler alternative:

  struct key {
          u64 dev;
          u64 dir;
  };

  struct {
          __uint(type, BPF_MAP_TYPE_HASH);
          __uint(max_entries, 1024);
          __type(key, struct key);
          __type(value, u64);
  } hints SEC(".maps");

  SEC("lsm/file_open")
  int BPF_PROG(set_hint, struct file *file)
  {
          struct dentry *dentry = file->f_path.dentry;
          struct key key = {
                  .dev = dentry->d_sb->s_dev,
                  .dir = dentry->d_parent->d_inode->i_ino,
          };
          u64 *hint;

          if (!(file->f_mode & FMODE_WRITE))
                  return 0;
          hint = bpf_map_lookup_elem(&hints, &key);
          if (hint)
                  bpf_file_set_write_hint(file, *hint);
          return 0;
  }


and the kernel bit:

diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
index 35ccd98..937c278 100644
--- a/fs/bpf_fs_kfuncs.c
+++ b/fs/bpf_fs_kfuncs.c
@@ -498,6 +498,24 @@ __bpf_kfunc struct inode *bpf_real_data_inode(struct file *file)
 	return d_real_inode(file_dentry(file));
 }

+/**
+ * bpf_file_set_write_hint - set the write lifetime hint of a file's inode
+ * @file: file to set the hint on
+ * @hint: one of RWH_WRITE_LIFE_*
+ *
+ * The in-kernel equivalent of fcntl(F_SET_RW_HINT).
+ *
+ * Return: 0 on success, -EINVAL if @hint is not a valid hint.
+ */
+__bpf_kfunc int bpf_file_set_write_hint(struct file *file, u64 hint)
+{
+	if (hint >= WRITE_LIFE_HINT_NR)
+		return -EINVAL;
+
+	WRITE_ONCE(file_inode(file)->i_write_hint, hint);
+	return 0;
+}
+
 __bpf_kfunc_end_defs();

 BTF_KFUNCS_START(bpf_fs_kfunc_set_ids)
@@ -509,6 +527,7 @@ BTF_ID_FLAGS(func, bpf_get_file_xattr, KF_SLEEPABLE)
 BTF_ID_FLAGS(func, bpf_set_dentry_xattr, KF_SLEEPABLE)
 BTF_ID_FLAGS(func, bpf_remove_dentry_xattr, KF_SLEEPABLE)
 BTF_ID_FLAGS(func, bpf_real_data_inode, KF_SLEEPABLE | KF_RET_NULL)
+BTF_ID_FLAGS(func, bpf_file_set_write_hint)
 BTF_ID_FLAGS(func, bpf_inode_init_xattr)
 #ifdef CONFIG_NET
 BTF_ID_FLAGS(func, bpf_sock_read_xattr, KF_RCU)
@@ -519,6 +538,7 @@ BTF_KFUNCS_END(bpf_fs_kfunc_set_ids)
 BTF_SET_START(bpf_fs_kfunc_lsm_only_ids)
 BTF_ID(func, bpf_set_dentry_xattr)
 BTF_ID(func, bpf_remove_dentry_xattr)
+BTF_ID(func, bpf_file_set_write_hint)
 BTF_SET_END(bpf_fs_kfunc_lsm_only_ids)

 BTF_ID_LIST_SINGLE(bpf_inode_init_xattr_ids, func, bpf_inode_init_xattr)

pw-bot: cr

      parent reply	other threads:[~2026-12-01  4:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  4:34 [PATCH 0/6] xfs: BPF data placement policy for zoned file systems Naohiro Aota
2026-12-01  4:34 ` [PATCH 1/6] fs: add fs_dp BPF struct_ops for file data placement Naohiro Aota
2026-12-01  4:34 ` [PATCH 2/6] bpf: allow fs_dp struct_ops programs to call FS kfuncs Naohiro Aota
2026-12-01  4:34 ` [PATCH 3/6] xfs: add BPF data placement hook at file open Naohiro Aota
2026-12-01  4:34 ` [PATCH 4/6] xfs: add ioctls to select a BPF data placement policy Naohiro Aota
2026-12-01  4:34 ` [PATCH 5/6] xfs: bind a BPF data placement policy to a project ID Naohiro Aota
2026-12-01  4:34 ` [PATCH 6/6] xfs: let XFS_IOC_{SET,GET}_DP_OPS act on " Naohiro Aota
2026-12-01  4:37 ` [PATCH 1/2] fs_dp: let a policy pick a write stream Naohiro Aota
2026-12-01  4:37   ` [PATCH 2/2] xfs: bind write streams along with a data placement policy Naohiro Aota
2026-12-01  4:56 ` Alexei Starovoitov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DN94O5A0VHG4.20DQ0YGD1VAAA@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=anuj20.g@samsung.com \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=cem@kernel.org \
    --cc=dgc@kernel.org \
    --cc=djwong@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=hans.holmberg@wdc.com \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=joshi.k@samsung.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=naohiro.aota@wdc.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox