Ubuntu's SSD-oriented optimization solution, ubuntussd
.
.
.
.
.
First, let's look at the LZ partition:
>$ sudo fdisk -lDisk /dev/sda: 120.0 GB, 120034123776 bytes255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0001cbca Device Boot Start End Blocks Id System/dev/sda1 * 2048 206847 102400 83 Linux/dev/sda2 206848 234438655 117115904 83 LinuxDisk /dev/sdb: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk identifier: 0x000a1ddb Device Boot Start End Blocks Id System/dev/sdb1 2048 1922080767 961039360 83 Linux/dev/sdb2 1922082814 1953523711 15720449 5 ExtendedPartition 2 does not start on physical sector boundary./dev/sdb5 1922082816 1953523711 15720448 82 Linux swap / Solaris
Two hard disks:/dev/sda and/dev/sdb. Therefore, only/dev/sda is optimized.
/Dev/sda1 is/boot partition,/dev/sda2 is/partition.
1. Optimized configuration for/etc/fstab
>$ sudo vim /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).## <file system> <mount point> <type> <options> <dump> <pass># / was on /dev/sda2 during installationUUID=d9a9c636-a561-4b71-acc5-51d3204c75ba / ext4 noatime,discard,errors=remount-ro 0 1# /boot was on /dev/sda1 during installationUUID=1716571d-14c5-4d09-9e69-8c97d5543de1 /boot ext4 noatime,discard,defaults 0 2# /home was on /dev/sdb1 during installationUUID=aa94f45f-8dcb-45c8-bef4-c8adace32a3b /home ext4 defaults 0 2# swap was on /dev/sdb5 during installationUUID=d93e0ac2-c372-470c-9dd6-1e17a9242ee4 none swap sw 0 0tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0
The red and bold parts above are manually added by LZ. The following LZ explains in detail the meaning of the manually added parts.
NoatimeIndicates that the file access time is not updated when the file is accessed, which can reduce the write operations on the disk.
There are three time options for Linux file systems. For more information, see LZ's blog "(3) Documents and directories for learning advanced programming in Unix environments (APUE) together".
DiscardIndicates that TRIM is enabled.
TRIM has two main functions: 1. Improve the hard disk write efficiency; 2. Improve the SSD life based on the average write algorithm.
For more information, see.
Linux Kernel supports TRIM commands from 2.6.33. Therefore, first check the kernel version to determine whether the operating system supports TRIM:
>$ uname -aLinux yuhuashi-Linux 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux>$
The kernel version of LZ is 3.small, so TRIM is supported.
Next, check whether SSD supports TRIM. Although most SSDS currently support TRIM, not all SSDS support TRIM.
$ sudo hdparm -I /dev/sda | grep TRIM * Data Set Management TRIM supported (limit 8 blocks)$>
The display of information similar to this is supported. The display of different SSDS may be different.
Of course, the above two configurations do not have dependency, so you can configure the first or only the configuration.
At the end of the file, mount the/tmp,/var/tmp, And/var/log directories to the memory. This has two purposes:
1) Acceleration by memory: the memory speed is much faster than that of the hard disk. attaching such frequently read/write directories to the memory can greatly improve their read/write speed.
2) Reduce the number of writes to SSD: This temporary directory usually stores many small files and reads and writes frequently. To improve the SSD life, mount them to the memory.
Note: the/var/log directory above is the directory where system logs are located. If it is mounted to the memory, all these logs will be lost after shutdown!Of course, for individuals, the historical system logs are usually useless, so LZ also mounts them to the memory.
Check whether the above configuration takes effect:
>$ sudo mount -oremount /dev/sda1>$ mount -l/dev/sda2 on / type ext4 (rw,noatime,discard,errors=remount-ro)tmpfs on /tmp type tmpfs (rw,noatime,mode=1777)tmpfs on /var/tmp type tmpfs (rw,noatime,mode=1777)tmpfs on /var/log type tmpfs (rw,noatime,mode=1777)/dev/sda1 on /boot type ext4 (rw,noatime,discard)/dev/sdb1 on /home type ext4 (rw)>$
As you can see,/dev/sda1 and/dev/sda2 already have noatime and discard Mount attributes; and/tmp,/var/tmp, And/var/log have been mounted as tmpfs. This indicates that the above configuration is successful.
2. Reduce SWAP Switching
LZ allocates a large number of SWAP instances, but it is found that SWAP space is rarely used in actual use, and LZ never uses the sleep function, so it is also possible to do not allocate or less SWAP instances.
Of course, the premise is that your memory is sufficient for your daily use. LZ is 8 GB memory.
The SWAP of LZ is allocated on the mechanical hard disk. It doesn't matter if the SWAP is used less frequently.
In fact, this step is generally only applicable to children's shoes that allocate SWAP to SSD. For example, if SWAP is allocated to a mechanical hard disk like LZ, it doesn't matter if it is not set.
>$ suPassword:># echo 1 > /proc/sys/vm/swappiness>#
Between 0 and 100, the larger the value, the larger the switching amount.
3. Use noop I/O Scheduling Algorithm
Noop is equivalent to implementing the simplest FIFO queue. Since SSD does not need to be addressable like a mechanical hard disk, the simplest scheduling algorithm can also improve efficiency accordingly.
> $ SuPassword: # view the current scheduling algorithm, the following selected by brackets indicates the current scheduling algorithm> # cat/sys/block/sda/queue/schedulernoop [deadline] cfq # modify the scheduling algorithm and view it again> # echo noop>/ sys/block/sda/queue/schedue> # cat/sys/block/sda/queue/schedue [noop] deadline cfq # LZ found that this method can only be set temporarily, the next restart changes back, so you need to modify the system startup script> # vim/etc/rc. local # Add this sentence at the bottom (above exit 0), save and exit, and use the following cat (1) After restart) command to verify echo noop>/sys/block/sda/queue/schedue> #
4. Disable the EXT4 log function.
This step is placed at the end because it is required to enter LiveCD. Therefore, after installing the system, you should finish other optimization work for the first time, otherwise, you will need to restart the system and perform the optimization.
The purpose of disabling file system logs is to reduce the number of SSD writes for I/O operations and improve the SSD life.
However, the log of shutting down the file system is more likely to cause damage to the file system, such as sudden power failure. However, LZ uses a laptop and is not afraid of sudden power outages. It is worth a try to improve the life of SSD.
1) Restart LiveCD.
2) execute the command in shell:
# Modify the root password. Because the command must be run under root, you must first obtain the root permission of LiveCD.> $ Sudo passwdRootEnter a new UNIX Password: enter a new UNIX Password: passwd: the password has been successfully updated> $ su password: # view the device file in the partition, fortunately, the file name of the device is the same as that viewed in the system, so that you do not have to compare it again.> # Fdisk-LDisk/dev/sda: 120.0 GB, 120034123776 bytes255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectorsUnits = sector of 1*512 = 512 bytesSector size (logical/physical ): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes/512 bytesDisk identifier: 0x0001cbca device start end block Id system/dev/sda1 * 2048 206847 102400 83 Linux/dev/sda2 206848 234438655 117115904 83 LinuxDisk/dev/sdb: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectorsUnits = sector of 1*512 = 512 bytesSector size (logical/physical ): 512 bytes/4096 bytesI/O size (minimum/optimal): 4096 bytes/4096 bytesDisk identifier: 0x000a1ddb device start end block number Id system/dev/sdb1 2048 1922080767 961039360 83 Linux/dev/sdb2 1922082814 1953523711 15720449 5 extended partition 2 not started at the physical sector boundary. /Dev/sdb5 1922082816 1953523711 15720448 82 Linux swap/Solaris # Shut down the file system log of the/boot partition. This is for the partition, so it should be done on each SSD partition.> # Tune2fs-O ^ has_journal/dev/Sda1Tune2fs 1.42.9 (4-Feb-2014) # disable/partition file system logs> # Tune2fs-O ^ has_journal/dev/Sda2Tune2fs 1.42.9 (4-Feb-2014) # Run the file system detection. It is said that not running may cause file system errors. LZ has not personally challenged it, so it is better to run it. This is also for partitioning, so we need to do it on every partition that closes the file system log.> # E2fsck-f/dev/Sda1E2fsck 1.42.9 (4-Feb-2014) Step 1: Check inode, block, and size Step 2: Check directory structure Step 2: Check directory connectivity Pass 4: Checking reference counts Step 2: check cluster profile information/dev/sda1: 301/25688 files (1.0% non-contiguous), 38564/102400 blocks> # E2fsck-f/dev/Sda2E2fsck 1.42.9 (4-Feb-2014) Step 1: Check inode, block, and size Step 2: Check directory structure Step 2: Check directory connectivity Pass 4: Checking reference counts Step 2: check the cluster overview information/dev/sda2: 182739/7323648 files (0.2% non-contiguous), 1599116/29278976 blocks # The work on LiveCD is finished, and restart the system to enter the system> # Reboot
> #
Because the above content is large, LZ marks the commands that need to be manually executed in red.
3) after the system is restarted, verify whether the system is successful:
>$ dmesg | grep EXT4[ 3.787513] EXT4-fs (sda2): mounted filesystem without journal. Opts: (null)[ 4.194035] EXT4-fs (sda2): re-mounted. Opts: discard,errors=remount-ro[ 4.362051] EXT4-fs (sda1): mounted filesystem without journal. Opts: discard[ 4.382329] EXT4-fs (sdb1): mounted filesystem with ordered data mode. Opts: (null)>$
A prompt similar to the bold font above indicates that the configuration is successful. If the blue font above is displayed, the configuration does not take effect. Of course, the configuration takes effect for LZ, because LZ only closes the file system logs of sda1 and sda2. Sdb1 is not a solid state drive, and LZ does not close its file system logs.
References:
1. Full record of SSD Hard Drive Optimization in Ubuntu
2. What is the role of ssd trim?
3. A summary of four IO Scheduling Algorithms in linux 2.6 kernel