"Reprint" Linux Cgroup Resource isolation Conquer-CPU Isolation 1

Source: Internet
Author: User
Tags cpu usage

Linux Cgroup has two subsystems that support CPU isolation.
One is the CPU subsystem and the other is the Cpuset subsystem.

The CPU subsystem chooses the corresponding CPU resource scheduling method according to the scheduling properties of the process set.

principle see
https://www.kernel.org/doc/documentation/scheduler/sched-design-cfs.txt
CFS is used to handle several process scheduling policies
sched_batch
sched_idle

.2. Real-Time scheduling real-time scheduler (RT)
Principle See
Https://www.kernel.org/doc/Documentation/scheduler/sched-rt-group.txt
RT is used to handle several process scheduling strategies
Sched_fifo
Sched_rr

CFS scheduling Method

The CFS Scheduler is for Sched_other, Sched_batch, Sched_idle processes for properties.
The restriction means is divided into two aspects,
.1. Limit the CPU usage of the resource group to a hard limit,
.2. And the CPU usage weight of the resource group.
Tasks within the CFS dispatch resource group use CPU resources for extra weight when the CPU is idle, but cannot exceed the hard limit.
Example

groupA : cpu.shares=250  groupB : cpu.shares=750  

CFS guarantees that the GROUPA process can use 25% of the CPU resources, and the GROUPB process can use 75% of the CPU resources.
If the CPU is idle, the Groupa process can use more than 25% of the CPU resources.
If a groupc comes in again, and Cpu.shares = 250 is configured, the CPU resources will be redistributed between the three group.

  25:75:25

Note Cpu.shares must >= 2

Cpu.shares only limits the use limit, if you also need to set the CPU usage limit, can be set by the following two parameters.

cpu.cfs_period_us = 统计CPU使用时间的周期  cpu.cfs_quota_us = 周期内允许占用的CPU时间(指单核的时间, 多核则需要在设置时累加)  

If a task in a group uses more CPU time within a cycle cpu.cfs_period_us than Cpu.cfs_quota_us, it goes into a suppressed state and needs to wait for the next cycle to continue using the CPU.

example, the period is 1 seconds, allowing the use of 4 seconds of CPU time. (assuming the cpu>=4 core, this group can run up to 4 cores within a lifetime (1s))

cpu.cfs_period_us = 1000000cpu.cfs_quota_us = 4000000 
RT (Real-time) scheduling method

The RT schedule is for the SCHED_FIFO, SCHED_RR process for properties.
Similar to the quota and period of CFS, limits the upper limit on CPU usage. However, RT scheduling only restricts the CPU usage of real-time tasks.

 Th E RT Scheduler Works in a similar it to the ceiling enforcement control of the CFS (for more information, refer to sections 3.2.1, "CFS tunable Parameters") but limits CPU access to real-time tasks only.        

Cpu.rt_period_us = Count the period of CPU usage time
Cpu.rt_runtime_us = time during which a task is allowed to use a single CPU core, if there are multiple cores in the system, the time of the kernel multiplier can be used (the calculation method is not the same as the CFS, need attention)
Example

As mentioned above,The Access Times is multipliedByTheNumberof logical CPUs. For example, setting Cpu.rt_runtime_usTo200000and Cpu.rt_period_usTo1000000 translatesToThe task being ableTo accessA single CPUFor0.4Seconds outof every 1 second on systems with two cpus (0.2 Span class= "Hljs-title" >x 2), or  0.8 seconds on systems with four CPUs ( Span class= "Hljs-title" >0.2 x 4).   
Grouping Statistics Information

Since there is the concept of suppressed state and CPU time slices, there is a corresponding statistic
It is used to report the CPU scheduling period, the number of times, and the duration of the suppression in the packet. (Note that its statistics do not include sub-groupings, another CPUACCT subsystem statistics contain sub-groupings, another document will talk about)

Cpu.statreports CPUTime statisticsUsingThe following values: How many fragments have been in the past nr_periods-Numberof period intervals (As specifiedin Cpu.cfs_period_us) that has elapsed. How many times are suppressed nr_throttled- number of times Tasks in a Cgroup has been throttled (that is, not allowed to run because they has exhausted all of the Available time as specified by Their quota). How long did all the tasks add up Throttled_time-the total in nanoseconds) for which tasks in a Cgroup have been throttled.       

From the suppression time of statistics and the number of suppression times, you can determine whether you need to increase the CPU limit for the packet.

Example

.1.
Limit group Cgroupa Tasks can use up to 8 kernel resources
Limit group CGROUPB Tasks can use up to 16 kernel resources

Load CPU subsystem, create sub-resource partition

mkdir -p /cgroup/cpumount -t cgroup -o cpu cpu /cgroup/cpucd /cgroup/cpumkdir cgroupAmkdir cgroupB

Configure resource ratios (base 100, number of cores multiplied by 100 to get Cpu.shares)

800 > cpu.sharesecho 1000000 > cpu.cfs_period_usecho 8000000 > cpu.cfs_quota_uscd ../cgroupBecho 1600 > cpu.sharesecho 1000000 > cpu.cfs_period_usecho 16000000 > cpu.cfs_quota_us

Running tasks

start -D /home/digoal/pgdata1921cgexec -g cpu:cgroupB pg_ctl start -D /home/digoal/pgdata1922
Summary

.1. Minimum limit
Cpu.shares
.2. Limit limit
Cpu.cfs_period_us
Cpu.cfs_quota_us
.3. Limited real-time task limit
Cpu.rt_period_us
Cpu.rt_runtime_us

CPUACCT Subsystem

The CPUACCT subsystem is a subsystem used to count CPU usage, which is not an isolated resource, but a statistical resource usage.
The statistics for the CPUACCT subsystem contain sub-partitions.

"Reprint" Linux Cgroup Resource isolation Conquer-CPU Isolation 1

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.