Commit 1119ec49 authored by ZhaoLong Wang's avatar ZhaoLong Wang
Browse files

mm, fs: Add BPF_READAHEAD build option for bpf readhead

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I7Y9JD


CVE: NA

---------------------------

This patch introduces a new configuration option called
BPF_READAHEAD, which is designed to optimize the read
performance in Spark SQL scenarios using eBPF to implement a
programmable kernel.

The changes include:

 - Add CONFIG_BPF_READAHEAD to mm/Kconfig, which depends on
   CONFIG_TRACEPOINTS.

 - Add conditional compilation directives to fs/ext4/file.c, fs/read_write.c,
   fs/xfs/xfs_file.c, and include/linux/fs.h to include tracepoint-related
   headers and functions only when BPF_READAHEAD is enabled.

 - Miodify page_cache_sync_ra() in mm/readahead.c to disable forced readahead
   when BPF_READAHEAD is not enabled.

Signed-off-by: default avatarZhaoLong Wang <wangzhaolong1@huawei.com>
parent 1bab7be7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1721,7 +1721,7 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out)
	return 0;
}

#ifdef CONFIG_TRACEPOINTS
#ifdef CONFIG_BPF_READAHEAD
static void fs_file_read_ctx_init(struct fs_file_read_ctx *ctx,
				  struct file *filp, loff_t pos)
{
@@ -1752,7 +1752,7 @@ void fs_file_read_update_args_by_trace(struct kiocb *iocb)
	filp->f_ctl_mode &= ~(ctx.clr_f_mode & FS_FILE_READ_MODE_MASK);
}
EXPORT_SYMBOL_GPL(fs_file_read_update_args_by_trace);
#endif

EXPORT_TRACEPOINT_SYMBOL_GPL(fs_file_read);
EXPORT_TRACEPOINT_SYMBOL_GPL(fs_file_release);
#endif
+13 −5
Original line number Diff line number Diff line
@@ -43,7 +43,9 @@
#include <linux/cred.h>
#include <linux/mnt_idmapping.h>
#include <linux/slab.h>
#ifdef CONFIG_BPF_READAHEAD
#include <linux/tracepoint-defs.h>
#endif
#include <linux/kabi.h>

#include <asm/byteorder.h>
@@ -190,11 +192,16 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
/* File supports async nowait buffered writes */
#define FMODE_BUF_WASYNC	((__force fmode_t)0x80000000)

#ifdef CONFIG_BPF_READAHEAD
/* File mode control flag, expect random access pattern */
#define FMODE_CTL_RANDOM	((__force fmode_t)0x1000)

/* File mode control flag, will try to read head of the file into pagecache */
#define FMODE_CTL_WILLNEED		((__force fmode_t)0x400000)
#else
#define FMODE_CTL_RANDOM	0
#define FMODE_CTL_WILLNEED	0
#endif

/*
 * Attribute flags.  These should be or-ed together to figure out what
@@ -3524,16 +3531,17 @@ struct fs_file_read_ctx {
	long long index;
};

#ifdef CONFIG_TRACEPOINTS
#ifdef CONFIG_BPF_READAHEAD
DECLARE_TRACEPOINT(fs_file_read);
extern void fs_file_read_update_args_by_trace(struct kiocb *iocb);
#else
static inline void fs_file_read_update_args_by_trace(struct kiocb *iocb) {}
#endif

static inline void fs_file_read_do_trace(struct kiocb *iocb)
{
	if (tracepoint_enabled(fs_file_read))
		fs_file_read_update_args_by_trace(iocb);
}
#else
static inline void fs_file_read_update_args_by_trace(struct kiocb *iocb) {}
static inline void fs_file_read_do_trace(struct kiocb *iocb) {}
#endif

#endif /* _LINUX_FS_H */
+6 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifdef CONFIG_BPF_READAHEAD

#undef TRACE_SYSTEM
#define TRACE_SYSTEM fs

@@ -31,3 +33,7 @@ DECLARE_TRACE(fs_file_release,

/* This part must be outside protection */
#include <trace/define_trace.h>
#else
#define trace_fs_file_release(...)
#define trace_fs_file_read(...)
#endif /* CONFIG_BPF_READAHEAD */
+9 −0
Original line number Diff line number Diff line
@@ -1424,6 +1424,15 @@ config ETMEM
	  high-performance storage media to release memory space and reduce
	  memory costs.

config BPF_READAHEAD
	bool "Enable bpf readahead optimization"
	select TRACEPOINTS
	default n
	help
	  EBPF is used to implement a programmable kernel. The readahead behavior
	  of the kernel is adjusted based on the application read mode to optimize
	  the read performance in the Spark SQL scenario,

source "mm/damon/Kconfig"

endmenu