Categories
Linux

Setting Ubuntu 20.04 to use bfq block scheduler with Ansible

This is a simple ansible config that will set your machine to use the bfq scheduler:

---
# This will turn on the bfq scheduler on Ubuntu 20.04
- hosts: localhost
  become: yes
  tasks:
  - name: Enable kernel module loading
    copy:
      dest: /etc/modules-load.d/bfq.conf
      content: "bfq"
  - name: Enable bfq by default
    copy:
      dest: /etc/udev/rules.d/60-scheduler.rules
      content: 'ACTION=="add|change", KERNEL=="sd*[!0-9]|sr*", ATTR{queue/scheduler}="bfq"'

Put this in a file called enable_bfq_playbook.yml and then run it with ansible-playbook:

~/l/a/bfq> sudo ansible-playbook enable_bfq_playbook.yml 
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Enable kernel module loading] ********************************************
ok: [localhost]

TASK [Enable bfq by default] ***************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Reboot, and you should now have bfq enabled on your disk:

~/l/a/bfq> sudo su -
root@phan-ubu:~# cat /sys/block/sda/queue/scheduler 
mq-deadline [bfq] none
root@phan-ubu:~# 

Leave a Reply

Your email address will not be published. Required fields are marked *