Solid State Drive tweaks: Difference between revisions

From WickyWiki
mNo edit summary
 
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
20110923 SSD, Ubuntu 11.04 Natty Narwhal 64 bit
[[Category:Ubuntu]]
 
[[Category:Ubuntu System]]
[[Category:201110]]
* https://wiki.ubuntu.com/MagicFab/SSDchecklist
* https://wiki.ubuntu.com/MagicFab/SSDchecklist


== Prepare ==
==Prepare==


# check for ssd firmware updates
# check for ssd firmware updates
Line 10: Line 11:
Note: in a dual boot configuration with Windows 7, Windows will not boot after changing AHCI. You will need to make some changes in Windows before proceeding.
Note: in a dual boot configuration with Windows 7, Windows will not boot after changing AHCI. You will need to make some changes in Windows before proceeding.


== Format SSD ==
==Format SSD==
 
'''Update: it is better to have journaling enabled for possible fault correction. Skip this section.'''


Format drive as ext4, journaling disabled.
Format drive as ext4, journaling disabled.


{| style="color:black; cellpadding="15%" cellspacing="0" border="1"
MAKE SURE WE ARE TALKING ABOUT THE RIGHT DRIVE HERE
| style=";background-color:orange;" |
; MAKE SURE WE ARE TALKING ABOUT THE RIGHT DRIVE HERE
|}


Physical drive: "sdb", partition "sdb1"
Physical drive: "sdb", partition "sdb1"
Line 35: Line 35:
</syntaxhighlight>
</syntaxhighlight>


== TRIM and access time ==
==Access time==
 
The "relatime" option writes the time-of-access to disk and causes unnecessary additional writes to disk. Mount volumes using the "noatime" option in stead of the "relatime" option.
 
<syntaxhighlight lang=bash>
sudo cp /etc/fstab ~/fstab-backup
sudo gedit /etc/fstab
</syntaxhighlight>
 
Notice the location of 'noatime,'. Do not change anything else:
 
<blockquote>
<syntaxhighlight lang=bash>
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /              ext4    noatime,data=writeback,errors=remount-ro 0      1
</syntaxhighlight>
</blockquote>
 
==TRIM==
 
The TRIM function prepares (wipes) free space and prevents significant slowdown of writes as the drive is used.
 
===Manual TRIM===
 
<syntaxhighlight lang=bash>
sudo fstrim -v /
</syntaxhighlight>


The TRIM function prepares (wipes) free space for faster writing. Enable the TRIM command support using the "discard" mounting option.
Tip: use this tool to TRIM for example every 30 minutes using crontab. See [[MySQL#Schedule_a_backup_with_crontab]] for an example.


===Discard TRIM===


The "relatime" option writes the time-of-access to disk and causes unnecessary additional writes to disk. Mount volumes using the "noatime" option in stead of the "relatime" option
'''Note: this method will cause trimming with every deletion and can slowdown deletions.'''


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
sudo cp /etc/fstab ~/fstab-backup
sudo gedit /etc/fstab
sudo gedit /etc/fstab
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /              ext4    noatime,discard,data=writeback,errors=remount-ro 0      1
</syntaxhighlight>
</syntaxhighlight>
 
Notice the location of '''discard,''', do not change anything other:
 
<blockquote>
<syntaxhighlight lang=bash>
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /              ext4    noatime,discard,data=writeback,errors=remount-ro 0      1
</syntaxhighlight>
</blockquote>


Reboot. To test if TRIM is working look here:
Reboot. To test if TRIM is working look here:
Line 52: Line 84:
* http://askubuntu.com/questions/18903/how-to-enable-trim
* http://askubuntu.com/questions/18903/how-to-enable-trim


== Swap ==
==Swap==
Lower the likelyness of swap
Lower the likelyness of swap
Line 59: Line 91:
sudo gedit /etc/sysctl.conf
sudo gedit /etc/sysctl.conf


# add/edit these lines
# add/edit these lines


# minimum swappiness
# minimum swappiness
vm.swappiness=0
vm.swappiness=0


# weak inode cache schrinking
# weak inode cache schrinking
vm.vfs_cache_pressure=50
vm.vfs_cache_pressure=50
</syntaxhighlight>
</syntaxhighlight>


== I/O scheduler ==
See also
* [[Ubuntu freezing with high memory usage]]
 
==I/O scheduler==


* change I/O scheduler strategy to "noop" (or "deadline")
Change I/O scheduler strategy to "noop" (or "deadline")


Note: there are alternatives to add this option to grub or to install a "sysutils" package
Note: there are alternatives to add this option to grub or to install a "sysutils" package
Line 77: Line 112:
cat /sys/block/sda/queue/scheduler  
cat /sys/block/sda/queue/scheduler  
</syntaxhighlight>
</syntaxhighlight>
noop anticipatory deadline [cfq]
noop anticipatory deadline [cfq]


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 83: Line 118:
</syntaxhighlight>
</syntaxhighlight>


# add thise lines before exit 0 for drive "sda"
Add these lines before exit 0 for drive "sda"
echo noop > /sys/block/sda/queue/scheduler
 
# reboot
<syntaxhighlight lang=bash>
echo noop > /sys/block/sda/queue/scheduler
</syntaxhighlight>
 
Reboot


== Temporary files ==
==Temporary files==


Use RAM disk for temporary files to reduce the number of writes to the SSD.
Use in-memory disk for temporary files to reduce the number of writes to the SSD.


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 103: Line 142:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
df
df
tmpfs xxxxxx yyyyy zzzzzz n% /tmp
...
tmpfs xxxxxx yyyyy zzzzzz n% /tmp
...
</syntaxhighlight>
 
'''Move firefox cache to the in-memory disk /tmp'''
 
In Firefox go to url "about:config"
 
* Look for the setting "browser.cache.disk.parent_directory"
* Create this setting as a New String if it does not exist.
* Set the value to "/tmp".
* Restart Firefox
* Folders as "/tmp/Cash/0", "/tmp/Cash/1", "/tmp/Cash/2" etc will be created by Firefox.
 
==Zeitgeist==
 
Zeitgeist is an activity logger that regularly writes to a database in your home folder. The following will prevent this without removing this functionality for all users:
 
<syntaxhighlight lang=bash>
rm ~/.local/share/zeitgeist/activity.sqlite
</syntaxhighlight>
 
The file will be recreated and be almost empty, then:
 
<syntaxhighlight lang=bash>
chmod -rw ~/.local/share/zeitgeist/activity.sqlite
zeitgeist-daemon --replace
</syntaxhighlight>
 
To enable again do:
 
<syntaxhighlight lang=bash>
chmod +rw ~/.local/share/zeitgeist/activity.sqlite
zeitgeist-daemon --replace
</syntaxhighlight>
 
==Monitor I/O activity==
 
To monitor I/O activity, user left/right to change sort order:
 
<syntaxhighlight lang=bash>
sudo apt-get install iotop
sudo iotop -a
</syntaxhighlight>
</syntaxhighlight>


Move firefox cache to the earlier created /tmp
Monitor files open for writing, in this example:
* firefox
* zeitgeist
 
<syntaxhighlight lang=bash>
sudo lsof -c firefox -c zeitgeist -r 5 | grep -e "[[:digit:]]\+w"
</syntaxhighlight>


# in firefox go to "about:config"
==Startup problems without journal==
# filter for "browser.cache.disk.parent_directory" Set the value to "/tmp"


== Other ==
Note: not needed if you do not turn of the journal.


Did this from other Ubuntu and then it booted
Did this from other Ubuntu and then it booted
Line 121: Line 208:
</syntaxhighlight>
</syntaxhighlight>


* moved aMule and Vuze folders to Data drive, NB: aMule will reset the folder when it is not found
Moved aMule and Vuze folders to Data drive, NB: aMule will reset the folder when it is not found

Latest revision as of 19:24, 20 March 2017

Prepare

  1. check for ssd firmware updates
  2. Enable SATA AHCI mode in the BIOS (if available)

Note: in a dual boot configuration with Windows 7, Windows will not boot after changing AHCI. You will need to make some changes in Windows before proceeding.

Format SSD

Update: it is better to have journaling enabled for possible fault correction. Skip this section.

Format drive as ext4, journaling disabled.

MAKE SURE WE ARE TALKING ABOUT THE RIGHT DRIVE HERE

Physical drive: "sdb", partition "sdb1"

	
sudo fdisk -l /dev/sdb | grep sectors
255 heads, 63 sectors/track, 7297 cylinders
	
sudo fdisk -H 255 -S 63 /dev/sdb
 "d" delete partition
 "n" new partition, primary, 1
 "w" to write partition table and exit
sudo mke2fs -t ext4 -O ^has_journal /dev/sdb1

Access time

The "relatime" option writes the time-of-access to disk and causes unnecessary additional writes to disk. Mount volumes using the "noatime" option in stead of the "relatime" option.

sudo cp /etc/fstab ~/fstab-backup
sudo gedit /etc/fstab

Notice the location of 'noatime,'. Do not change anything else:

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /               ext4    noatime,data=writeback,errors=remount-ro 0       1

TRIM

The TRIM function prepares (wipes) free space and prevents significant slowdown of writes as the drive is used.

Manual TRIM

sudo fstrim -v /

Tip: use this tool to TRIM for example every 30 minutes using crontab. See MySQL#Schedule_a_backup_with_crontab for an example.

Discard TRIM

Note: this method will cause trimming with every deletion and can slowdown deletions.

sudo gedit /etc/fstab

Notice the location of discard,, do not change anything other:

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /               ext4    noatime,discard,data=writeback,errors=remount-ro 0       1

Reboot. To test if TRIM is working look here:

Swap

Lower the likelyness of swap

	
sudo gedit /etc/sysctl.conf

# add/edit these lines

# minimum swappiness
vm.swappiness=0

# weak inode cache schrinking
vm.vfs_cache_pressure=50

See also

I/O scheduler

Change I/O scheduler strategy to "noop" (or "deadline")

Note: there are alternatives to add this option to grub or to install a "sysutils" package

cat /sys/block/sda/queue/scheduler

noop anticipatory deadline [cfq]

	
sudo gedit /etc/rc.local

Add these lines before exit 0 for drive "sda"

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

Reboot

Temporary files

Use in-memory disk for temporary files to reduce the number of writes to the SSD.

sudo gedit /etc/fstab

Add after the last line (exact text)

tmpfs   /tmp  tmpfs  nodev,nosuid,noexec,mode=1777  0 0

After reboot, using df you should see a line like

df
...
tmpfs xxxxxx yyyyy zzzzzz n% /tmp
...

Move firefox cache to the in-memory disk /tmp

In Firefox go to url "about:config"

  • Look for the setting "browser.cache.disk.parent_directory"
  • Create this setting as a New String if it does not exist.
  • Set the value to "/tmp".
  • Restart Firefox
  • Folders as "/tmp/Cash/0", "/tmp/Cash/1", "/tmp/Cash/2" etc will be created by Firefox.

Zeitgeist

Zeitgeist is an activity logger that regularly writes to a database in your home folder. The following will prevent this without removing this functionality for all users:

rm ~/.local/share/zeitgeist/activity.sqlite

The file will be recreated and be almost empty, then:

chmod -rw ~/.local/share/zeitgeist/activity.sqlite
zeitgeist-daemon --replace

To enable again do:

chmod +rw ~/.local/share/zeitgeist/activity.sqlite
zeitgeist-daemon --replace

Monitor I/O activity

To monitor I/O activity, user left/right to change sort order:

sudo apt-get install iotop
sudo iotop -a

Monitor files open for writing, in this example:

  • firefox
  • zeitgeist
sudo lsof -c firefox -c zeitgeist -r 5 | grep -e "[[:digit:]]\+w"

Startup problems without journal

Note: not needed if you do not turn of the journal.

Did this from other Ubuntu and then it booted

sudo tune2fs -o journal_data_writeback /dev/sdb1

Moved aMule and Vuze folders to Data drive, NB: aMule will reset the folder when it is not found