Ubuntu + Solid State Drive (SSD): managing or disabling the swap space / page file



There are mixed views on using SSDs for page files / swap space. A frequent view encountered is to avoid having a page file or swap space on an SSD to minimise R/W activity, since FLASH chips have a limited lifespan. Wear levelling helps manage the SSD life but eventually the SSD will degrade and to prolong life paging operations should be avoided. 

An increasingly popular contrasting view is that most modern SSDs will become outdated before they die, therefore worrying about paging to an SSD shouldn't be a priority since the SSD will likely be outdated with cheaper and larger alternatives available before the SSD dies.

Read on for a couple of options for managing an SSD within Ubuntu...

Some options for managing the swap space:

Check your swap status
First off check your swap space status:
swapon -s


Disable swap space
If you have sufficient RAM you may be able to get away without having a swap space or page file however, this is not necessarily always the best option for performance and if you use hibernation will more than likely cause an issue.


To temporarily disable swap space for the current user session run:
swapoff


To persistently disable swap space edit the file system table:
sudo gedit /etc/fstab

Which will show your file system table, your swap partition will be the line with type 'swap' and options 'sw':
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' 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>
# swap was on /dev/sda5 during installation
UUID=17f0cb90-cde6-4e64-96a5-682c43b05aa1 none            swap    sw              0       0

Find the line with swap referenced and comment it out to prevent swap space from being mounted at the next boot on the SSD. This disables the swap partition:
# UUID=17f0cb90-cde6-4e64-96a5-682c43b05aa1 none            swap    sw              0       0


Alternatively change the swap space mount options to include noauto, so that the swap space is not automatically mounted on boot.
UUID=17f0cb90-cde6-4e64-96a5-682c43b05aa1 none            swap    sw,noauto              0       0


Move swap space to another disk
For those without enough RAM you will have a need for swap space to page to. In which case to preserve an SSD you can move the swap partition or page file to a traditional hard drive to avoid wearing out the SSD with frequent write operations. The performance benefit of using an SSD will reduce by moving swap space to a hard drive although lifespan may increase. If you are going to do this ideally:
  • you will need to use a fast hard disk;
  • the swap partition should be placed near the beginning of the drive; and
  • the hard drive should not be busy with other activity, to maintain swap peformance.
To move the swap space edit the file system table:
sudo gedit /etc/fstab

From:
UUID=17f0cb90-cde6-4e64-96a5-682c43b05aa1 none            swap    sw              0       0

To:
UUID=Insert_UUID_of_a_none_SSD_disk none            swap    sw              0       0

Automatic TRIM
The TRIM command allows an operating system to inform an SSD which blocks of data are no longer considered in use and can be wiped internally. Because low-level operation of SSDs differs significantly from mechanical hard disks, the typical way in which operating systems handle operations like deletes and formats results in progressive performance degradation of write operations on SSDs.  TRIM enables the SSD to handle garbage collection overhead, which would otherwise significantly slow down future write operations to the involved blocks, in advance.


Automatic TRIM has been supported in Linux since kernel 2.6.33 with the EXT4 file system. 
For automatic TRIM to work, the drive needs to be mounted with the "discard" option in fstab. 


To add this option to the file system table edit:
sudo gedit /etc/fstab

From:
<file system> <mount point>   <type>  <options>       <dump>  <pass>

# / was on /dev/sda1 during installation
UUID=94cc00eb-9abf-4df2-983a-66f190bc809e /               ext4    errors=remount-ro 0       1

To:
UUID=94cc00eb-9abf-4df2-983a-66f190bc809e /               ext4    discard,errors=remount-ro 0       1


1 comment:

Note: only a member of this blog may post a comment.