Using a Rotational Hard Disk on Modern Linux

Overview

The reasons to use a real rotational Hard Disk Drive(HDD) on modern linux are few, but do exist. Maybe you don't have the time, money, or physical access to upgrade to a Solid State Drive SSD. Maybe you are just copying the data off an old drive.

Hdparm

hdparm can be used to get of set HDD configuration.

hdparm -I /dev/sda

Access Time

Writing to the disk every time a file is access can be expensive. This is true with SSDs, but compounded by the speed of HDDs.

relatime

relatime is the modern Linux default. Use it if available.

noatime

noatime is reasonable if on an old kernel for some reason

nodiratime

noadirtime doesn't update directory access times which can be combined with relatime

lazytime

lazytime only updates all times in RAM only writing them back to disk at certain intervals

I/O Scheduler

Rotational HDDs are slow enough that the choice of scheduler is very important.

Deadline

The default IO scheduler in Debian for rotational disks. It uses minimal CPU, but still reorder seeks to optimize throughput. deadline and mq-deadline

BFQ

Probably the best option for HDDs with desktop use. It uses more CPU to reduce latency and fairly share the disk IO. It will help make the desktop feel a little more responsive possible at the cost of theoretical max throughput. In Debian, this is compiled as a module that has to be loaded first

modprobe bfq
echo SCHED > /sys/block/sda/queue/scheduler

To make it permanent add this to /etc/sysfs.conf

block/sda/queue/scheduler = bfq

It should automatically load the module, but if not add bfq to /etc/modules.

None

The default for SSDs this scheduler does nothing. it just hands off the IO requests adding the minimum amount of overhead. It is great with SSDs because they have little penalty for out of order accesses and they are so fast delaying access to make an optimal decision is more likely to cost more than it pays.

File System

A Defragmented file will require less seeking to read. So using a file system like EXT4 should speed up rotational disk access.

EXT 2/3/4

https://opensource.com/article/17/5/introduction-ext4-filesystem

Converting EXT2 to EXT3

You just need to add the journal

tune2fs -j /dev/sda1
Shortcut Journaling

The mount option data=writebackallows the journal to It is smoother, but don't do it as it can lead to significant.

I think this link says it all. https://help.marklogic.com/Knowledgebase/Article/View/209/0/linux-filesystem-tuning---performance-datawriteback-vs-dataintegrity-dataorderedS

Converting EXT3 to EXT4

Need to enable extents and a few other EXT4 standard features

tune2fs -O extents,uninit_bg,dir_index /dev/sda1
fsck -pf /dev/sda1
e2fsck -f /dev/sda1
Converting files to extents (Potentially Dangerous)

This will go through and change all the files in the directory to extents.

find /mnt -xdev -type f -print0 | xargs -0 chattr +e
find /mnt -xdev -type d -print0 | xargs -0 chattr +e

This may cause an issue for files using hard links such as mercurial repos. You can find files that have multiple hard links with this:

find /mnt -type f -links +1
Defragmenting EXT4

Once the files are all using extents you can defrag them

e4defrag -v /dev/sda1

System Indexing Tools

Many newer tools and OS's, such as Windows 10, rely heavily on background file system indexing to speed up searches and other file system tasks. This indexing can greatly increase the load on the disk at inconvenient times, this is particularly not helpful if you don't use the tools that use these indexes.

Akonadi

akonadictl status
akonadictl stop

in ~/.config/akonadi/akonadiserverrc

StartServer=false

Baloo

balooctl status
balooctl stop

~/.config/baloofilerc

Gnome Tracker

Logging

Logging is another source of file system activity that may get in the way of what you are trying to do. It is probably a small contributor, but while we are at it.

Journald

Find constantly logging processes anything constantly logging is constantly accessing the disk not a big component, but if it is spewing errors it should probably be fixed anyway.

journalctl -f

old syslog

Modern Linux packages can almost all use Journald you can probably remove older logging frameworks if you just embrace the systemd journal, freeing up a little space.