Linux XFS filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/6] xfs: BPF data placement policy for zoned file systems
@ 2026-12-01  4:34 Naohiro Aota
  2026-12-01  4:34 ` [PATCH 1/6] fs: add fs_dp BPF struct_ops for file data placement Naohiro Aota
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Naohiro Aota @ 2026-12-01  4:34 UTC (permalink / raw)
  To: viro, brauner, cem, hch
  Cc: ast, djwong, dgc, jack, linux-xfs, linux-fsdevel, bpf,
	linux-kernel, dlemoal, Hans Holmberg, Anuj Gupta, Kanchan Joshi,
	Naohiro Aota

When files with different lifetimes are colocated in the same zone,
zoned XFS suffers from GC write amplification: once the short-lived
files are deleted or overwritten, the zone still holds live data of the
long-lived files, which GC has to move out before the zone can be
reset. This costs throughput and latency.

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.

Results of a micro-benchmark on a 32TB SMR HDD (fill to 80% with 256MiB and
1MiB files, then overwrite) where large and small files are separated
by setting the WRITE_LIFE_SHORT hint on the small ones, either by a BPF
policy or by fcntl in the application:

                     baseline     fcntl hint   BPF policy
  overwrite tput     157 MiB/s    179 MiB/s    179 MiB/s
  large write p99    17.3 s       13.3 s       13.2 s
  GC moved           14.55 GB     0            0

The BPF policy gives the same result as setting the hint with fcntl,
without changing the application.

* Interface

The struct_ops and its registry are in VFS core (fs/fs_dp.c,
CONFIG_FS_DP_BPF), so that other filesystems can use them too. A
filesystem looks up a policy by name with fs_dp_ops_get() and drops it
with fs_dp_ops_put().

** struct_ops

An eBPF program for the policy implements fs_dp_ops. file_open is called
from xfs_file_open() when a file is opened for writing, with the file
being opened, the inode number of its parent directory, and the file's
attributes as a struct file_kattr (project ID, xflags, ...; may be NULL).
It returns the write hint to set on the inode in struct
fs_dp_file_open_res; an invalid hint is ignored.

	struct fs_dp_ops {
		char name[FS_DP_OPS_NAME_MAX];
		int (*file_open)(const struct file *file,
				 unsigned long parent_ino,
				 const struct file_kattr *fa,
				 struct fs_dp_file_open_res *res);
	};

	struct fs_dp_file_open_res {
		enum rw_hint i_write_hint;
	};

fs_dp_file_open_res has only i_write_hint for now. It is a struct so
that it can carry more placement results, e.g. a write stream as in the
reference patches described below.

** Binding to a filesystem

A registered policy is bound with XFS-specific ioctls for now.
XFS_IOC_SET_DP_OPS binds the policy of the given name, or unbinds the
current one if the name is empty; XFS_IOC_GET_DP_OPS returns the name of
the bound policy. Without a flag they act mount-wide and must be issued
on the root directory. With XFS_DP_OPS_F_PROJID they act on the project
ID of the ioctl'd file instead; per-project-ID bindings override the
mount-wide one. (GET is _IOWR so it can read the flag in.) The filesystem
holds a reference on each bound policy until it is replaced or the
filesystem is unmounted.

	struct xfs_dp_ops_name {
		char	name[XFS_DP_OPS_NAME_MAX];	/* NUL-terminated */
		__u32	flags;				/* XFS_DP_OPS_F_* */
		__u32	pad[3];
	};

	#define XFS_DP_OPS_F_PROJID	(1u << 0)
	#define XFS_IOC_SET_DP_OPS	_IOW ('X', 71, struct xfs_dp_ops_name)
	#define XFS_IOC_GET_DP_OPS	_IOWR('X', 72, struct xfs_dp_ops_name)

** Alternative binding interface

A VFS-level hook attached by a BPF link with a target fd is likely the
final form, but needs more VFS and BPF core changes. We keep the binding
XFS-specific for now to get feedback on the idea first.

** Known limitation: FS kfuncs need CONFIG_BPF_LSM

A policy can call FS kfuncs such as bpf_path_d_path() (patch 2), but
only when CONFIG_BPF_LSM is enabled, because fs/bpf_fs_kfuncs.c is built
only with it. binfmt_misc struct_ops programs have the same limitation.
Most of these kfuncs are not tied to BPF LSM, so this should eventually
be fixed by building the file without CONFIG_BPF_LSM (e.g. under a
hidden CONFIG_BPF_FS_KFUNCS selected by BPF_LSM, BINFMT_MISC_BPF and
FS_DP_BPF), keeping only the LSM-specific parts under it. We left that
out of this series to keep it focused, and can send it separately.

* Write streams

The XFS write streams series [1] and its zoned XFS support [2] let user
space reserve streams and set them on files. As a reference, two more
patches on top of them, sent as replies to this mail, let the policy
pick a stream as well: the stream files are bound along with the policy
by XFS_IOC_SET_DP_OPS, and file_open() returns an index into them in
fs_dp_file_open_res.write_stream.

[1] https://lore.kernel.org/linux-xfs/20261103110640.1000095-1-anuj20.g@samsung.com/
[2] https://lore.kernel.org/linux-xfs/20261110103540.46876-1-hans.holmberg@wdc.com/

* Open question

Unregistering a policy only removes its name from the registry; file
systems that use it keep running it until they unbind it, as with
binfmt_misc. Should unregistering stop them instead?

This series is based on v7.4-rc5.

Naohiro Aota (6):
  fs: add fs_dp BPF struct_ops for file data placement
  bpf: allow fs_dp struct_ops programs to call FS kfuncs
  xfs: add BPF data placement hook at file open
  xfs: add ioctls to select a BPF data placement policy
  xfs: bind a BPF data placement policy to a project ID
  xfs: let XFS_IOC_{SET,GET}_DP_OPS act on a project ID

 fs/Kconfig             |  10 ++
 fs/Makefile            |   1 +
 fs/bpf_fs_kfuncs.c     |   6 +-
 fs/fs_dp.c             | 209 +++++++++++++++++++++++++++++++++++++++++
 fs/xfs/Makefile        |   2 +
 fs/xfs/libxfs/xfs_fs.h |  17 ++++
 fs/xfs/xfs_bpf.c       | 197 ++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_bpf.h       |  32 +++++++
 fs/xfs/xfs_file.c      |   2 +
 fs/xfs/xfs_ioctl.c     |   6 ++
 fs/xfs/xfs_mount.h     |   5 +
 fs/xfs/xfs_super.c     |   3 +
 include/linux/fs_dp.h  |  58 ++++++++++++
 13 files changed, 546 insertions(+), 2 deletions(-)
 create mode 100644 fs/fs_dp.c
 create mode 100644 fs/xfs/xfs_bpf.c
 create mode 100644 fs/xfs/xfs_bpf.h
 create mode 100644 include/linux/fs_dp.h


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.56.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-12-01  4:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 0/6] xfs: BPF data placement policy for zoned file systems Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox