Disable/Enable Readahead value for LVM volume with tuned running.

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9

Issue

  • How to disable Readahead for LV with tuned service enabled?
  • How to set readahead value using custom systemd unit file with tuned enabled?

Resolution

Create a systemd service unit file, and make sure it starts after tuned service and set the needed value for read ahead in ExecStart:

# cat /etc/systemd/system/setra.service 
[Unit]
Description=Set custom read-ahead on LV
After=tuned.service
Requires=tuned.service

[Service]
Type=idle
ExecStart=/sbin/blockdev --setra 0 /dev/mapper/vgtest-lvtest

[Install]
WantedBy=multi-user.target

If there are multiple logical volumes to set the read ahead value then one can use the Type=oneshot:

# cat /etc/systemd/system/setra.service 
[Unit]
Description=Set custom read-ahead on LV
After=tuned.service
Requires=tuned.service

[Service]
Type=oneshot
ExecStart=/sbin/blockdev --setra 0 /dev/mapper/vgtest-lvtest
ExecStart=/sbin/blockdev --setra 8 /dev/mapper/vg1-lv1

[Install]
WantedBy=multi-user.target

Enable the custom service:

#systemctl daemon-reload
#systemctl enable setra.service

Check the result:

# blockdev --report                 
RO    RA   SSZ   BSZ   StartSec            Size   Device
...
rw  8192   512  4096          0      2147483648   /dev/dm-0
rw  8192   512   512          0     18756927488   /dev/dm-1
rw     0   512   512          0      1073741824   /dev/dm-2   <-- 
rw  8192   512   512          0      2147483648   /dev/dm-3

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments