Solid State Drives (SSD) have started dominating the chromebook kind of new generation laptop and Premium laptops. It replaces conventional Hard Disk Drives (HDD) due to advantages of high throughput (fast read/write speed), light weight and small form factor. The cost of SSD is going down gradually so that it is affordable for Desktop system too.

In this background, recently I bought a SSD for my ageing home desktop machine replacing the faulty hard disk. It is Transcend SATA 128GB drive of model SSD340 (TS128GSSD340). I have installed Ubuntu 14.04 on this SSD. Here is the quick look on how far this kind of SSDs are supported in Ubuntu 14.04 kind of Linux distributions. The reason for “kind of” in above sentence is most of this discussion is applicable/useful on any modern Linux distributions and SSD.

Installation

Ensure that your BIOS settings for SSD SATA device is set as AHCI mode to get full benefit out of SSD. The installation is straight forward, did not find any issue in detecting and installing the OS on top of it. Good start! Now we have Ubuntu 14.04 installed on SSD.

Collecting information about SSD

Issue following command to get in depth information about your SSD. It is highly useful data comes handy while you configure and fine tune your SSD. Replace the “/dev/sda” with your drive in the following command.

karuppuswamy@Ubuntu-PC:~$ sudo hdparm -I /dev/sda /dev/sda: ATA device, with non-removable media Model Number: TS128GSSD340 Serial Number: 20140410B39474016734 Firmware Revision: SVN263 Transport: Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0 Standards: Supported: 9 8 7 6 5 Likely used: 9 Configuration: Logical max current cylinders 16383 16383 heads 16 16 sectors/track 63 63 -- CHS current addressable sectors: 16514064 LBA user addressable sectors: 250069680 LBA48 user addressable sectors: 250069680 Logical Sector size: 512 bytes Physical Sector size: 512 bytes Logical Sector-0 offset: 0 bytes device size with M = 1024*1024: 122104 MBytes device size with M = 1000*1000: 128035 MBytes (128 GB) cache/buffer size = unknown Form Factor: less than 1.8 inch Nominal Media Rotation Rate: Solid State Device Capabilities: LBA, IORDY(can be disabled) Queue depth: 32 Standby timer values: spec'd by Standard, no device specific minimum R/W multiple sector transfer: Max = 16 Current = 16 Advanced power management level: 254 DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 *udma5 Cycle time: min=120ns recommended=120ns PIO: pio0 pio1 pio2 pio3 pio4 Cycle time: no flow control=120ns IORDY flow control=120ns Commands/features: Enabled Supported: * SMART feature set Security Mode feature set * Power Management feature set * Write cache * Look-ahead * Host Protected Area feature set * WRITE_BUFFER command * READ_BUFFER command * NOP cmd * DOWNLOAD_MICROCODE * Advanced Power Management feature set SET_MAX security extension * 48-bit Address feature set * Device Configuration Overlay feature set * Mandatory FLUSH_CACHE * FLUSH_CACHE_EXT * SMART error logging * SMART self-test * General Purpose Logging feature set * WRITE_{DMA|MULTIPLE}_FUA_EXT * 64-bit World wide name * WRITE_UNCORRECTABLE_EXT command * {READ,WRITE}_DMA_EXT_GPL commands * Segmented DOWNLOAD_MICROCODE * Gen1 signaling speed (1.5Gb/s) * Gen2 signaling speed (3.0Gb/s) * Gen3 signaling speed (6.0Gb/s) * Native Command Queueing (NCQ) * Host-initiated interface power management * Phy event counters * Host automatic Partial to Slumber transitions * Device automatic Partial to Slumber transitions * READ_LOG_DMA_EXT equivalent to READ_LOG_EXT DMA Setup Auto-Activate optimization Device-initiated interface power management * Software settings preservation Device Sleep (DEVSLP) * SMART Command Transport (SCT) feature set * SCT Error Recovery Control (AC3) * SCT Features Control (AC4) * SCT Data Tables (AC5) * Data Set Management TRIM supported (limit 2 blocks) Security: Master password revision code = 65534 supported not enabled not locked not frozen not expired: security count supported: enhanced erase 2min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT. Logical Unit WWN Device Identifier: 5000000000000000 NAA : 5 IEEE OUI : 000000 Unique ID : 000000000 Checksum: correct Device Sleep: DEVSLP Exit Timeout (DETO): 100 ms (drive) Minimum DEVSLP Assertion Time (MDAT): 31 ms (drive)

Health of SSD

S.M.A.R.T is the standard to report health condition of a storage device. You need to install a package called “smartmontools” to get health report of your SSD. Issue the following commands to install and run this tool and know the how healthy your device is.

$ sudo apt-get install smartmontools $ sudo smartctl -A /dev/sda smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF READ SMART DATA SECTION === SMART Attributes Data Structure revision number: 16 Vendor Specific SMART Attributes with Thresholds: ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 1 Raw_Read_Error_Rate 0x000a 100 100 000 Old_age Always - 0 2 Throughput_Performance 0x0005 100 100 050 Pre-fail Offline - 0 3 Spin_Up_Time 0x0007 100 100 050 Pre-fail Always - 0 5 Reallocated_Sector_Ct 0x0013 100 100 050 Pre-fail Always - 0 7 Unknown_SSD_Attribute 0x000b 100 100 050 Pre-fail Always - 0 8 Unknown_SSD_Attribute 0x0005 100 100 050 Pre-fail Offline - 0 9 Power_On_Hours 0x0012 100 100 000 Old_age Always - 1 10 Unknown_SSD_Attribute 0x0013 100 100 050 Pre-fail Always - 0 12 Power_Cycle_Count 0x0012 100 100 000 Old_age Always - 4 167 Unknown_Attribute 0x0022 100 100 000 Old_age Always - 0 168 Unknown_Attribute 0x0012 100 100 000 Old_age Always - 0 169 Unknown_Attribute 0x0013 100 100 010 Pre-fail Always - 1441792 170 Unknown_Attribute 0x0013 100 100 010 Pre-fail Always - 0 173 Unknown_Attribute 0x0012 199 199 000 Old_age Always - 4295163905 175 Program_Fail_Count_Chip 0x0013 100 100 010 Pre-fail Always - 0 192 Power-Off_Retract_Count 0x0012 100 100 000 Old_age Always - 3 194 Temperature_Celsius 0x0022 054 054 030 Old_age Always - 46 (Min/Max 43/46) 197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0 240 Unknown_SSD_Attribute 0x0013 100 100 050 Pre-fail Always - 0

Trim Support

Trim is the way of housekeeping in SSD, which ensures that free blocks are readily available in advance for further write. All modern SSDs support this feature, you can verify with hdparm command we used to collect information of SSD.

$ sudo hdparm -I /dev/sda | grep TRIM * Data Set Management TRIM supported (limit 2 blocks)

The above command shows that Trim is supported by this SSD.

“fstrim” is the command which does this job. This can be run periodically through a cron job. Here is a way to see this in action. Let’s say you have created a new partition and file system on SSD. In this case /home file system is on SSD. Now I am asking the SSD to trim the deleted file’s blocks.

$ sudo fstrim -v /home /home: 0 bytes were trimmed

Since we have not deleted any file, it does show 0 bytes trimmed. Now let’s delete a file of size 1.9GB. Then issue fstrim command as shown below, which shows the no. of bytes trimmed around 1.9GB. Till you issue this command, SSD in no way to know that you don’t need this data again. Now this command explicitly instructed SSD to delete the data and keep it ready for further writing (In fact flash memory chips in SSD needs to erase the blocks before every write – which I simply call “keep it ready”).

$ sudo fstrim -v /home /home: 2113138688 bytes were trimmed

Ubuntu has automated this for you, but with a catch. Yes, it is enabled by default for Intel and Samsung SSDs, which have been well tested and supported. In case your drive supports Trim, you can also try enabling this (Disclaimer: It is your responsibility to keep the data backed up properly, I am not responsible for any lost you claim on this). I have enabled it for my Transcend SSD by appending “–no-model-check” to the fstrim command in the file /etc/cron.weekly/fstrim. Here is how it is in my file.

exec fstrim-all --no-model-check

In case of new SSD, you may need not to run this cron job weekly as per Ubuntu default. You can move this to /etc/cron.monthly/fstrim till you accumulate a lot of files.

There is a way to do this trim operation on the fly. You can do this by adding “discard” flag while mounting the file system. It means that file system can issue this trim instruction to SSD when ever it deletes a file. But it may affect the performance of device. So it is not preferred for a new SSD at least.

File System mount

The default file system mount file shown in my case.

$ sudo vi /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # # / was on /dev/sda5 during installation UUID=3fca70df-d717-4664-8268-3c2048b00ac3 / ext4 errors=remount-ro 0 1 # /home was on /dev/sda6 during installation UUID=f7d9be87-6a1c-4b7e-9179-7a3056db9716 /home ext4 defaults 0 2 # swap was on /dev/sda7 during installation UUID=4c48ce5f-1204-4bf8-a4e1-6776a17fd8d8 none swap sw 0 0

“discard” flag is not set by default during installation. This flag will instruct file system to issue trim command when ever you delete a file, which may lead to slow down of system. Periodical trim should be fine for a desktop system.

Add “noatime” flag to all SSD file systems in /etc/fstab except swap. This flag helps preventing updating file system meta data of “file access time” (which in turn writing to SSD) when ever you access a file in SSD.

Here is the updated /etc/fstab.

$ sudo vi /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # # / was on /dev/sda5 during installation UUID=3fca70df-d717-4664-8268-3c2048b00ac3 / ext4 noatime,errors=remount-ro 0 1 # /home was on /dev/sda6 during installation UUID=f7d9be87-6a1c-4b7e-9179-7a3056db9716 /home ext4 defaults,noatime 0 2 # swap was on /dev/sda7 during installation UUID=4c48ce5f-1204-4bf8-a4e1-6776a17fd8d8 none swap sw 0 0

Browser configuration

Some people prefer to fine tune SSD to optimize the number of writes. Here is how to do it. Firefox caches the pages you have visited which causes a lot of IO to SSD. You can disable it by setting cache limit as 0MB as shown in below. This setting can be reached by Firefox Menu -> Preferences -> Advanced -> Cached Web Content

Swap configurations

Setting the swappiness is highly debated topic in Linux kernel world. In case you plan to disable the swap partition, in stead of disabling the swap partition (or omitting), we can set swappiness as 0 so that swap partition can be used for suspend to disk (Hibernate). By default Hibernation is disabled in Ubuntu. You need to enable it through other hacks.

$ sudo swapon -s [sudo] password for karuppuswamy: Filename Type Size Used Priority /dev/sda7 partition 7811068 0 -1

$ cat /proc/meminfo | grep "^Mem" MemTotal: 7660780 kB MemFree: 6387244 kB $ cat /proc/meminfo | grep "^Swap" SwapCached: 0 kB SwapTotal: 7811068 kB SwapFree: 7811068 kB

Turning the Kernel parameters

The following commands shows the default kernel parameter which may need tuning.

$ sysctl vm.swappiness vm.swappiness = 60

$ sysctl vm.vfs_cache_pressure vm.vfs_cache_pressure = 100

The lower (from 100 to 50) value of vfs_cache_pressure configures kerenl to retain filesystem meta data (dentry and inode cache), which means even during memory pressure this cache won’t be released. In case you have enough RAM (in my case it is 8GB), it is fine to reduce it further. This will lead to less frequent SSD access.

Append the following three lines in /etc/sysctl.conf to fine tune the above parameters. You need to reboot the system to make it effective.

# Custom settings # disable the swapping, still swap partition is necessary for hibernation vm.swappiness=0 vm.vfs_cache_pressure=50

IO Scheduler algorithm

Before reading further, here is a quick overview of IO scheduler algorithms.

the Anticipatory scheduler introduces a controlled delay before dispatching the I/O to attempt to aggregate and/or re-order requests improving locality and reducing disk seek operations. This algorithm is intended to optimize systems with small or slow disk subsystems;

the Completely Fair Queuing (CFQ) scheduler maintains a scalable per-process I/O queue and attempts to distribute the available I/O bandwidth equally among all I/O requests;

the Deadline scheduler uses a deadline algorithm to minimize I/O latency for a given I/O request;

the Noop scheduler is a simple FIFO queue, and it assumes performance of the I/O has been or will be optimized at the block device.

By default “deadline” is selected which is good for SSD, leaving it as it is.

$ cat /sys/block/sda/queue/scheduler noop [deadline] cfq

For a 1GB file, copying from HDD to SSD, it took 10.347 seconds as per below test with the above default setting.

$ time cp /media/karuppuswamy/72e998d2-78f0-436c-a067-b1f578c3737c/karuppuswamy/Archives/Linux\ ISOs/ubuntu-14.04-desktop-amd64.iso . real 0m10.347s user 0m0.036s sys 0m2.741s

You can experiment with “noop”, which is supposed to work well for a SATA SSD with AHCI Programming Interface and NCQ support. The command is given below.

$ sudo echo noop > /sys/block/sda/queue/scheduler

I believe this notes is helpful for you. Thanks for reading.