doc:techref:ssd

SSD Disks

This are some previous recommendations prior to start, or even buy the disk:

  • Use a recent kernel > 3.2 or better > 3.9
  • Check feature and Firmware version using (note that you may need to use windows to update firmware ;( ) smartctl -a <device> hdparm -I <device>
  • Check if kernel recognizes the disk as a not rotational one: cat /sys/class/block/sda/queue/rotational 0
  • Buying the right sized SSD is key. As with all filesystems, target <75 % occupancy for all SSD partitions to ensure efficient use by the kernel

This is critical aspect, although many modern Linuxes wiht up-to-date partitioning tools automatically set this correctly. Partitions and filesystems should be aligned to the block size of the device (usually 1 or 4Mb).

In Linux, simply run fdisk -cu (device) on the drive you want to partition, enter a start sector of at least 2,048. The general rule is that the starting sector must be divisible by 512, but to cater for all variations of SSD page size and filesystem block size, 2,048 is a good idea (and equates to 1MB).

Old sector size industry was 512bytes, now industry is moving to sectors of 4K, if using fdisk:

  • Deactivate DOS compatibility mode (the -c flag).
  • Use sectors as display units (the -u flag).

with parted you can use align-check opt to check for alignment or run the following command to check if partition is aligned:

# blockdev --getalignoff /dev/<partition>
0
  • Use ext4 (btrfs is still experimental on 3.11). data=ordered which sould be a good compromise between full journaling and none at all. See Ext4 Filesystem documentation for more details.
  • Avoid swapping to SSD or use HDD for swap
  • Write less: set noatime,nodiratime,relatime options on mount in /etc/fstab
  • Use TRIM:
    • Actively setting option discard on mount in /etc/fstab
    • Passively scheduling fstrim cronjob periodically
    • Not critical if you have enough free space or unpartitioned space in the SSD
  • Remove /etc/mtab and create it as a symbolic link to /proc/mounts
  • NO swap space
  • Mount /tmp/, /run/ as tmpfs, either on fstab or via /etc/default/tmpfs
  • Link /var/tmp/ to /tmp, if you can put it on another device is always a secure practice
  • Dependening on your needs may be recommended to tmp mount /var/log/ too. Also set syslog to not sync the logs or use ramlog
  • Is also recommended to set journal to writeback, which will commit metadata to the journal and content data lazily on background (so a crash may lead us to quite stale/old data).

The default IO scheduler used is designed for rotational disks, but not for SSD disks. Newer kernels can detect whether the disk is SSD or rotational one by the contents of the file /sys/block/sdX/queue/rotational.

Recommended IO scheduler for SSD disks is NOOP (a basic FIFO) or deadline (which sets a deadline to server read requests). You can set the scheduler on /sys/block/sda/queue/scheduler

Both are basic schedulers that guarantee fast turnaround of I/O requests. NOOP is basically no scheduler at all, it's a basic FIFO (First In, First Out) queue whereas deadline does some sorting to guarantee read requests take priority over write, which is useful if you want to guarantee read responsiveness under heavy writes.

Via sysctl is recommended to adjust following settings:

These settings should be reviewed for correctness/documentation
vm.vfs_cache_pressure=50
vm.laptop_mode=5
vm.dirty_writeback_centisecs=60000
vm.dirty_ratio=90
vm.dirty_background_ratio=1
vm.swappiness=1

Or better, use pm-utils (Debian BTS #659260), tlp, or laptop-mode-tools (also optimizes read buffers) to configure the laptop-mode even under AC operation.

Use of RAMDISK can stop constantly changing files from hitting on the SSD (it may hit SSD via swap). RAMDISK configuration may be performed setting RAMTMP, RAMRUN and RAMLOCK on/etc/default/tmpfs

Enabling RAMTMP may cause some (broken) applications to run out of temporary write disk space. Setting TMPDIR environment variable for those programs pointing to a writable disk space should fix their situation.

  • doc/techref/ssd.txt
  • Last modified: 2021/06/10 21:45
  • by 127.0.0.1