Let's say I have two swap partitions, /dev/sdb and /dev/sdc, where /dev/sdb is 4 times faster in terms of I/O than /dev/sdc. Is it possible to configure it in such way that when the OS decides that it has 5 MB of RAM content to swap out, it directs 4 MB of it to /dev/sdb and 1 MB to /dev/sdc to provide optimal swapping speed?
- 149
- 147
1 Answers
If /dev/sdb is 4 times faster than /dev/sdc, it'll be faster to fill up /dev/sdb first before starting on /dev/sdc.
Keep in mind that it's not just splitting up sequential reads and writes; there's also seek latencies, disk spin-up times, and synchronizing both disks so that one writes four parts while the other writes one. The sequential throughput may theoretically be higher, but it's not practical.
That said, mounted swap partitions have priorities. If you want to mount your two swap partitions so that /dev/sdb is used first and then /dev/sdc, consider this example:
sudo swapon -p 10 /dev/sdb
sudo swapon -p 5 /dev/sdc
In /etc/fstab, you would pass the pri option to set the priority, like so:
/dev/sda none swap defaults,pri=10 0 0
/dev/sdb none swap defaults,pri=5 0 0
As a practical example, you would want to do this if you were using zram. Since zram is way faster than hard drives and solid-state drives, you would like your zram swap partitions to be used first. Here, you can see the four zram devices preferred to the slow device /dev/zd16:
deltik@node51 [~]$ swapon -s
Filename Type Size Used Priority
/dev/zd16 partition 8388604 0 -1
/dev/zram0 partition 1524800 275252 5
/dev/zram1 partition 1524800 275400 5
/dev/zram2 partition 1524800 276296 5
/dev/zram3 partition 1524800 275392 5
(On Ubuntu, zram swap is conveniently provided by the zram-config package.)
Even though /dev/zram* are orders of magnitude faster than /dev/zd16 sequentially, I would not want to balance the workload because /dev/zd16 seeks way slower than /dev/zram* do.