Linux Resource Management-I/O priority, linux-I/O priority
The previous blog introduced the use of cgroup to control the CPU and memory usage of processes. This time, we added the method of using cgroup to control the IO priority of processes.
Prerequisites
To control the I/O priority of a process, Kernel support is required. The following two parameters must be enabled during kernel compilation.
CONFIG_BLK_CGROUP=yCONFIG_CFQ_GROUP_IOSCHED=y
The method for checking whether to enable these two kernel compilation options is simple:
root@debian-113:~# grep -i 'blk_cgroup' /boot/config-`uname -r`root@debian-113:~# grep -i 'cfq_group' /boot/config-`uname -r`
If these two kernel options are not enabled, you can only recompile the kernel and then try the following example.
Run/proc/cgroups again to check whether blkio is enabled.
Root @ debian-113 :~ # Cat/proc/cgroups # subsys_name hierarchy num_cgroups enabledcpuset 0 1 1 CPU 0 1 cpuacct 0 1 1 memory 0 1 1 devices 0 1 freezer 0 1 1net_cls 0 1 1 blkio 0 1 1 <-- enabled = 1, perf_event 0 1 1 is enabled
If blkio is not enabled, you can use grub to set startup parameters.
For more information, see resource control in Linux-CPU and memory.Instance 4-cgroup controls the memory usedEnable memory.
In addition, you have to check whether CFQ can be used as an IO scheduler.
root@debian-113:~# cat /sys/class/block/sda/queue/scheduler noop deadline [cfq]
The above results indicate that cfq scheduling is supported. [] cfq indicates that cfq scheduling is currently used.
If no cfq exists in the cat result, re-compile the kernel to support cfq scheduling.
If the cat result contains cfq, but cfq is not the scheduling program currently in use, that is, [] is not included in cfq, then
Cat cfq/sys/class/block/sda/queue/scheduler <-- set the current IO scheduler to cfq
Note:The above sda is my tested hard disk. If your disk is sdb or other, modify it accordingly.
Instance-control IO priority
Before the experiment, create a test script (a simple example is as follows)
#! /Bin/bash #################################### ################################# 1. create two test files, all of which are 1 GB #2. add the current process to the specified cgroup #3. perform the dd operation #4. delete test file #5. display log ###################################### ############################ function usage () {echo ". /blkio-test.sh <group1> <group2> "exit 1} if [$ #! = 2]; then usagefigroup1_src = ~ /Group1.srcgroup2 _ src = ~ /Group2.srcgroup1 _ log =/tmp/group1.loggroup2 _ log =/tmp/group2.loggroup1 = $1group2 = $2 echo "Generate Test Data $ group1_src and $ group2_src (the size is 1 GB) "dd if =/dev/zero of = $ group1_src count = 1024 bs = 1Mdd if =/dev/zero of = $ group2_src count = 1024 bs = 1 Mecho" at the same time at $ group1 and start dd test in $ group2 "echo 3>/proc/sys/vm/drop_cachesecho $ >>$ group1/tasks (date; dd if = $ group1_src of =/dev/null; date;) >$ group1_log 2> & 1 & echo $ >>$ group 2/tasks (date; dd if = $ group2_src of =/dev/null; date;)> $ group2_log 2> & 1 & waitecho "the test is complete! "Echo" start to clear test file "rm-rf $ group1_src $ group2_srcecho" test file cleanup completed "echo" ------------------------------------ "echo" display group1 log "cat $ group1_logecho" response "echo" display group2 log "cat $ group2_logecho "------------------------------------------"
Start the experiment:
# Mount cgroup file system root @ debian-113 :~ # Mount-t cgroup-o blkio cgroup/mnt/cgroup/root @ debian-113 :~ # Mkdir/mnt/cgroup/{A, B} root @ debian-113 :~ # Ll/mnt/cgroup/total 0drwxr-xr-x 2 root 0 Sep 5 Adrwxr-xr-x 2 root 0 Sep 5 B-r -- 1 root 0 sep 5 blkio. io_merged-r -- r -- 1 root 0 Sep 5 blkio. io_queued-r -- r -- 1 root 0 Sep 5 blkio. io_service_bytes-r -- r -- 1 root 0 Sep 5 blkio. io_serviced-r -- r -- 1 root 0 Sep 5 blkio. io_service_time-r -- r -- 1 root 0 S Ep 5 blkio. io_wait_time -- w ------- 1 root 0 Sep 5 13:23 blkio. reset_stats-r -- r -- 1 root 0 Sep 5 blkio. sectors-r -- 1 root 0 Sep 5 13:23 blkio. time-rw-r -- 1 root 0 Sep 5 13:23 blkio. weight <-- this is the file that sets the IO priority-rw-r -- 1 root 0 Sep 5 blkio. weight_device-rw-r -- r -- 1 root 0 Sep 5 cgroup. clone_children -- w-1 root 0 Sep 5 13:23 c Group. event_control-rw-r -- r -- 1 root 0 Sep 5 cgroup. procs-rw-r -- 1 root 0 Sep 5 notify_on_release-rw-r -- r -- 1 root 0 Sep 5 release_agent-rw-r -- r -- 1 root 0 Sep 5 tasks # default the IO priority of the two groups is 500root @ debian-113: ~ # Cat/mnt/cgroup/A/blkio. weight500 <-- the value range is 100 ~ 1000, the greater the value priority higher root @ debian-113 :~ # Cat/mnt/cgroup/B/blkio. weight500 # The default test results are as follows: A and B both take 20 seconds root @ debian-113 :~ #. /Blkio-test.sh/mnt/cgroup/A/mnt/cgroup/B Generate Test Data/root/group1.src and/root/group2.src (both sizes are 1 GB) 1024 + 0 records in1024 + 0 records outparts 3741824 bytes (1.1 GB) copied, 6.01188 s, 179 MB/s1024 + 0 records in1024 + 0 records outparts 3741824 bytes (1.1 GB) copied, 9.4272 s, 114 Mbit/s at the same time in/mnt/cgroup/A and/mnt/cgroup/B dd test completed! Start to clear the test file. Test File cleanup is complete. logFri Sep of group1 is displayed 5 13:26:31 CST 20142097152 + 0 records in2097152 + 0 records outputted 3741824 bytes (1.1 GB) copied, 20.0504 s, 53.6 MB/sFri Sep 5 13:26:51 CST 2014 records display group2's logFri Sep 5 13:26:31 CST 20142097152 + 0 records in2097152 + 0 records out1073741824 bytes (1.1 GB) copied, 18.8583 s, 56.9 MB/sFri Sep 5 13:26:51 CST 2014 ------------------------------------------ # modify the priority of A to 100, B priority to 1000root @ debian-113 :~ # Echo 100>/mnt/cgroup/A/blkio. weightroot @ debian-113 :~ # Echo 1000>/mnt/cgroup/B/blkio. weightroot @ debian-113 :~ # Cat/mnt/cgroup/A/blkio. weight100root @ debian-113 :~ # Cat/mnt/cgroup/B/blkio. weight1000 # test results with different priorities: A takes 19 seconds; B takes 11 seconds root @ debian-113 :~ #. /Blkio-test.sh/mnt/cgroup/A/mnt/cgroup/B Generate Test Data/root/group1.src and/root/group2.src (both sizes are 1 GB) 1024 + 0 records in1024 + 0 records outparts 3741824 bytes (1.1 GB) copied, 6.52967 s, 164 MB/s1024 + 0 records in1024 + 0 records outparts 3741824 bytes (1.1 GB) copied, 8.01311 s, 134 Mbit/s at the same time in/mnt/cgroup/A and/mnt/cgroup/B dd test completed! Start to clear the test file. Test File cleanup is complete. logFri Sep of group1 is displayed 5 13:30:06 CST 20142097152 + 0 records in2097152 + 0 records outputted 3741824 bytes (1.1 GB) copied, 18.5598 s, 57.9 MB/sFri Sep 5 13:30:25 CST 2014 records display group2's logFri Sep 5 13:30:06 CST 20142097152 + 0 records in2097152 + 0 records out1073741824 bytes (1.1 GB) copied, 10.6127 s, 101 MB/sFri Sep 5 13:30:17 CST 2014 ------------------------------------------
It can be seen that after the IO priority is adjusted, the process in the cgroup with a higher priority can complete IO operations more quickly.
Summary
In fact, in addition to the I/O priority, cgroup can also control other I/O attributes of processes. For details, see the I/O settings file mounted to cgroup.
For more information about the meaning of each file, see cgroup documentation.
In which system is the process with a high priority? In linux, the highest priority is-20, and the lowest priority is 19?
The priority level of the linux system you mentioned is indeed like this. Note that normal users can only ~ 19 to adjust the priority value of the application, only the super user has the right to adjust a higher priority value (from-20 ~ 19 ). The smaller the value, the higher the priority. The larger the value, the lower the priority. Windows is a system with a high priority. Others are not clear
How are linux resources managed? Fast to be detailed
Resource Manager: to ensure proper resources are allocated to jobs, a database must be maintained for cluster resource management. This database records the attributes and status of various resources in the cluster system, all user-submitted requests, and running jobs. The Policy Manager generates a priority list based on the data and the specified scheduling policy. The Resource Manager schedules jobs based on the priority list. The resource manager should also be able to reserve resources. In this way, not only powerful resources can be reserved for required jobs, but also redundant resources can be reserved to cope with node failures and sudden computing in the cluster.
Job Scheduling Policy Manager: Based on the Resource Manager, the policy manager obtains the resource status of each node and the system job information to generate a priority list. This list tells the resource manager when to run the job on which nodes. Policy Manager not only provides a complex set of parameters to define the computing environment and jobs, but also provides a simple and flexible expression for this definition to allow the system administrator to implement policy-driven resource scheduling.
2. Job Management Software in the Beowulf Cluster
There are many options to manage resources in the cluster system. PBS Resource Manager and Maui Job scheduler are most suitable for cluster systems.
2.1 PBS
PBS (Portable Batch System) is a flexible Batch processing System developed by NASA. It is used in Cluster Systems, supercomputers, and large-scale parallel systems. PBS has the following features:
Ease of use: provides unified interfaces for all resources and is easy to configure to meet the needs of different systems. Flexible job schedulers allow different systems to adopt their own scheduling policies.
Portability: complies with POSIX 1003.2 standards and can be used in shell, batch processing, and other environments.
Adaptability: it can adapt to various management policies and provide scalable authentication and security models. Supports Dynamic Distribution of loads on the Wide Area Network and virtual organizations built on multiple physical entities in different locations.
Flexibility: supports interaction and batch processing jobs.
OpenPBS (www.OpenPBS.org/) is the implementation of Open Source of PBS. For commercial PBS, see www.pbspro.com /.
2.2 Maui
Maui is an advanced Job scheduler. It uses active scheduling policies to optimize resource utilization and reduce job response time. Maui's resource and load management allows advanced parameter configurations: Job Priority, Scheduling and Allocation, Fairness and fair share) and Reservation Policy ). Maui's QoS mechanism allows direct transfer of resources and services, Policy Exemption, and restricted access to specified features. Maui uses an advanced Resource Reservation architecture to precisely control when, where, WHO, and how resources are used. The reserved Maui architecture fully supports non-intrusive metadata scheduling.
Maui is designed thanks to the experience of the world's largest high-performance computing center. Maui itself also provides test tools and Simulators for estimating and tuning system performance.
Maui needs the resource manager to work with it. We can think of Maui as an insert part in PBS.
For more Maui information, visit www.supercluster.org.
3. Cluster System Management
From the perspective of system composition, the cluster system is... the remaining full text>