Skip to content

Instantly share code, notes, and snippets.

@anfernee
Created May 11, 2020 05:26
Show Gist options
  • Save anfernee/80d289139e9e8a7fea4a659767e4265c to your computer and use it in GitHub Desktop.
Save anfernee/80d289139e9e8a7fea4a659767e4265c to your computer and use it in GitHub Desktop.

All subsystem defined in: https://elixir.bootlin.com/linux/v4.20/source/include/linux/cgroup_subsys.h

Implementation defined in (e.g. cpuset): https://elixir.bootlin.com/linux/v4.20/source/kernel/cgroup/cpuset.c

Freezer is a very simple example (only has 3 files) https://elixir.bootlin.com/linux/v4.20/source/kernel/cgroup/freezer.c

struct cgroup_subsys cpuset_cgrp_subsys = {
	.css_alloc	= cpuset_css_alloc,
	.css_online	= cpuset_css_online,
	.css_offline	= cpuset_css_offline,
	.css_free	= cpuset_css_free,
	.can_attach	= cpuset_can_attach,
	.cancel_attach	= cpuset_cancel_attach,
	.attach		= cpuset_attach,
	.post_attach	= cpuset_post_attach,
	.bind		= cpuset_bind,
	.fork		= cpuset_fork,
	.legacy_cftypes	= files,  // files under the folder
	.early_init	= true,
};


static struct cftype files[] = {
	{
		.name = "cpus",
		.seq_show = cpuset_common_seq_show,
		.write = cpuset_write_resmask,
		.max_write_len = (100U + 6 * NR_CPUS),
		.private = FILE_CPULIST,
	},

	{
		.name = "mems",
		.seq_show = cpuset_common_seq_show,
		.write = cpuset_write_resmask,    // common handler for cpus/mems
		.max_write_len = (100U + 6 * MAX_NUMNODES),
		.private = FILE_MEMLIST,
	},
  // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment