Libvirt, the underlying technology Docker introduction of -CGroups

CGroups Profile

Control Groups CGroup is an abbreviation, a Linux kernel may provide limited recording mechanism physical resources (e.g., cpu memory i / o, etc.) of the isolation process group (process groups) is used, this mechanism according to the needs the series of system integration tasks and subtasks (or separated) into different groups according to the division level of resources, so as to provide a unified framework for system resource management. Libvirt created virtual machine divided into Cgroups resource area, enabling all virtual machines, some virtual machines, resource control single virtual machine, such as a disk IO bandwidth control virtual machines. Container also use CGroups to limit cpu, io, memory, network and other resources.

CGroups of four functions

Resource limitations: cgroups that the tasks can be total resources to the limit. For example, set the upper limit of memory used by the task runs, once beyond to send OOM.
Priority assignment: the CPU time slice number and disk IO bandwidth allocation, in fact, tantamount to control the priority task to run.
Statistical Resources: Resource usage can cgoups statistical systems, such as the use of long CPU, memory usage and so on. This feature is ideal for current products by way of the use of cloud billing.
Mission Control: cgroups can perform tasks suspended recovery operations.

CGroups of four key concepts

任务(task)。在 Cgroups 中,任务就是系统的一个进程或线程,在 linux 系统中,内核本身的调度和管理并不对进程和线程进行区分,只是根据 clone 时传入的参数的不同来从概念上区分进程和线程;
控制组(Cgroup)。Cgroups 中的资源控制都是以Cgroup为单位实现。一个进程可以加入到某个Cgroup,也从一个进程组迁移到另一个Cgroup。一个Cgroup的进程可以使用 CGroups 以Cgroup为单位分配的资源,同时受到 CGroups 以 Cgroup 为单位设定的限制;
层级(hierarchy)。层级有一系列 cgroup 以一个树状结构排列而成,每个层级通过绑定对应的子系统进行资源控制。层级中的 cgroup 节点可以包含零个或多个子节点,子节点继承父节点挂载的子系统。一个操作系统中可以有多个层级
子系统(subsystem)。一个子系统就是一个资源控制器,比如 cpu 子系统就是控制 cpu 时间分配的一个控制器,内存子系统可以限制内存的使用量。子系统必须附加(attach)到一个层级上才能起作用,一个子系统附加到某个层级以后,这个层级上的所有控制族群都受到这个子系统的控制。

The difference CGroups and CGroup

CGroups:cgroups是Linux内核中的一个机制,我们用它来作容器资源的限制等功能。
CGroup:cgroup中文叫做控制组。它是cgroups实现资源控制的一个基本单位。cgroup表示按某种资源控制标准划分而成的一个任务组。它其中包含有一个或多个任务。

The relationship between the four key concepts

每次在系统中创建新层级时,该系统中的所有任务都是那个层级的默认 cgroup(我们称之为  root cgroup,此 cgroup 在创建层级时自动创建,后面在该层级中创建的 cgroup 都是此 cgroup 的后代)的初始成员
一个子系统最多只能附加到一个层级;
一个层级可以附加多个子系统;
一个任务可以是多个 cgroup 的成员,但是这些 cgroup 必须在不同的层级;
系统中的进程(任务)创建子进程(任务)时,该子任务自动成为其父进程所在 cgroup 的成员。然后可根据需要将该子任务移动到不同的 cgroup 中,但开始时它总是继承其父任务的 cgroup。

FIG exemplary hierarchy CGroups
Libvirt, the underlying technology Docker introduction of -CGroups

As shown in FIG CGroup hierarchy display, CPU, and Memory subsystem has its own independent two-level system, but made by association Task Group.

Cgroups subsystem description

cpuset   这个子系统为 cgroup 中的任务分配独立 CPU(在多核系统)和内存节点。
cpu      这个子系统使用调度程序提供对 CPU 的 cgroup 任务访问。
cpuacct  这个子系统自动生成 cgroup 中任务所使用的 CPU 报告。
blkio    这个子系统为块设备设定I/O访问控制,比如物理设备(磁盘,固态硬盘,USB 等等)。
memory   这个子系统设定 cgroup 中任务使用的内存限制,并自动生成由那些任务使用的内存资源报告。
devices  这个子系统可允许或者拒绝 cgroup 中的任务访问设备。
freezer  这个子系统挂起或者恢复 cgroup 中的任务。
net_cls  这个子系统使用等级识别符(classid)标记网络数据包,这让linux流量控制器(tc)可以识别来自特定cgroup任务的数据包,并进行网络限制。
perf_event:这个子系统可以使cgroup中的任务进行统一的性能测试。

You can view the current kernel supports the / proc / cgroups subsystem
Libvirt, the underlying technology Docker introduction of -CGroups

CGroups Typical Application Architecture

Libvirt, the underlying technology Docker introduction of -CGroups

As shown in FIG, Cgroups techniques may be used to limit the physical resources in the underlying operating system functions Container. Each figure corresponds to a Container Cgroup JVM process level, various subsystems provided by CGroup can be physical limitations for each JVM thread level corresponding process, these limitations including CPU, memory, and so many kinds of resources.
CGroups relevant documents

CGroups the way the document provides an application interface, we can see the mount point cgroups the mount command:
Libvirt, the underlying technology Docker introduction of -CGroups

View the next cgroups subsystem:
Libvirt, the underlying technology Docker introduction of -CGroups

Check under the control group under the cpu subsystem:
Libvirt, the underlying technology Docker introduction of -CGroups

Figure directories machine, system.slice, user.slice is now existing control group.

This first-stage on the next issue we continue to learn the application CGroups on Libvirt.
Libvirt, the underlying technology Docker introduction of -CGroups

Rui Jiang cloud computing official website link: https://www.eflycloud.com/home?from=RJ_0027

Guess you like

Origin blog.51cto.com/13475644/2414073