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

!3588 files cgroups

Merge Pull Request from: @chenridong 
 
Merge original patch:[cgroups: Resource controller for open files]
and it's bugfixes listed in the issue.
https://gitee.com/openeuler/kernel/issues/I8ND8I
Besides, add enable / disable switch and boot parameter 
 
Link:https://gitee.com/openeuler/kernel/pulls/3588

 

Reviewed-by: default avatarZhang Jianhua <chris.zjh@huawei.com>
Reviewed-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: default avatarZucheng Zheng <zhengzucheng@huawei.com>
Reviewed-by: default avatarLu Jialin <lujialin4@huawei.com>
Reviewed-by: default avatarLiu Chao <liuchao173@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parents a60f40a8 7ef10071
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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

+1 −0
Original line number Diff line number Diff line
@@ -183,6 +183,7 @@ CONFIG_CGROUP_BPF=y
# CONFIG_CGROUP_DEBUG is not set
CONFIG_SOCK_CGROUP_DATA=y
CONFIG_CGROUP_V1_KILL=y
CONFIG_CGROUP_FILES=y
CONFIG_NAMESPACES=y
CONFIG_UTS_NS=y
CONFIG_TIME_NS=y
+1 −0
Original line number Diff line number Diff line
@@ -205,6 +205,7 @@ CONFIG_CGROUP_BPF=y
# CONFIG_CGROUP_DEBUG is not set
CONFIG_SOCK_CGROUP_DATA=y
CONFIG_CGROUP_V1_KILL=y
CONFIG_CGROUP_FILES=y
CONFIG_NAMESPACES=y
CONFIG_UTS_NS=y
CONFIG_TIME_NS=y
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ obj-$(CONFIG_COREDUMP) += coredump.o
obj-$(CONFIG_SYSCTL)		+= drop_caches.o sysctls.o

obj-$(CONFIG_FHANDLE)		+= fhandle.o
obj-$(CONFIG_CGROUP_FILES)	+= filescontrol.o
obj-y				+= iomap/

obj-y				+= quota/
+37 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <linux/bitops.h>
#include <linux/spinlock.h>
#include <linux/rcupdate.h>
#include <linux/filescontrol.h>
#include <linux/close_range.h>
#include <net/sock.h>

@@ -337,6 +338,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, unsigned int max_fds, int
	new_fdt->open_fds = newf->open_fds_init;
	new_fdt->full_fds_bits = newf->full_fds_bits_init;
	new_fdt->fd = &newf->fd_array[0];
	files_cgroup_assign(newf);

	spin_lock(&oldf->file_lock);
	old_fdt = files_fdtable(oldf);
@@ -401,9 +403,23 @@ struct files_struct *dup_fd(struct files_struct *oldf, unsigned int max_fds, int

	rcu_assign_pointer(newf->fdt, new_fdt);

	return newf;
	if (files_cgroup_dup_fds(newf)) {
		/* could not get enough FD resources.  Need to clean up. */
		new_fds = new_fdt->fd;
		for (i = open_files; i != 0; i--) {
			struct file *f = *new_fds++;

			if (f)
				fput(f);
		}
		if (new_fdt != &newf->fdtab)
			__free_fdtable(new_fdt);
		*errorp = -EMFILE;
		goto out_release;
	}
	return newf;
out_release:
	files_cgroup_remove(newf);
	kmem_cache_free(files_cachep, newf);
out:
	return NULL;
@@ -429,6 +445,7 @@ static struct fdtable *close_files(struct files_struct * files)
			if (set & 1) {
				struct file * file = xchg(&fdt->fd[i], NULL);
				if (file) {
					files_cgroup_unalloc_fd(files, 1);
					filp_close(file, files);
					cond_resched();
				}
@@ -437,7 +454,7 @@ static struct fdtable *close_files(struct files_struct * files)
			set >>= 1;
		}
	}

	files_cgroup_remove(files);
	return fdt;
}

@@ -531,6 +548,10 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
	 */
	if (error)
		goto repeat;
	if (files_cgroup_alloc_fd(files, 1)) {
		error = -EMFILE;
		goto out;
	}

	if (start <= files->next_fd)
		files->next_fd = fd + 1;
@@ -568,6 +589,8 @@ EXPORT_SYMBOL(get_unused_fd_flags);
static void __put_unused_fd(struct files_struct *files, unsigned int fd)
{
	struct fdtable *fdt = files_fdtable(files);

	files_cgroup_put_fd(files, fd);
	__clear_open_fd(fd, fdt);
	if (fd < files->next_fd)
		files->next_fd = fd;
@@ -1106,6 +1129,7 @@ static int do_dup2(struct files_struct *files,
	struct file *file, unsigned fd, unsigned flags)
__releases(&files->file_lock)
{
	int err;
	struct file *tofree;
	struct fdtable *fdt;

@@ -1125,8 +1149,15 @@ __releases(&files->file_lock)
	 */
	fdt = files_fdtable(files);
	tofree = fdt->fd[fd];
	if (!tofree && fd_is_open(fd, fdt))
		goto Ebusy;
	if (!tofree && fd_is_open(fd, fdt)) {
		err = -EBUSY;
		goto out;
	}

	if (!tofree && files_cgroup_alloc_fd(files, 1)) {
		err = -EMFILE;
		goto out;
	}
	get_file(file);
	rcu_assign_pointer(fdt->fd[fd], file);
	__set_open_fd(fd, fdt);
@@ -1141,9 +1172,9 @@ __releases(&files->file_lock)

	return fd;

Ebusy:
out:
	spin_unlock(&files->file_lock);
	return -EBUSY;
	return err;
}

int replace_fd(unsigned fd, struct file *file, unsigned flags)
Loading