Unverified Commit f6805816 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!3895 Spark SQL scenario bpf readahead optimization synchronization to OLK-6.6

Merge Pull Request from: @ci-robot 
 
PR sync from: ZhaoLong Wang <wangzhaolong1@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/RLF5JH5J3HK3VWYVGZCNKKOQM5QMJDRK/ 
CONFIG:
CONFIG_DEBUG_INFO_BTF=y
CONFIG_BPF_SYSCALL=y
CONFIG_NF_CONNTRACK=y
CONFIG_NF_CONNTRACK_MARK=y

V2:
 - Using helpers function, such as i_size_read(), round_up
 - Fix commit log Signature

V3
 - Do not use the round_up helper function. Use the correct calculation
 - err = -errno before printf

V4
 - Drop the "Conflict" in the commit log.

Hou Tao (5):
  vfs: add bare tracepoints for vfs read and release
  fs: add helper fs_file_read_do_trace()
  xfs: add trace for read and release of regular file
  ext4: add trace for the read and release of regular file
  selftests/bpf: add demo for file read pattern detection

Yufen Yu (1):
  readahead: introduce FMODE_CTL_WILLNEED to read first 2MB of file

ZhaoLong Wang (2):
  selftests/bpf: Update the demo file_read_pattern to run on libbpf 1.0+


-- 
2.39.2
 
https://gitee.com/openeuler/kernel/issues/I7Y9JD
https://gitee.com/openeuler/kernel/issues/I8O4U8 
 
Link:https://gitee.com/openeuler/kernel/pulls/3895

 

Reviewed-by: default avatarHou Tao <houtao1@huawei.com>
Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parents 3d157b5f f063f495
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <linux/uio.h>
#include <linux/mman.h>
#include <linux/backing-dev.h>
#include <trace/events/fs.h>
#include "ext4.h"
#include "ext4_jbd2.h"
#include "xattr.h"
@@ -144,6 +145,7 @@ static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
	if (iocb->ki_flags & IOCB_DIRECT)
		return ext4_dio_read_iter(iocb, to);

	fs_file_read_do_trace(iocb);
	return generic_file_read_iter(iocb, to);
}

@@ -165,6 +167,8 @@ static ssize_t ext4_file_splice_read(struct file *in, loff_t *ppos,
 */
static int ext4_release_file(struct inode *inode, struct file *filp)
{
	trace_fs_file_release(inode, filp);

	if (ext4_test_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE)) {
		ext4_alloc_da_blocks(inode);
		ext4_clear_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE);
+38 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@

#include <linux/uaccess.h>
#include <asm/unistd.h>
#define CREATE_TRACE_POINTS
#include <trace/events/fs.h>

const struct file_operations generic_ro_fops = {
	.llseek		= generic_file_llseek,
@@ -1718,3 +1720,39 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out)

	return 0;
}

#ifdef CONFIG_TRACEPOINTS
static void fs_file_read_ctx_init(struct fs_file_read_ctx *ctx,
				  struct file *filp, loff_t pos)
{
	memset(ctx, 0, sizeof(*ctx));
	ctx->name = file_dentry(filp)->d_name.name;
	ctx->f_mode = filp->f_mode;
	ctx->key = (unsigned long)filp;
	ctx->i_size = i_size_read(file_inode(filp));
	ctx->prev_index = filp->f_ra.prev_pos >> PAGE_SHIFT;
	ctx->index = pos >> PAGE_SHIFT;
}

#define FS_FILE_READ_VERSION 1
#define FS_FILE_READ_MODE_MASK (FMODE_CTL_RANDOM | FMODE_CTL_WILLNEED)

void fs_file_read_update_args_by_trace(struct kiocb *iocb)
{
	struct file *filp = iocb->ki_filp;
	struct fs_file_read_ctx ctx;

	fs_file_read_ctx_init(&ctx, filp, iocb->ki_pos);
	trace_fs_file_read(&ctx, FS_FILE_READ_VERSION);

	if (!ctx.set_f_mode && !ctx.clr_f_mode)
		return;

	filp->f_ctl_mode |= ctx.set_f_mode & FS_FILE_READ_MODE_MASK;
	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);
+3 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <linux/mman.h>
#include <linux/fadvise.h>
#include <linux/mount.h>
#include <trace/events/fs.h>

static const struct vm_operations_struct xfs_file_vm_ops;

@@ -270,6 +271,7 @@ xfs_file_buffered_read(
	ssize_t			ret;

	trace_xfs_file_buffered_read(iocb, to);
	fs_file_read_do_trace(iocb);

	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
	if (ret)
@@ -1227,6 +1229,7 @@ xfs_file_release(
	struct inode	*inode,
	struct file	*filp)
{
	trace_fs_file_release(inode, filp);
	return xfs_release(XFS_I(inode));
}

+37 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
#include <linux/cred.h>
#include <linux/mnt_idmapping.h>
#include <linux/slab.h>
#include <linux/tracepoint-defs.h>

#include <asm/byteorder.h>
#include <uapi/linux/fs.h>
@@ -188,6 +189,12 @@ 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)

/* 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)

/*
 * Attribute flags.  These should be or-ed together to figure out what
 * has been changed!
@@ -1030,6 +1037,7 @@ struct file {
	struct address_space	*f_mapping;
	errseq_t		f_wb_err;
	errseq_t		f_sb_err; /* for syncfs */
	fmode_t			f_ctl_mode;
} __randomize_layout
  __attribute__((aligned(4)));	/* lest something weird decides that 2 is OK */

@@ -3382,4 +3390,33 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len,
extern int generic_fadvise(struct file *file, loff_t offset, loff_t len,
			   int advice);

struct fs_file_read_ctx {
	const unsigned char *name;
	unsigned int f_mode;
	unsigned int rsvd;
	/* clear from f_ctl_mode */
	unsigned int clr_f_mode;
	/* set into f_ctl_mode */
	unsigned int set_f_mode;
	unsigned long key;
	/* file size */
	long long i_size;
	/* previous page index */
	long long prev_index;
	/* current page index */
	long long index;
};

#ifdef CONFIG_TRACEPOINTS
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);
}
#endif /* _LINUX_FS_H */
+33 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM fs

#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_FS_H

#include <linux/types.h>
#include <linux/tracepoint.h>
#include <linux/fs.h>

#undef FS_DECLARE_TRACE
#ifdef DECLARE_TRACE_WRITABLE
#define FS_DECLARE_TRACE(call, proto, args, size) \
	DECLARE_TRACE_WRITABLE(call, PARAMS(proto), PARAMS(args), size)
#else
#define FS_DECLARE_TRACE(call, proto, args, size) \
	DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))
#endif

FS_DECLARE_TRACE(fs_file_read,
	TP_PROTO(struct fs_file_read_ctx *ctx, int version),
	TP_ARGS(ctx, version),
	sizeof(struct fs_file_read_ctx));

DECLARE_TRACE(fs_file_release,
	TP_PROTO(struct inode *inode, struct file *filp),
	TP_ARGS(inode, filp));

#endif /* _TRACE_FS_H */

/* This part must be outside protection */
#include <trace/define_trace.h>
Loading