In the first use
case we will see how we can manage the I/O Operations on the Disk devices. This
is done by the blkio sub system available in the CGroups. The blkio sub system
moderates I/O operations to the specified block devices. In this example we will see how we can
restrict the read operations performed on a drive
For this we use the
“blkio.throttle.read_bps_device”
parameter which specifies a upper limit on the number of read operations a
device can perform. The rate of the read operations are specifired in bytes per
second. The values for this accepts major, minor, and bytes_per_second.
Major& Minor - device types and node
numbers specified in Linux
Bytes_per_second is the upper limit rate at which read operations
can be performed.
Now lets block the
read Operations on the device /dev/sda to 10MB. For this we need to first find
the major and minor values for the device. These can be found by using the
[root@vx111a dev]#
ls -l sd*
brw-rw---- 1 root disk 8, 0 Mar 15 14:24 sda
brw-rw---- 1 root disk 8, 1 Mar 15 14:24 sda1
brw-rw---- 1 root disk 8, 2 Mar 15 14:24 sda2
brw-rw---- 1 root disk 8, 3 Mar 15 14:24 sda3
brw-rw---- 1 root disk 8, 4 Mar 15 14:24 sda4
brw-rw---- 1 root disk 8, 5 Mar 15 14:24 sda5
brw-rw---- 1 root disk 8, 6 Mar 15 14:24 sda6
[Note: Major for /dev/sda1 is 8 and minor is 1]
brw-rw---- 1 root disk 8, 0 Mar 15 14:24 sda
brw-rw---- 1 root disk 8, 1 Mar 15 14:24 sda1
brw-rw---- 1 root disk 8, 2 Mar 15 14:24 sda2
brw-rw---- 1 root disk 8, 3 Mar 15 14:24 sda3
brw-rw---- 1 root disk 8, 4 Mar 15 14:24 sda4
brw-rw---- 1 root disk 8, 5 Mar 15 14:24 sda5
brw-rw---- 1 root disk 8, 6 Mar 15 14:24 sda6
[Note: Major for /dev/sda1 is 8 and minor is 1]
OR
[root@vx111a ~]# cat /proc/partitions | grep sda
8 0 488386584 sda
8 1 81920000 sda1
8 2 51200000 sda2
8 3 51200000 sda3
8 4 1 sda4
8 5 10240000 sda5
8 6 10240000 sda6
8 1 81920000 sda1
8 2 51200000 sda2
8 3 51200000 sda3
8 4 1 sda4
8 5 10240000 sda5
8 6 10240000 sda6
In this case for
/sda, we have the major number as 8 and minor number as 0. Lets run the hdparm
command first with out the cgroups and see what is the disk read rate for the drive /dev/sda.
NOTE
- Hdparm is the tool to use when it comes to tuning your hard disk or DVD
drive, but it can also measure read speed, deliver valuable information about
the device, change important drive settings, and even erase SSDs securely
[root@vx111a ~]#
hdparm --direct -t /dev/sda
/dev/sda:
Timing O_DIRECT disk reads: 368 MB in 3.00 seconds = 122.42 MB/sec
/dev/sda:
Timing O_DIRECT disk reads: 368 MB in 3.00 seconds = 122.42 MB/sec
We can see that
disk read rate is 122MB per second. Now we want to restrict the value to 10MB.
Now create a group
in the /etc/cgconfig.conf file as
group limitIO{
blkio {
blkio.throttle.read_bps_device = "8:0 1048576";
}
}
blkio {
blkio.throttle.read_bps_device = "8:0 1048576";
}
}
We have defined a
limitIO group with taking the blkio subsystem. Now lets configure the cgrules.conf files by
adding the below line to the end of the file,
*:hdparm blkio limitIO/
This tells that operations
performed by hdparm command needs to be added to blkio sub sytem and limited by
the group limitIO.
Now restart both
the services and run the lssubsys command to check the configuration,
[root@vx111a /]#lssubsys
cpuset:/
perf_event:/
hugetlb:/
blkio:/
blkio:/limitIO
memory:/
memory:/testOOM
net_cls:/
perf_event:/
hugetlb:/
blkio:/
blkio:/limitIO
memory:/
memory:/testOOM
net_cls:/
We can see the
limitIO group is associated with the blkio subsystem.Once the serices are
restarted run the hdparm again and see the values.
Testing
Now test the cgroup
using the hdparm command as,
[root@vx111a ~]#
hdparm --direct -t /dev/sda
/dev/sda:
Timing O_DIRECT disk reads: 4 MB in 4.00 seconds = 1023.38 kB/sec
/dev/sda:
Timing O_DIRECT disk reads: 4 MB in 4.00 seconds = 1023.38 kB/sec
We can see that the
value is limited to 1MB which is under 10MB.
More to Come, Happy
learning J
No comments :
Post a Comment