In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about what Cgroup is in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
There is often a requirement in Linux systems to limit the allocation of resources for one or more processes. That is, you can complete the concept of a set of containers in which there is a specific proportion of cpu time, IO time, available memory, and so on. Then came the concept of cgroup, and cgroup is controller group, which was first proposed by google engineers and later integrated into the Linux kernel.
Cgroup is a Linux kernel function that manages arbitrary processes in packets. Cgroup itself provides the infrastructure for packetized management of processes and interfaces.
Then the Android operating system relies on this technology to assign a different cgroup to each application and isolate each program to achieve the goal that one application will not affect the environment of other applications.
Cgroups subsystem cpu subsystem, which mainly limits the cpu utilization of the process. The cpuacct subsystem, which can count cpu usage reports for processes in cgroups. The cpuset subsystem, which can assign separate cpu nodes or memory nodes to processes in cgroups. The memory subsystem, which limits the amount of memory used by the process. The blkio subsystem, which can restrict the block device io of the process. The devices subsystem, which can control the process to access certain devices. The net_cls subsystem, which can mark the network packets of the processes in cgroups, and then use the tc module (traffic control) to control the packets. Net_prio-this subsystem is used to design the priority freezer subsystem of network traffic and can suspend or resume processes in cgroups. The ns subsystem, which enables processes under different cgroups to use different namespacehugetlb-this subsystem is primarily designed to restrict the HugeTLB system, which is a large-page file system. Cgroups hierarchy (Hierarchy)
The kernel uses cgroup structures to represent the resource limits of a control group to one or more cgroups subsystems. The cgroup structure can be organized into a tree, and the tree composed of each cgroup structure is called a cgroups hierarchical structure.
The cgroups hierarchy can attach one or more cgroups subsystems, and the current hierarchy can restrict the resources of the cgroups subsystem of its attach. Each cgroups subsystem can only be attach into one cpu hierarchy.
Just take a good look at this picture:
After creating a node in the cgroups hierarchy (cgroup structure), processes can be added to a node's control task list, and all processes in a node's control list are limited by the resources of the current node. At the same time, a process can also be added to nodes of different cgroups hierarchies, because different cgroups hierarchies can be responsible for different system resources. So there is a many-to-many relationship between processes and cgroup structures.
The figure above depicts the overall structure of the relationship between the process and the cgroups. The bottom P represents a process. Each process descriptor has a pointer to an auxiliary data structure, css_set (cgroups subsystem set). Processes pointing to a css_set are added to the process list of the current css_set. A process can only belong to one css_set, a css_set can contain multiple processes, and processes belonging to the same css_set are limited by the resources associated with the same css_set.
The "M × N Linkage" in the figure above shows that css_set can associate many-to-many with cgroups nodes through auxiliary data structures. But the implementation of cgroups does not allow css_set to associate multiple nodes under the same cgroups hierarchy at the same time. This is because cgroups does not allow multiple restricted configurations for the same resource.
When a css_set is associated with multiple cgroups hierarchical nodes, it indicates the need for multiple resource control over the processes under the current css_set. When a cgroups node associates multiple css_set, it indicates that the process list under multiple css_set is subject to the same limitation of the same resource.
Practical operation
View the cgroup mount point (centos7.5):
1 [root@k8s-master ~] # mount-t cgroup 2 cgroup on / sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd) 3 cgroup on / sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids) 4 cgroup on / sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) 5 cgroup on / sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec Relatime,memory) 6 cgroup on / sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu) 7 cgroup on / sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) 8 cgroup on / sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) 9 cgroup on / sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb) 10 cgroup on / sys/fs/cgroup/perf_event type cgroup (rw,nosuid Nodev,noexec,relatime,perf_event) 11 cgroup on / sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) 12 cgroup on / sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
Create an isolation group
[root@k8s-master ~] # cd / sys/fs/cgroup/cpu
[root@k8s-master cpu] # mkdir cpu_test
The following file [root@k8s-master cpu] # ls cpu_test/ is automatically generated when the directory is created.
Write an endless loop test program to increase cpu utilization
1 int main (void) 2 {3 int I = 0; 4 for (;;) iTunes; 5 return 0; 6}
Cpu uses 100% after starting the program
Default-1 is not limited, and now it is changed to 20000. It is understandable that the usage rate is limited to 20%.
[root@k8s-master cpu] # echo 20000 > / sys/fs/cgroup/cpu/cpu_test/cpu.cfs_quota_us
Find the process number and add it to the cpu tasks. The top cpu usage will come down soon.
[root@k8s-master ~] # echo 23732 > > / sys/fs/cgroup/cpu/cpu_test/tasks
Other resource restrictions are basically the same as cpu. So much for writing first.
Thank you for reading! This is the end of this article on "what is Cgroup in Linux?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.