Wednesday, May 23, 2012

SSD & CentOS 6+


SSD  & CentOS 6+

SSDs can be divided into three classes, based on throughput:
  • The first class of SSDs use a PCI-Express connection, which offers the fastest I/O throughput compared to other classes. This class also has a very low latency for random access.
  • The second class uses the traditional SATA connection, and features fast random access for read and write operations (though not as fast as SSDs that use PCI-Express connection).
  • The third class also uses SATA, but the performance of SSDs in this class do not differ substantially from devices that use 7200rpm rotational disks.
For all three classes, performance degrades as the number of used blocks approaches the disk capacity. The degree of performance impact varies greatly by vendor. However, all devices experience some degradation.
Enabling discard support is most useful when there is available free space on the file system, but the file system has already written to most logical blocks on the underlying storage device.
At present, ext4 is the only fully-supported file system that supports discard. 

To enable discard commands on a device, use the mount option discard. For example, to mount /dev/sda2 to /data with discard enabled, run:
mount -t ext4 -o discard /dev/sdb1 /data

By default, ext4 does not issue the discard command.
This is mostly to avoid problems on devices which may not properly implement the discard command. The Linux swap code will issue discard commands to discard-enabled devices, and there is no option to control this behavior.

There are basically two big things to do
-        enable discard/trim support in the file system
-       Limit write operations to the SSD. You want to enable discard to deal with underlying drive specific performance degradation that will happen over time

Move /tmp to ram.  This depends on how much ram you have and how much /tmp space you use, but it really helps to limit writes to the SSD

Change the mount options for your ext4 filesystem
-       change data from the default of ordered to writeback. This reduces the journal data to meta-data only, thus limiting writes.
-       change the commit value from the default of 5 seconds to 10, or 15. This gets you a 2 to 3x write savings, though you risk losing a bit more data if you lose power.
-       If you don't need access time records (mtime and ctime should be enough for most folks) disabling atime will also limit write operations. 
Ex:   /dev/sdb1        /      ext4     defaults,discard,data=writeback,noatime,commit=15     1 1
A/ mount file systems with the "noatime" option.
"noatime" prevents the file system from updating file access times.
"noatime" includes "nodiratime" (prevents directory access time updates).

Consider whether you need journals
            File system journals make file system reconstruction (fsck for
example) possible, and running without any journal makes catastrophic
file system failure far more likely. On the other hand, journals
require extra write operations, Sometimes it's easy enough to
reconstruct a file system that it's not worth the cost in terms of SSD
write operations.
echo "noop" > /sys/block/sda/queue/scheduler
in /etc/rc.d/rc.local.
OR
one can eliminate journaling altogether by doing this to a unmounted or read-only ext4
tune2fs -O ^has_journal /dev/sda1
 Then there will be no journal. While you are at it the command:
tune2fs -r 1024 /dev/sda1
will reduce the root-reserved blocks to 1k (4MB) 
Get rid of /tmp
Put it on ramdisk. The X11 server makes a huge number of tiny
writes to /tmp and if these flush to disk at a high rate it creates a
load of writes. Adding this line to /etc/fstab does the trick.
none /tmp tmpfs defaults 0 0

To enable trim, use the "discard' mount option in fstab for all mounted partitions from the SSD. The "swap" partition automatically uses TRIM. For example from /etc/fstab ....

Code:
UUID=ffc6a6fc-1bf3-4f25-ab17-067b0515e85a /   ext4    noatime,discard,data=writeback 1 1
UUID=24941fe7-6d23-4969-951e-0872d4b81b0e /home      ext4    noatime,discard,data=writeback 1 2
UUID=2bbebe51-c0f8-4296-ba0a-e715bf84dc67 swap       swap    defaults                       0 0


Few useful Commands

fdisk -u -l /dev/sdX
cat /sys/block/sda/queue/scheduler
Use iotop -oPa and sort by disk writes to see how much programs are writing to disk
Using “tune2fs –l /dev/sdb”, we can see the file system block size is 4KB with journal turned on.
Using “more /sys/fs/ext4/sdc/lifetime_write_kbytes” to see how much has been written to the disk so far





stop all application/System  services on the box,
unmount sdbX and sdcX
run tune2fs to set stride, stripe-width options
change mounting option on sdb, sdc to use noatime
mount again
start application/System services 



mkfs.ext4 -b 1024 -E stride=128,stripe-width=128 -O ^has_journal /dev/sda1
mkfs.ext4 -b 4096 -E stride=32,stripe-width=32 /dev/sda3 

Ref

No comments:

Post a Comment