Cgroup Usage Introduction

Source: Internet
Author: User

First, Cgroup Introduction:

According to official documents, RHEL6 has prepared a new feature for the kernel------resource control, also known as Cgroup. The package for this service is libcgroup. With this, you can allocate resources such as CPU time, system memory, network bandwidth, and so on. This is controlled by the Cgconfig service. If this service is not started, there will be no content in the Cgroup folder in the root directory.


[Email protected]]#/etc/init.d/cgconfig status

[[Email Protected]]#/etc/init.d/cgconfig stop

[[email protected]] #ls/cgroup


After starting this service, there will be some more content under the/cgroup directory:


[Email protected] cgroup]#/etc/init.d/cgconfig restart

Stopping cgconfig service: [OK]

Starting cgconfig service: [OK]

[Email protected] cgroup]# pwd

/cgroup

[[email protected] cgroup]# ls

Blkio CPU CPUACCT cpuset devices Freezer memory net_cls


Second, cgroup the introduction of each module:

Cgroup are similar to processes, they are hierarchical, and each attribute is inherited from the parent process. Cgroup contains multiple orphaned subsystems, and no subsystem represents a single resource. A total of 9 subsystems have been prepared in rhel6, the following is a detailed description of each subsystem:

? Blkio this subsystem setting restricts the input and output control of each block device. For example: disks, CDs, USB, and so on.

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

? CPUACCT generates CPU resource reports for cgroup tasks.

? Cpuset if it is a multi-core CPU, this subsystem allocates a separate CPU and memory for the Cgroup task.

? Devices allows or denies access to the device for the Cgroup task.

? Freezer pause and Resume cgroup tasks.

? Memory sets each cgroup and generates memory resource reports.

? NET_CLS tags each network packet for Cgroup convenience.

? NS namespace subsystem.

There is a certain relationship between the above nine subsystems. See the official documentation for details.


Third, the use of Cgroup:

1, the installation of Cgroup:

When installing the system, the Libcgroup software package is installed by default and can be installed using the following command if it is not installed:

[Email protected]/]# rpm-q Libcgroup

Libcgroup-0.36.1-6.el6.x86_64

If not installed, please install with Yum.

2, the Cgroup service control:

Change it to start with the system's startup:

[Email protected]/]# chkconfig--list cgconfig

Cgconfig 0:off1:off2:off3:off4:off5:off6:off

[Email protected]/]# chkconfig cgconfig on

[Email protected]/]# chkconfig--list cgconfig

Cgconfig 0:off1:off2:on3:on4:on5:on6:off

Stop and start of service

[Email protected] cgroup]#/etc/init.d/cgconfig Stop/start

3, cgroup configuration file cgconfig.conf File Description:

In the cgconfig.conf file, there are two main types: Mount and group. Mount is the hierarchy that creates and mounts which hierarchies are virtual file systems, and attaches subsystems. The contents of the cgconfig.conf file are as follows:

[Email protected]/]# more/etc/cgconfig.conf

#

# Copyright IBM Corporation. 2007

#

# Authors:Balbir Singh

# is the free software; You can redistribute it and/or modify it

# under the terms of version 2.1 of the GNU Lesser general public License

# as published by the Free software Foundation.

#

# This program was distributed in the hope so it would be useful, but

# without any WARRANTY; Without even the implied warranty of

# merchantability or FITNESS for A particular PURPOSE.

#

# See Mans cgconfig.conf for further details.

#

# By default, mount all controllers to/cgroup/


Mount {

Cpuset=/cgroup/cpuset;

CPU=/CGROUP/CPU;

Cpuacct=/cgroup/cpuacct;

Memory=/cgroup/memory;

Devices=/cgroup/devices;

Freezer=/cgroup/freezer

...... Omitted.......

such as cpuset=/cgroup/cputest, can be understood as the following commands

[Email protected]/]# mount-t cgroup-o cpuset cpuset/cgroup/cpuset

Mount:cpuset already mounted Or/cgroup/cpuset busy

[Email protected]/]# UMOUNT/CGROUP/CPU

cpu/cpuacct/cpuset/

[Email protected]/]# Umount/cgroup/cpuset

[Email protected]/]# mount-t cgroup-o cpuset cpuset/cgroup/cpuset

4. Several commands related to Cgroup:

Lssubsys-----shows the subsystems that already exist.

[Email protected]/]# Lssubsys-am

Cpu/cgroup/cpu

Cpuacct/cgroup/cpuacct

Memory/cgroup/memory

Devices/cgroup/devices

Freezer/cgroup/freezer

Net_cls/cgroup/net_cls

Blkio/cgroup/blkio

Cpuset/cgroup/cpuset

Ns

As shown above, except that the NS subsystem is not set in the/etc/cgconfig.conf file, the others are mounted under the corresponding directory.

Lscgroup-----Show All the Cgroup.

[Email protected]/]# Lscgroup

cpu:/

cpuacct:/

memory:/

devices:/

freezer:/

net_cls:/

blkio:/

cpuset:/

5. Mount and unload subsystem hierarchy:

As shown above, each module is mounted with the directory below. The following uninstalls the CPU subsystem hierarchy:

[Email protected]/]# UMOUNT/CGROUP/CPU

[[email protected]/]# Lssubsys-am # (-A for all,-M for display mount point.) )

Cpuacct/cgroup/cpuacct

Memory/cgroup/memory

Devices/cgroup/devices

Freezer/cgroup/freezer

Net_cls/cgroup/net_cls

Blkio/cgroup/blkio

Cpuset/cgroup/cpuset

Ns

Cpu

The other unload and mount are the same. Use the following command to mount it back:

[[email protected]/]# mount-t Cgroup-o CPU CPU/CGROUP/CPU

[Email protected]/]# Lssubsys-am

Cpuacct/cgroup/cpuacct

Memory/cgroup/memory

Devices/cgroup/devices

Freezer/cgroup/freezer

Net_cls/cgroup/net_cls

Blkio/cgroup/blkio

Cpuset/cgroup/cpuset

Cpu/cgroup/cpu

Ns

6. Create a custom Cgroup:

The Cgcreate command is used here, as shown here: Let's look at an example:

[Email protected]/]# cgcreate

Usage is cgcreate-t:-A:-G:


[Email protected]/]# cgcreate-g Cpu,net_cls:/test-subgroup

[Email protected]/]# Lssubsys-am

Cpuacct/cgroup/cpuacct

Memory/cgroup/memory

Devices/cgroup/devices

Freezer/cgroup/freezer

Net_cls/cgroup/net_cls

Blkio/cgroup/blkio

Cpuset/cgroup/cpuset

Cpu/cgroup/cpu

Ns

Did not come out. You see. In fact, after the mount, the use of the Lssubsys command is not visible. Because AH. After the creation, the system can not be mounted, because the mount point does not exist, and so on after the mount point is created, the system will be automatically mounted up.

7. Delete Cgroup

[Email protected]/]# Cgdelete

Usage is Cgdelete [-r]: [...]


Cgroup Usage Introduction

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.