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
SysFSrotational 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:lsblkNAME 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
sda1andsda2. -
Set the IO scheduler to either
mq-deadlineornonefor each of the listed devices:For example:
echo mq-deadline > /sys/block/<device_name>/queue/schedulerwhere <device_name> is the name of the device you want to apply settings for.
-
The mq-deadline scheduler optimizes requests to minimize IO latency. If in doubt, use the mq-deadline scheduler.
echo mq-deadline > /sys/block/<device_name>/queue/scheduler -
The
nonescheduler 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 none > /sys/block/<device_name>/queue/scheduler
-
-
Set the
nr_requestsvalue 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
readaheadvalue 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
readaheadsetting for RAID on SSDs is the same as that for SSDs that are not being used in a RAID installation.-
Open
/etc/rc.localfor editing. -
Add the following lines to set the
readaheadon 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
readaheadto 128, which is the recommended value:sudo blockdev --setra 128 /dev/<spinning_disk>