Blk-iocost weight-based throttling enhances cgroup I/O subsystem (blkcg) disk throttling in Alibaba Cloud Linux. It allocates block device I/O bandwidth by application or process priority. Configure weight values to limit per-application or per-process I/O bandwidth.
The Alibaba Cloud Linux kernel supports both cgroup v1 and v2 interfaces for blk-iocost, but only one is active at a time. Run stat -fc %T /sys/fs/cgroup to check which version is active.
-
A return value of
tmpfsindicates the cgroup v1 interface. -
A return value of
cgroup2fsindicates the cgroup v2 interface.
Supported operating systems
-
Alibaba Cloud Linux 2 with kernel version
4.19.81-17or later -
Alibaba Cloud Linux 3
Use the cost.qos interface
The cost.qos interface enables or disables blk-iocost and rate-limits I/O quality of service (QoS) based on latency and weight. It exists only in the root blkcg group, and its name varies between cgroup versions.
-
cgroup v1:
blkio.cost.qos -
cgroup v2:
io.cost.qos
Configuration
Each line starts with the device number in MAJ:MIN format (run lsblk | grep <Cloud_Disk_Name> to find it), followed by these parameters:
|
Parameter |
Description |
|
enable |
Enables or disables blk-iocost.
|
|
ctrl |
The control mode.
|
Enable the blk-iocost feature
This example enables blk-iocost for device 254:48 in user mode. The disk is saturated when 95% of read/write latencies (rlat and wlat) exceed 5000 μs (5 ms), and the kernel adjusts the dispatch rate between 50% and 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'
Use the cost.model interface
The cost.model interface configures the I/O cost model. It exists only in the root blkcg group, and its name varies between cgroup versions.
-
cgroup v1:
blkio.cost.model -
cgroup v2:
io.cost.model
Configuration
Each line starts with the device number in MAJ:MIN format (run lsblk | grep <Cloud_Disk_Name> to find it), followed by these parameters:
|
Parameter |
Description |
|
ctrl |
The control mode.
|
|
model |
Currently only the
|
Set a cost model
This example sets a linear cost model for device 254:48 with user-defined parameters.
-
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'
Use the weight/cost.weight interface
This interface controls I/O resource allocation through a weight value between 1 and 10000. The interface name varies by cgroup version and OS. These files exist only in blkcg subgroups.
-
Alibaba Cloud Linux 3
-
cgroup v1:
blkio.cost.weight -
cgroup v2:
io.weight
-
-
Alibaba Cloud Linux 2
-
cgroup v1:
blkio.cost.weight -
cgroup v2:
io.cost.weight
-
Configuration
-
To modify the default weight of a
blkcg, set a weight value for the interface:<weight>. -
To modify the weight of a
blkcgon a specific device, use the following format:MAJ:MIN <weight>.
Modify weights
After you enable blk-iocost, these examples create control groups (blkcg1 for cgroup v1, cg1 for cgroup v2) and set both the default weight and the device-specific weight for 254:48 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 50 -
cgroup 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 50 -
Alibaba 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
The following tools help monitor and tune I/O performance under blk-iocost.