Cgroup Learning (5) -- create new cgroup

Source: Internet
Author: User

Create new cgroup

This process is mkdir/cgroup/CPU/test_cpu: Create a cgroup in A/cgroup/CPU hierarchy. The following BT creates a cgroup under the CPU hierarchy:

mkdir /cgroup/cpu/test_cpu74447177 8388 (mkdir) call trace: 0xffffffff8105fe80 : cpu_cgroup_create+0x0/0x40[kernel] 0xffffffff810c1021 :cgroup_mkdir+0x161/0x540 [kernel] 0xffffffff811850a7 :vfs_mkdir+0xa7/0x100 [kernel] 0xffffffff8118816e :sys_mkdirat+0xfe/0x120 [kernel] 0xffffffff811881a8 : sys_mkdir+0x18/0x20[kernel] 0xffffffff8100b0f2 :system_call_fastpath+0x16/0x1b [kernel]

In cgroup_mkdir, cgroup_create is called directly (this may be optimized by the compiler). It first creates a cgroup_subsys_state for each subsys to which the cgroup belongs and initializes it:

for_each_subsys(root, ss) {              struct cgroup_subsys_state*css = ss->create(ss, cgrp);              init_cgroup_css(css, ss,cgrp);…}

You can use this cgroup-> subsys [] to obtain all cgroup_subsys_state of the cgroup. You can also use cgroup_subsys_state-> cgroup to know the cgroup to which the cgroup_subsys_state belongs. In the future, the group control bodies of cgroup and subsys will be converted using this structure.
Cpu_cgroup_create will eventually generate a task_group (that is, the Group Control Body Structure of the CPU subsystem) through sched_create_group (inheriting the parent cgroup), which contains the SE, cfs_rq, shares and so on (we will discuss it in detail when introducing the CPU subsystem ).
After cgroup_subsys_state is created, the cgroup_create_dir directory is generated and the Subsystem File cgroup_populate_dir is generated:

74447240 8388 (mkdir) call trace: 0xffffffff81054e60 :cpu_cgroup_populate+0x0/0x30 [kernel] 0xffffffff810c007a :cgroup_populate_dir+0x7a/0x110 [kernel] 0xffffffff810c11fc : cgroup_mkdir+0x33c/0x540[kernel] 0xffffffff811850a7 :vfs_mkdir+0xa7/0x100 [kernel] 0xffffffff8118816e :sys_mkdirat+0xfe/0x120 [kernel] 0xffffffff811881a8 : sys_mkdir+0x18/0x20[kernel] 0xffffffff8100b0f2 :system_call_fastpath+0x16/0x1b [kernel]

When the cgroup directory is created (cgroup_create_dir), The cgroup is saved in dentry-> d_fsdata = MRM, And the directory is associated with the cgroup, when you need to operate the files in this directory, you can obtain the cgroup to which the file belongs. Similarly, when every file is generated (cgroup_add_file) the cftype of the file is saved to dentry-> d_fsdata.
= (Void *) CFT. When operating the file, it will be completed according to the method defined by it.
In short, this process completes the creation of the cgroup structure, including the cgroup_subsys_state of all subsystems to which the cgroup belongs, then corresponding directories and files, and binds these files to the cgroup. The relationship between css_set and the cgroup is not established here, because the cgroup does not attach any process at mkdir, so there is no relationship between css_set and it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.