From: Yang Yingliang yangyingliang@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8ND8I
--------------------------------
When files cgroup is enabled, it's will leads syscall performance regression in UnixBench. Add a helper files_cgroup_enabled() and use it to control if use files cgroup, wen can use cgroup_disable=files in cmdline to disable files cgroup.
syscall of UnixBench (large is better) enable files cgroup: 2868.5 disable files cgroup: 3177.0 disable config of files cgroup: 3186.5
Signed-off-by: Yang Yingliang yangyingliang@huawei.com Signed-off-by: chenridong chenridong@huawei.com --- .../admin-guide/kernel-parameters.txt | 7 ++++--- fs/filescontrol.c | 19 +++++++++++++++++++ include/linux/filescontrol.h | 9 +++++++++ 3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 022a06068306..fe2dc03538fe 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -565,9 +565,10 @@ - if foo is an optional feature then the feature is disabled and corresponding cgroup files are not created - {Currently only "memory" controller deal with this and - cut the overhead, others just disable the usage. So - only cgroup_disable=memory is actually worthy} + {Currently only "memory" and and "files" controller + deal with this and cut the overhead, others just + disable the usage. So only cgroup_disable=memory and + cgroup_disable=files are actually worthy} Specifying "pressure" disables per-cgroup pressure stall information accounting feature
diff --git a/fs/filescontrol.c b/fs/filescontrol.c index a47152757207..925e02a2ba33 100644 --- a/fs/filescontrol.c +++ b/fs/filescontrol.c @@ -151,6 +151,9 @@ static int files_cgroup_can_attach(struct cgroup_taskset *tset)
int files_cgroup_alloc_fd(struct files_struct *files, u64 n) { + if (!files_cgroup_enabled()) { + return 0; + } /* * Kernel threads which are forked by kthreadd inherited the * const files_struct 'init_files', we didn't wrap it so @@ -175,6 +178,9 @@ EXPORT_SYMBOL(files_cgroup_alloc_fd);
void files_cgroup_unalloc_fd(struct files_struct *files, u64 n) { + if (!files_cgroup_enabled()) { + return; + } /* * It's not charged so no need to uncharge, see comments in * files_cgroup_alloc_fd. @@ -189,6 +195,9 @@ EXPORT_SYMBOL(files_cgroup_unalloc_fd);
void files_cgroup_put_fd(struct files_struct *files, unsigned int fd) { + if (!files_cgroup_enabled()) { + return; + } struct fdtable *fdt = files_fdtable(files);
if (test_bit(fd, fdt->open_fds)) @@ -197,6 +206,9 @@ void files_cgroup_put_fd(struct files_struct *files, unsigned int fd)
int files_cgroup_get_fd(struct files_struct *newf) { + if (!files_cgroup_enabled()) { + return 0; + } spin_lock(&newf->file_lock); int err = files_cgroup_alloc_fd(newf, files_cgroup_count_fds(newf)); spin_unlock(&newf->file_lock); @@ -302,6 +314,10 @@ struct cgroup_subsys files_cgrp_subsys = { */ void files_cgroup_assign(struct files_struct *files) { + + if (!files_cgroup_enabled()) { + return; + } struct cgroup_subsys_state *css;
if (files == &init_files) @@ -313,6 +329,9 @@ void files_cgroup_assign(struct files_struct *files)
void files_cgroup_remove(struct files_struct *files) { + if (!files_cgroup_enabled()) { + return; + } struct task_struct *tsk = current; struct files_cgroup *fcg;
diff --git a/include/linux/filescontrol.h b/include/linux/filescontrol.h index 07403ada16d7..2744c375699c 100644 --- a/include/linux/filescontrol.h +++ b/include/linux/filescontrol.h @@ -19,6 +19,7 @@ #define _LINUX_FILESCONTROL_H
#include <linux/fdtable.h> +#include <linux/cgroup.h>
#ifdef CONFIG_CGROUP_FILES extern int files_cgroup_alloc_fd(struct files_struct *files, u64 n); @@ -30,15 +31,23 @@ extern void files_cgroup_remove(struct files_struct *files);
extern int files_cgroup_get_fd(struct files_struct *newf); extern void files_cgroup_put_fd(struct files_struct *files, unsigned int fd); + +static inline bool files_cgroup_enabled(void) +{ + return cgroup_subsys_enabled(files_cgrp_subsys); +} + #else /* no CONFIG_CGROUP_FILES */ static inline int files_cgroup_alloc_fd(struct files_struct *files, u64 n){return 0;}; static inline void files_cgroup_unalloc_fd(struct files_struct *files, u64 n){};
+ static inline void files_cgroup_assign(struct files_struct *files){}; static inline void files_cgroup_remove(struct files_struct *files){};
static inline int files_cgroup_get_fd(struct files_struct *newf){return 0;}; static inline void files_cgroup_put_fd(struct files_struct *files, unsigned int fd){}; + #endif /* CONFIG_CGROUP_FILES */
#endif /* _LINUX_FILESCONTROL_H */