Cgroup Learning (1) -- What cgroup?

Source: Internet
Author: User

This series of articles will introduce the concept of cgroup, The cgroup framework, and the subsystem of cgroup.

 

What cgroup?

Control groups provide a mechanic foraggregating/partitioning sets of tasks, and all their future children, define hierarchical groups with specialized behaviour. -- Adjust
Of tasks are managed and act on their children, that is, they are a hierarchical relationship, and their behavior is consistent in a hierarchical. So what functions does cgroup provide? Let's briefly describe it through figure 1.


Figure 1

From figure 1, we can see that the cgroup supports CPU set, NS, CPU, cpuacct, memory, and other subsystems. Hierarchy represents hierarchy ID, and we can also see cpuset, CPU, memory, blkio is mounted to the same hierarchy 14. Next we will briefly introduce the role of subsystems:
Cpuset: Specifies the CPU and memory nodes used by tasks, which is equivalent to sched_setaffinity and set_mempolicy;
NS: namespace service;
CPU: used to set the CPU usage of tasks;
Cpuacct: used to record CPU statistics;
Memory: used to set the memory usage of tasks;
Devices: used to set the use of devices by tasks (whitelist, read, write, mknod );
Freezer: Used to suspend or resume tasks;
Net_cls: uses the classid to mark network packets and allows Linux traffic control (TC) to identify packets generated from a specific cgroup;
Blkio: Controls and monitors tasks's access to block devices;
Note: For more detailed explanation, see: https://access.redhat.com/knowledge/docs/zh-CN/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/index.html

 

Simple use and precautions

You can view the cgroup subsystem supported by the system through/proc/cgroups (or you can determine whether the system supports cgroup). If the hierarchy item is not 0, the corresponding subsystem has been mounted, in this case, if you mount this subsystem to another directory, a busy error may occur ). Then mount the required cgroup subsystem to the/cgroup directory:① Mount
-T cgroup-o cpu, cpuset, memory, blkio agent_cgroup/cgroup
This process also creates a hierarchy. If the prompt is: Mount: Agent already mounted or/cgroup busy, you can query the directory to which the corresponding sub-system is mounted by using lssubsys-M memory, check whether the original subsys umount needs to be deleted from the bottom layer in sequence before umount, and then umount can ensure the success of umount, otherwise, if the umount directory does not exist, but umount is not successful, you can see that its hierarchy item is not 0 through/proc/cgroup, in this case, you need to mount this subsystem to a directory, and then delete the directories without rmdir first, and then umount ).
Create a cgroup. Under the mounted directory, create the directory:② Mkdir/cgroup/cg_test, That is, a cgroup is created (the operation corresponding to this operation is rmdir. Only the tasks in the cgroup can be removed after they are moved to the top group ), now we can see that there are already many files in the new directory.
Then modify the corresponding pseudo file content:Echo 512>/cgroup/cg_test/CPU. SharesTo complete the cgroup configuration.
Finally, add the task to the cgroup:④ Echo pid>/cgroup/cg_test/CPU. TasksOr cgexec (Note: If you want to remove a task from a group, you only need to put it into the root tasksecho pid>/cgroup/tasks ).
This is simple, but the above operations require the root permission, and the kernel has not yet provided the corresponding API interface, only this file read/write method, or the corresponding tool to achieve. These four processes are all the content of the cgroup.

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.