Use of KVM Cgroup

Source: Internet
Author: User

Reference:

Http://www.ibm.com/developerworks/cn/linux/1506_cgroup/index.html

Http://baike.baidu.com/link?url=o3EDZZKaX9NJx8G1KvBgAj_Cnh9Z9yZXvcSaiIAVrkZ6je5VmVrab9QbEUq50XBSTOpYpc0opyeuUEw0dE5U9q

"KVM Virtualization Technology Practical and Principle analysis"

Brief introduction:

In KVM we can assign resources to clients using parameters such as-M-SMP, but this allocation is a coarse-grained resource allocation, assuming a scenario where two clients on the local disk provide MySQL services, but one of them is more secure to the data and needs to be written to disk in a timely manner.  The other one is not high on data security, it doesn't matter if it's slower, and I/O requests are equivalent. At this point, if we still simply assign the device to the client as we did in the previous method, the I/O speed of the two clients is quite the same, and it does not reach our goal. Cgroup is useful at this time.


The concept of Cgroup:

Task: A process running in the system, a process that is a member of one or more control groups

Control group: A control group is a set of tasks according to a certain standard, each task in the control group is limited by the resources of this control group

Hierarchical System (Hierarchy): For short, control groups can be organized into hierarchical forms, both of which control the group tree. Control the child nodes of the population tree The group is the child of the parent control group, inheriting the specific attribute subsystem (subsystem) of the parent control group. A subsystem is a resource controller, such as a CPU subsystem is a controller that controls CPU time allocation. Subsystems must be attached (attach) to one level to function, and when a subsystem is attached to a hierarchy, all control groups at that level are controlled by this subsystem.

From the book "KVM Virtualization Technology Combat and Principle analysis":

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8B/D3/wKiom1hZ-E6jDEZsAALSqvDcOeg334.png "title=" h21g%@ 8UM53] ' y_hwyn4} ' 2.png "alt=" Wkiom1hz-e6jdezsaalsqvdcoeg334.png "/>

In short, Cgroup is similar to the operation of a service company, a company (system resources) is divided into different departments (tiers), each department provides different services (subsystems), each customer (Task) can enjoy different levels of service (Cgroup), so that their relationship is good understanding:

(Excerpt from http://www.ibm.com/developerworks/cn/linux/1506_cgroup/index.html below)

     (1) each time a new level is created in the system, all tasks in that system are the default cgroup for that level (we call it root cgroup, which is created automatically when the hierarchy is created, and the Cgroup The Cgroup created later in the hierarchy are the initial members of this cgroup,          //Each customer can enjoy a basic service level

     (2) A subsystem can be attached to a maximum of one level;          //a service that is only available in a department , such as technical services, you can only find technical department.

     (3) One level can attach multiple subsystems;          / /A department can provide multiple services, such as the technical Department of Programmers also provide daily abused dog performance ~ ~

     (4) a task can be a member of multiple cgroup, but these cgroup must be at different levels;          //You can have both beauty front desk and programmer to write code, but you can not at the same time to two beautiful receptionist reception you, otherwise the programmer will not let you ~ ~

(5) When a process (task) in the system creates a child process (Task), the subtask automatically becomes a member of the Cgroup whose parent process is located.        The subtask can then be moved to a different cgroup as needed, but at first it always inherits the Cgroup of its parent task. //The customer's membership card can be used for his son, of course, his son can find a more beautiful front desk service ~ ~


Available Subsystems (Excerpt from: http://baike.baidu.com/link?url=o3EDZZKaX9NJx8G1KvBgAj_ CNH9Z9YZXVCSAIIAVRKZ6JE5VMVRAB9QBEUQ50XBSTOPYPC0OPYEUUEW0DE5U9Q)

Blkio-This subsystem sets input/output limits for block devices, such as physical devices (disk, SSD, USB, and so on).

CPU-this subsystem uses the scheduler to provide Cgroup task access to the CPU.

CPUACCT-This subsystem automatically generates the CPU reports used by the tasks in the Cgroup.

Cpuset-this subsystem allocates independent CPUs (on multicore systems) and memory nodes for tasks in Cgroup.

Devices-this subsystem allows or denies tasks in the Cgroup to access the device.

Freezer-This subsystem hangs or resumes tasks in the Cgroup.

Memory--This subsystem sets the limits for the use of tasks in Cgroup and automatically generates a report of memory resources used by those tasks.

NET_CLS-this subsystem uses the level identifier (CLASSID) to mark network packets, allowing the Linux Traffic Control Program (TC) to identify the packets generated from the specific cgroup.

NS--namespace subsystem.

Perf_event--This subsystem is mainly used for performance monitoring, sampling and analysis of the operation in the system.

You can use Lssubsys-am in Linux to view system-supported subsystems


Operation of Cgroup:

1. View kernel support:

cat/boot/config-2.6.32-431.el6.x86_64 |grep-i Cgroup

2. Create Cgroup and attach tasks

Mkdir-p/cgroup/blkio

Mount-t cgroup-o Blkio Blkio/cgroup/blkio #-o Blkio represents Blkio this subsystem, the second Blkio represents the hierarchy name, this level is mounted on the/cgroup/blkio

(mount-t cgroup-o cpu,cpuset,memory cpu_mem/cgroup/cpu_mem) #类似这条就是把cpu, cpuset,memory These three subsystems are attached to the cpu_mem at this level, mount the target Recorded as/cgroup/cpu_mem

Mkdir/cgroup/blkio/high_prio #创建高等级的控制群组

Mkdir/cgroup/blkio/low_prio #创建低等级的群组

echo 1000>/cgroup/blkio/high_prio/blkio.weight #设置控制群组的权重 with a value of 100-1000, the higher the priority, the greater the

Echo 100>/cgroup/blkio/low_prio/blkio.weight

PS aux #找到你想要控制的进程的id号

echo "$pid" >/cgroup/blkio/high_prio/tasks #把进程加入到控制群组, or you can view/cgroup/blkio/tasks, All of the default processes are added to this root cgroup

You can also use tools such as the cgcreate provided by Libcgroup to manage Cgroup, which provides a service:/etc/init.d/cgconfig its configuration file is/etc/ Cgconfig.conf, you can modify this configuration file to manage Cgroup, but the essence is the same as this article.


This article is from the "single Season rice" blog, please be sure to keep this source http://linzb.blog.51cto.com/5192423/1884658

Use of KVM 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.