Hi,
Recently I transferred a Samsung 830 Series 128GB SSD from retired
Win7pro box to a shiny new Slackware64-14.1 box.
Here I describe some of the things needed to run Linux on an SSD.
Over provisioning
``````````````````
This is where one leaves some of the SSD unallocated. The unallocated
space is used by the SSD firmware as part of it's garbage collection.
It extends the life of the SSD and also adds to speed of operation.
Samsung recommend over provisioning at 7 to 10% on small drives:
"
The SSD will naturally use any available free space to perform its
maintenance algorithms. If you have a small SSD, on the other hand,
it is recommended to set aside some OP (between 6.7 and 10% of total
drive space) to minimize the risk of accidentally filling the drive
to capacity. While filling a drive with data isn't harmful, it will
have a severe impact on performance.
" --<
http://www.samsung.com/global/business/semiconductor/minisite/SSD/us/html/about/whitepaper05.html>
So I aimed for about 10% over-provisioning, by leaving a portion of
the SSD unallocated:
# fdisk -l /dev/sda
Disk /dev/sda: 128.0 GB, 128035676160 bytes
255 heads, 63 sectors/track, 15566 cylinders, total 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x460bd378
Device Boot Start End Blocks Id System
/dev/sda1 2048 16779263 8388608 83 Linux
/dev/sda2 16779264 33556479 8388608 83 Linux
/dev/sda3 33556480 37750783 2097152 82 Linux swap
/dev/sda4 37750784 192956415 77602816 5 Extended
/dev/sda5 37752832 46141439 4194304 83 Linux
/dev/sda6 46143488 54532095 4194304 83 Linux
/dev/sda7 54534144 62922751 4194304 83 Linux
/dev/sda8 62924800 71313407 4194304 83 Linux
/dev/sda9 71315456 73412607 1048576 83 Linux
/dev/sda10 73414656 75511807 1048576 83 Linux
/dev/sda11 75513856 117456895 20971520 83 Linux
/dev/sda12 117458944 192956415 37748736 83 Linux
Notice the end sector is about 10% less than total sectors.
Another aspect of this is that the modern SSD is designed for the
NTFS filesystem, how does it know about what freespace is available
on a Linux filesystem? Thus we should use SSD over provisioning
on Linux in my opinion.
This may also explain why some SSDs have sizes in 60, 120, 240GB and
so on. There's also the difference between binary GiB and decimal GB
working in the SSD manufacturer's favour for making the space.
SSD trim
`````````
Early on, expensive SSDs were suffering from erase/write lifetime
limits, and people decided to do something to improve that. Also,
of the product's development, increases in capacity by using smaller
cells, and using MLC (the storing of 2 bits per cell as one of
four analog voltages), has decreased the erase/write life cycle
count to as low as 3000.
This is because SSDs can only be erased in much larger blocks (for
example, 128k or 256k) though they can be written in 4k blocks that
naturally suit modern hard drives and operating systems.
What SSD trim does is notify the SSD firmware when a file's contents
is no longer required, the SSD can then use this information as part
of its decision to coalesce vacant blocks to build the next erase
target block.
The first SSD survival tool is to specify 'noatime' in /etc/fstab for
SSD mountpoints, to remove these unnecessary inode updates (as long
as you're not running a server relying on file access times).
Next is the SSD trim command, the first trim method for Linux
filesystems was to specify the 'discard' option on SSD mount points,
in the /etc/fstab file.
** Note that this requires use of a filesystem that can perform the
** trim command, thus the dated reiserfs3 is out, so I'm now using
** ext4 for new systems with SSDs. (btrfs is a bit too new for me)
Problem with this early method is that Linux issued trim commands
that were executed synchronously with the business of writing new
files. So this fstab method fell into disfavour because it reduced
filesystem performance.
One doesn't want SSD garbage collection in the middle of a long file
write sequence, does one?
fstrim as cron job
```````````````````
The current preferred method is to call 'fstrim' from a root cron
job to perform the SSD filesystem trim on a regular basis. I've
seen references to once per day, or once per week. I set my system
to 04:50 each day, to be done after Slackware's normal 04:40 daily
business.
An fstrim script:
# cat /usr/local/bin/ssdtrim
#!/bin/sh
#
# ssdtrim
#
# trim SSD by issuing fstrim for each SSD active mount point, call from
# root cron job running daily or weekly
#
# Copyright (c) 2014 Grant Coady
http://bugsplatter.id.au GPLv2
#
# Example crontab entry
# # ssdtrim once a day at 04:50, logs to /var/log/ssdtrim.log
# 50 4 * * * /usr/local/bin/ssdtrim >> /var/log/ssdtrim.log 2>/dev/null
# #
#
# after
http://wiki.ubuntuusers.de/SSD/TRIM (very vaguely now)
#
echo "$(date +%F.%T)"
while read dire rest
do
fstrim -v $dire | gawk '
{
dir = $1
size = $2 / 2^10
sub(/:/,"", dir)
printf "%24s : %d K\n", dir, size
}'
# list active SSD mountpoints in this here document
done <<-EOF
/
/home
/var
/usr/local
/srv/common
/srv/mirror
EOF
After a reboot:
# /usr/local/bin/ssdtrim
2014-09-19.08:40:36
/ : 3130460 K
/home : 933392 K
/var : 3943312 K
/usr/local : 997860 K
/srv/common : 16067404 K
/srv/mirror : 15557272 K
I put the output redirection in the crontab so that the script could
be called casually:
# /usr/local/bin/ssdtrim
2014-09-19.08:42:39
/ : 0 K
/home : 0 K
/var : 0 K
/usr/local : 0 K
/srv/common : 0 K
/srv/mirror : 0 K
Why so many partitions? Because I can? Actually I was having big problems
with dataloss after transferring a working Slackware install to the SSD,
and the change from reiserfs3 to ext4, probably finger trouble. Solved by
a new bare metal install of Slackware64-14.1 onto ext4. We have:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 7.8G 4.8G 2.6G 65% /
/dev/sda5 3.9G 3.0G 691M 82% /home
/dev/sda7 3.9G 51M 3.6G 2% /var
/dev/sda9 976M 1.5M 908M 1% /usr/local
/dev/sda11 20G 4.3G 15G 23% /srv/common
/dev/sda12 36G 21G 14G 62% /srv/mirror
tmpfs 1.9G 0 1.9G 0% /dev/shm
deltree:/home/common 16G 4.2G 12G 27% /home/common
Partitions 2, 6, 8, 10 are for a parallel install of Slackware, when
the next release comes out. I'm a firm believer in parallel OS installs
on important boxes, for fast switchover if the new OS install goes awry.
Swap is on partition 3, I don't expect the box to use much swap.
ssdview
````````
Rather than slog through the 'smartctl -a /dev/sda', and wonder about that
'235 Unknown_Attribute ...', I wrote a small script to summarise important
numbers from the 'smartctl -a /dev/sda' command:
# cat /usr/local/bin/ssdview
#!/bin/sh
#
# ssdview
#
# report Total Bytes Written for /dev/sda, and some other info
#
# Copyright (c) 2014 Grant Coady GPLv2
http://bugsplatter.id.au
#
# Attribute 235 POR Recovery Count is defined by Samsung Magician on Windows
#
smartctl -a /dev/sda | gawk '
{
tag = $2
gsub(/_/, " ", tag)
}
/^235/ { tag = "POR Recovery Count" }
/Power_On_Hours|Power_Cycle_Count|Wear_Leveling_Count|^235/ {
printf "%24s : %d\n", tag, $10
}
/Total_LBAs_Written/ {
tag = "Total Bytes Written"
printf "%24s : %1.3f TB\n", tag, $10 * 512 / 10^12
}'
# end
An example of gawk at its best, text processing.
Produces :
# /usr/local/bin/ssdview
Power On Hours : 10651
Power Cycle Count : 623
Wear Leveling Count : 159
POR Recovery Count : 143
Total Bytes Written : 3.412 TB
I bought the SSD above about 2.5 years ago, and until a few months ago
I used to leave the Win7 box running 24/7.
Find the latest versions of these scripts on:
<
http://bugsplatter.id.au/system/d3v.html#running_an_ssd>
Enjoy!
Comments welcome.
Grant.