The blk-iocost weight-based throttling feature is an Alibaba Cloud Linux improvement of the weight-based disk throttling feature of the cgroup I/O subsystem (blkcg). blk-iocost is an I/O controller that is used to allocate bandwidth to I/O operations on block devices based on the priorities of applications or processes. blk-iocost can also control the usage of the block device I/O bandwidth by specific applications or processes based on specified weight values. blk-iocost helps you better control and manage disk I/O resources.
cgroup v1 and cgroup v2 are two versions of the resource management feature in the Linux kernel. In the Alibaba Cloud Linux kernel, the blk-iocost feature supports both cgroup v1 and v2 interfaces. In most cases, only one version is activated and used in a system. You can run the stat -fc %T /sys/fs/cgroup command to check.
If
tmpfsis returned, the cgroup v1 interface is used.If
cgroup2fsis returned, the cgroup v2 interface is used.
Limits on operating systems
Alibaba Cloud Linux 2 with kernel version
4.19.81-17or laterAlibaba Cloud Linux 3
Usage notes for the cost.qos interface
cost.qos is a read/write interface used to enable or disable the blk-iocost feature and limit the I/O quality of service (QoS) rate based on latency weight. The interface file exists only in the root group of blkcg, and its full name varies based on the cgroup version.
cgroup v1:
blkio.cost.qoscgroup v2:
io.cost.qos
Configuration
Each line in the configuration file starts with the major (MAJ) and minor (MIN) numbers of a disk in the MAJ:MIN format, followed by the parameters in the following table. To query the MAJ and MIN numbers of a disk, run the lsblk | grep <disk name> command.
Parameter | Description |
enable | Specifies whether to enable the blk-iocost feature.
|
ctrl | The control mode. Valid values:
|
Enable the blk-iocost feature
Enable the blk-iocost feature for a disk. In this example, the 254:48 disk is used, and the control mode is set to user. If more than 95% of read and write requests have a latency (rlat|wlat) longer than 5 milliseconds, the disk is considered saturated. The kernel adjusts the rate at which requests are sent to the disk within the range of 50% to 150%.
cgroup v1 interface
sudo sh -c 'echo "254:48 enable=1 ctrl=user rpct=95.00 rlat=5000 wpct=95.00 wlat=5000 min=50.00 max=150.00" > /sys/fs/cgroup/blkio/blkio.cost.qos'cgroup v2 interface
sudo sh -c 'echo "254:48 enable=1 ctrl=user rpct=95.00 rlat=5000 wpct=95.00 wlat=5000 min=50.00 max=150.00" > /sys/fs/cgroup/io.cost.qos'
Usage notes for the cost.model interface
cost.model is a read/write interface used to configure the cost model. The interface file exists only in the root group of blkcg, and its full name varies based on the cgroup version.
cgroup v1:
blkio.cost.modelcgroup v2:
io.cost.model
Configuration
Each line in the configuration file starts with the major (MAJ) and minor (MIN) numbers of a disk in the MAJ:MIN format, followed by the parameters in the following table. To query the MAJ and MIN numbers of a disk, run the lsblk | grep <disk name> command.
Parameter | Description |
ctrl | The control mode. Valid values:
|
model | The model parameter. Valid value:
|
Use the cost.model interface to configure a cost model
In this example, the 254:48 disk is used. Set the model parameter to linear and specify modeling parameters to configure a cost model.
cgroup v1 interface
sudo sh -c 'echo "254:48 ctrl=user model=linear rbps=2706339840 rseqiops=89698 rrandiops=110036 wbps=1063126016 wseqiops=135560 wrandiops=130734" > /sys/fs/cgroup/blkio/blkio.cost.model'cgroup v2 interface
sudo sh -c 'echo "254:48 ctrl=user model=linear rbps=2706339840 rseqiops=89698 rrandiops=110036 wbps=1063126016 wseqiops=135560 wrandiops=130734" > /sys/fs/cgroup/io.cost.model'
Usage notes for the weight/cost.weight interface
The weight interface of Alibaba Cloud Linux 3 and the cost.weight interface of Alibaba Cloud Linux 2 are core interfaces in the kernel used to control I/O resource allocation. Both interfaces are read/write interfaces. You can dynamically allocate disk I/O bandwidth by configuring weight values within the range of [1,10000]. The interface file exists only in the subgroup of blkcg, and its full name varies based on the cgroup version.
Alibaba Cloud Linux 3
cgroup v1:
blkio.cost.weightcgroup v2:
io.weight
Alibaba Cloud Linux 2
cgroup v1:
blkio.cost.weightcgroup v2:
io.cost.weight
Configuration
Set a weight value
<weight>for the interface to change the default weight ofblkcg.Set a port number and a weight value
MAJ:MIN <weight>for the interface to change the weight of the blkcg on the specified disk.
Modify the weight
After you enable the blk-iocost feature, create the blkcg1 control group of cgroup v1 and the cg1 control group of cgroup v2, and use the cost.weight interface for cgroup v1 and the weight interface for cgroup v2 to change the default weight of the control group to 50. Then, set the weight of the control group on the 254:48 disk to 50.
cgroup v1 interface
sudo mkdir /sys/fs/cgroup/blkio/blkcg1 # Create the control group blkcg1 sudo sh -c 'echo "50" > /sys/fs/cgroup/blkio/blkcg1/blkio.cost.weight' # Change the default weight to 50 sudo sh -c 'echo "254:48 50" > /sys/fs/cgroup/blkio/blkcg1/blkio.cost.weight' # Set the weight on the disk to 50cgroup v2 interface
Alibaba Cloud Linux 3
sudo mkdir /sys/fs/cgroup/cg1 # Create the control group cg1 sudo sh -c 'echo "50" > /sys/fs/cgroup/cg1/io.weight' # Change the default weight to 50 sudo sh -c 'echo "254:48 50" > /sys/fs/cgroup/cg1/io.weight' # Set the weight on the disk to 50Alibaba Cloud Linux 2
sudo mkdir /sys/fs/cgroup/cg1 # Create the control group cg1 sudo sh -c 'echo "50" > /sys/fs/cgroup/cg1/io.cost.weight' # Change the default weight to 50 sudo sh -c 'echo "254:48 50" > /sys/fs/cgroup/cg1/io.cost.weight' # Set the weight on the disk to 50
Common monitoring tools
blk-iocost needs to monitor and evaluate the I/O performance of your system. You can use the following tools or interfaces to monitor I/O resource usage and optimize resource utilization.