forked from mirrors/linux
		
	cgroup: Remove CFTYPE_PRESSURE
CFTYPE_PRESSURE is used to flag PSI related files so that they are not created if PSI is disabled during boot. It's a bit weird to use a generic flag to mark a specific file type. Let's instead move the PSI files into its own cftypes array and add/rm them conditionally. This is a bit more code but cleaner. No userland visible changes. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org>
This commit is contained in:
		
							parent
							
								
									0083d27b21
								
							
						
					
					
						commit
						8a693f7766
					
				
					 2 changed files with 36 additions and 27 deletions
				
			
		| 
						 | 
					@ -126,7 +126,6 @@ enum {
 | 
				
			||||||
	CFTYPE_NO_PREFIX	= (1 << 3),	/* (DON'T USE FOR NEW FILES) no subsys prefix */
 | 
						CFTYPE_NO_PREFIX	= (1 << 3),	/* (DON'T USE FOR NEW FILES) no subsys prefix */
 | 
				
			||||||
	CFTYPE_WORLD_WRITABLE	= (1 << 4),	/* (DON'T USE FOR NEW FILES) S_IWUGO */
 | 
						CFTYPE_WORLD_WRITABLE	= (1 << 4),	/* (DON'T USE FOR NEW FILES) S_IWUGO */
 | 
				
			||||||
	CFTYPE_DEBUG		= (1 << 5),	/* create when cgroup_debug */
 | 
						CFTYPE_DEBUG		= (1 << 5),	/* create when cgroup_debug */
 | 
				
			||||||
	CFTYPE_PRESSURE		= (1 << 6),	/* only if pressure feature is enabled */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* internal flags, do not use outside cgroup core proper */
 | 
						/* internal flags, do not use outside cgroup core proper */
 | 
				
			||||||
	__CFTYPE_ONLY_ON_DFL	= (1 << 16),	/* only on default hierarchy */
 | 
						__CFTYPE_ONLY_ON_DFL	= (1 << 16),	/* only on default hierarchy */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -217,6 +217,7 @@ struct cgroup_namespace init_cgroup_ns = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct file_system_type cgroup2_fs_type;
 | 
					static struct file_system_type cgroup2_fs_type;
 | 
				
			||||||
static struct cftype cgroup_base_files[];
 | 
					static struct cftype cgroup_base_files[];
 | 
				
			||||||
 | 
					static struct cftype cgroup_psi_files[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* cgroup optional features */
 | 
					/* cgroup optional features */
 | 
				
			||||||
enum cgroup_opt_features {
 | 
					enum cgroup_opt_features {
 | 
				
			||||||
| 
						 | 
					@ -1689,12 +1690,16 @@ static void css_clear_dir(struct cgroup_subsys_state *css)
 | 
				
			||||||
	css->flags &= ~CSS_VISIBLE;
 | 
						css->flags &= ~CSS_VISIBLE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!css->ss) {
 | 
						if (!css->ss) {
 | 
				
			||||||
		if (cgroup_on_dfl(cgrp))
 | 
							if (cgroup_on_dfl(cgrp)) {
 | 
				
			||||||
			cfts = cgroup_base_files;
 | 
								cgroup_addrm_files(css, cgrp,
 | 
				
			||||||
		else
 | 
										   cgroup_base_files, false);
 | 
				
			||||||
			cfts = cgroup1_base_files;
 | 
								if (cgroup_psi_enabled())
 | 
				
			||||||
 | 
									cgroup_addrm_files(css, cgrp,
 | 
				
			||||||
		cgroup_addrm_files(css, cgrp, cfts, false);
 | 
											   cgroup_psi_files, false);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								cgroup_addrm_files(css, cgrp,
 | 
				
			||||||
 | 
										   cgroup1_base_files, false);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		list_for_each_entry(cfts, &css->ss->cfts, node)
 | 
							list_for_each_entry(cfts, &css->ss->cfts, node)
 | 
				
			||||||
			cgroup_addrm_files(css, cgrp, cfts, false);
 | 
								cgroup_addrm_files(css, cgrp, cfts, false);
 | 
				
			||||||
| 
						 | 
					@ -1717,14 +1722,22 @@ static int css_populate_dir(struct cgroup_subsys_state *css)
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!css->ss) {
 | 
						if (!css->ss) {
 | 
				
			||||||
		if (cgroup_on_dfl(cgrp))
 | 
							if (cgroup_on_dfl(cgrp)) {
 | 
				
			||||||
			cfts = cgroup_base_files;
 | 
								ret = cgroup_addrm_files(&cgrp->self, cgrp,
 | 
				
			||||||
		else
 | 
											 cgroup_base_files, true);
 | 
				
			||||||
			cfts = cgroup1_base_files;
 | 
								if (ret < 0)
 | 
				
			||||||
 | 
									return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ret = cgroup_addrm_files(&cgrp->self, cgrp, cfts, true);
 | 
								if (cgroup_psi_enabled()) {
 | 
				
			||||||
		if (ret < 0)
 | 
									ret = cgroup_addrm_files(&cgrp->self, cgrp,
 | 
				
			||||||
			return ret;
 | 
												 cgroup_psi_files, true);
 | 
				
			||||||
 | 
									if (ret < 0)
 | 
				
			||||||
 | 
										return ret;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								cgroup_addrm_files(css, cgrp,
 | 
				
			||||||
 | 
										   cgroup1_base_files, true);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		list_for_each_entry(cfts, &css->ss->cfts, node) {
 | 
							list_for_each_entry(cfts, &css->ss->cfts, node) {
 | 
				
			||||||
			ret = cgroup_addrm_files(css, cgrp, cfts, true);
 | 
								ret = cgroup_addrm_files(css, cgrp, cfts, true);
 | 
				
			||||||
| 
						 | 
					@ -4132,8 +4145,6 @@ static int cgroup_addrm_files(struct cgroup_subsys_state *css,
 | 
				
			||||||
restart:
 | 
					restart:
 | 
				
			||||||
	for (cft = cfts; cft != cft_end && cft->name[0] != '\0'; cft++) {
 | 
						for (cft = cfts; cft != cft_end && cft->name[0] != '\0'; cft++) {
 | 
				
			||||||
		/* does cft->flags tell us to skip this file on @cgrp? */
 | 
							/* does cft->flags tell us to skip this file on @cgrp? */
 | 
				
			||||||
		if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		if ((cft->flags & __CFTYPE_ONLY_ON_DFL) && !cgroup_on_dfl(cgrp))
 | 
							if ((cft->flags & __CFTYPE_ONLY_ON_DFL) && !cgroup_on_dfl(cgrp))
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		if ((cft->flags & __CFTYPE_NOT_ON_DFL) && cgroup_on_dfl(cgrp))
 | 
							if ((cft->flags & __CFTYPE_NOT_ON_DFL) && cgroup_on_dfl(cgrp))
 | 
				
			||||||
| 
						 | 
					@ -4218,9 +4229,6 @@ static int cgroup_init_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (cft->seq_start)
 | 
							if (cft->seq_start)
 | 
				
			||||||
			kf_ops = &cgroup_kf_ops;
 | 
								kf_ops = &cgroup_kf_ops;
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
| 
						 | 
					@ -5144,10 +5152,13 @@ static struct cftype cgroup_base_files[] = {
 | 
				
			||||||
		.name = "cpu.stat",
 | 
							.name = "cpu.stat",
 | 
				
			||||||
		.seq_show = cpu_stat_show,
 | 
							.seq_show = cpu_stat_show,
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
						{ }	/* terminate */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct cftype cgroup_psi_files[] = {
 | 
				
			||||||
#ifdef CONFIG_PSI
 | 
					#ifdef CONFIG_PSI
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		.name = "io.pressure",
 | 
							.name = "io.pressure",
 | 
				
			||||||
		.flags = CFTYPE_PRESSURE,
 | 
					 | 
				
			||||||
		.seq_show = cgroup_io_pressure_show,
 | 
							.seq_show = cgroup_io_pressure_show,
 | 
				
			||||||
		.write = cgroup_io_pressure_write,
 | 
							.write = cgroup_io_pressure_write,
 | 
				
			||||||
		.poll = cgroup_pressure_poll,
 | 
							.poll = cgroup_pressure_poll,
 | 
				
			||||||
| 
						 | 
					@ -5155,7 +5166,6 @@ static struct cftype cgroup_base_files[] = {
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		.name = "memory.pressure",
 | 
							.name = "memory.pressure",
 | 
				
			||||||
		.flags = CFTYPE_PRESSURE,
 | 
					 | 
				
			||||||
		.seq_show = cgroup_memory_pressure_show,
 | 
							.seq_show = cgroup_memory_pressure_show,
 | 
				
			||||||
		.write = cgroup_memory_pressure_write,
 | 
							.write = cgroup_memory_pressure_write,
 | 
				
			||||||
		.poll = cgroup_pressure_poll,
 | 
							.poll = cgroup_pressure_poll,
 | 
				
			||||||
| 
						 | 
					@ -5163,7 +5173,6 @@ static struct cftype cgroup_base_files[] = {
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		.name = "cpu.pressure",
 | 
							.name = "cpu.pressure",
 | 
				
			||||||
		.flags = CFTYPE_PRESSURE,
 | 
					 | 
				
			||||||
		.seq_show = cgroup_cpu_pressure_show,
 | 
							.seq_show = cgroup_cpu_pressure_show,
 | 
				
			||||||
		.write = cgroup_cpu_pressure_write,
 | 
							.write = cgroup_cpu_pressure_write,
 | 
				
			||||||
		.poll = cgroup_pressure_poll,
 | 
							.poll = cgroup_pressure_poll,
 | 
				
			||||||
| 
						 | 
					@ -5930,6 +5939,7 @@ int __init cgroup_init(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BUILD_BUG_ON(CGROUP_SUBSYS_COUNT > 16);
 | 
						BUILD_BUG_ON(CGROUP_SUBSYS_COUNT > 16);
 | 
				
			||||||
	BUG_ON(cgroup_init_cftypes(NULL, cgroup_base_files));
 | 
						BUG_ON(cgroup_init_cftypes(NULL, cgroup_base_files));
 | 
				
			||||||
 | 
						BUG_ON(cgroup_init_cftypes(NULL, cgroup_psi_files));
 | 
				
			||||||
	BUG_ON(cgroup_init_cftypes(NULL, cgroup1_base_files));
 | 
						BUG_ON(cgroup_init_cftypes(NULL, cgroup1_base_files));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cgroup_rstat_boot();
 | 
						cgroup_rstat_boot();
 | 
				
			||||||
| 
						 | 
					@ -6821,9 +6831,6 @@ static ssize_t show_delegatable_files(struct cftype *files, char *buf,
 | 
				
			||||||
		if (!(cft->flags & CFTYPE_NS_DELEGATABLE))
 | 
							if (!(cft->flags & CFTYPE_NS_DELEGATABLE))
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((cft->flags & CFTYPE_PRESSURE) && !cgroup_psi_enabled())
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (prefix)
 | 
							if (prefix)
 | 
				
			||||||
			ret += snprintf(buf + ret, size - ret, "%s.", prefix);
 | 
								ret += snprintf(buf + ret, size - ret, "%s.", prefix);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6843,8 +6850,11 @@ static ssize_t delegate_show(struct kobject *kobj, struct kobj_attribute *attr,
 | 
				
			||||||
	int ssid;
 | 
						int ssid;
 | 
				
			||||||
	ssize_t ret = 0;
 | 
						ssize_t ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = show_delegatable_files(cgroup_base_files, buf, PAGE_SIZE - ret,
 | 
						ret = show_delegatable_files(cgroup_base_files, buf + ret,
 | 
				
			||||||
				     NULL);
 | 
									     PAGE_SIZE - ret, NULL);
 | 
				
			||||||
 | 
						if (cgroup_psi_enabled())
 | 
				
			||||||
 | 
							ret += show_delegatable_files(cgroup_psi_files, buf + ret,
 | 
				
			||||||
 | 
										      PAGE_SIZE - ret, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for_each_subsys(ss, ssid)
 | 
						for_each_subsys(ss, ssid)
 | 
				
			||||||
		ret += show_delegatable_files(ss->dfl_cftypes, buf + ret,
 | 
							ret += show_delegatable_files(ss->dfl_cftypes, buf + ret,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue