Optimize disk settings
The default disk configurations on most Linux distributions are not optimal. Follow these steps to optimize settings for your Solid State Drives (SSDs) or spinning disks.
Complete the optimization settings for either SSDs or spinning disks. Do not complete both procedures for either storage type. |
Optimize SSDs
Complete the following steps to ensure the best settings for SSDs.
-
Ensure that the
SysFS
rotational flag is set tofalse
(zero).This overrides any detection by the operating system to ensure the drive is considered an SSD.
-
Apply the same rotational flag setting for any block devices created from SSD storage, such as mdarrays.
-
Determine your devices by running
lsblk
:lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 32G 0 disk | |-sda1 253:1 0 8M 0 part |-sda2 253:2 0 32G 0 part /
In this example, the current devices are
sda1
andsda2
. -
Set the IO scheduler to either
deadline
ornoop
for each of the listed devices:For example:
echo deadline > /sys/block/<device_name>/queue/scheduler
where <device_name> is the name of the device you want to apply settings for.
-
The deadline scheduler optimizes requests to minimize IO latency. If in doubt, use the deadline scheduler.
echo deadline > /sys/block/<device_name>/queue/scheduler
-
The
noop
scheduler is the right choice when the target block device is an array of SSDs behind a high-end IO controller that performs IO optimization.echo noop > /sys/block/<device_name>/queue/scheduler
-
-
Set the
nr_requests
value to indicate the maximum number of read and write requests that can be queued:Machine size Value Large machines
`language-bash echo 128 sys/block/<device_name>/queue/nr_requests `
Small machines
`language-bash echo 32 sys/block/<device_name>/queue/nr_requests `
-
Set the
readahead
value for the block device to 8 KB.This setting tells the operating system not to read extra bytes, which can increase IO time and pollute the cache with bytes that weren’t requested by the user.
The recommended
readahead
setting for RAID on SSDs is the same as that for SSDs that are not being used in a RAID installation.-
Open
/etc/rc.local
for editing. -
Add the following lines to set the
readahead
on startup:touch /var/lock/subsys/local echo 0 > /sys/class/block/sda/queue/rotational echo 8 > /sys/class/block/sda/queue/read_ahead_kb
-
Save and close /etc/rc.local.
-
Optimize spinning disks
-
Check to ensure read-ahead value is not set to 65536:
sudo blockdev --report /dev/<spinning_disk>
-
Set the
readahead
to 128, which is the recommended value:sudo blockdev --setra 128 /dev/<spinning_disk>