Created
April 18, 2025 13:36
-
-
Save danpawlik/808aef0a9961fe7ca28ac247316b5af6 to your computer and use it in GitHub Desktop.
Set iops and read write limit using cgroup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Set system-wide IOPS limitation via cgroups v2 | |
hosts: all | |
become: true | |
vars: | |
main_blk_name: /dev/vda | |
iops_limit: 10000 | |
rw_total_limit: 104857600 # 100mb in bytes | |
tasks: | |
- name: Get block device major:minor | |
become: true | |
ansible.builtin.shell: | | |
lsblk -nd -o MAJ:MIN {{ main_blk_name }} | |
register: _blk_dev | |
changed_when: false | |
- name: Set IOPS limit in the root cgroup | |
become: true | |
ansible.builtin.shell: | | |
echo "{{ _blk_dev.stdout }} riops={{ iops_limit }} wiops={{ iops_limit }} rbps={{ rw_total_limit }} wbps={{ rw_total_limit }}" > {{ item }} | |
loop: | |
- /sys/fs/cgroup/init.scope/io.max | |
- /sys/fs/cgroup/machine.slice/io.max | |
- /sys/fs/cgroup/system.slice/io.max | |
- /sys/fs/cgroup/user.slice/io.max | |
ignore_errors: true | |
- name: Verify the IOPS limit | |
ansible.builtin.shell: | | |
echo "init"; | |
cat /sys/fs/cgroup/init.scope/io.max; | |
echo "machine"; | |
cat /sys/fs/cgroup/machine.slice/io.max; | |
echo "syste"; | |
cat /sys/fs/cgroup/system.slice/io.max; | |
echo "user" | |
cat /sys/fs/cgroup/user.slice/io.max; | |
register: _current_io_max | |
- name: Print the current io.max value | |
ansible.builtin.debug: | |
msg: "{{ _current_io_max.stdout_lines }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment