So I bought a new SSD the other day. After reading about SSD issues with SWAP partitions i decided to investigate further.
I found out you can use something called zram.
The zram module creates RAM based block devices named /dev/zram<id>(<id> = 0, 1, ...). Pages written to these disks are compressed and storedin memory itself. These disks allow very fast I/O and compression providesgood amounts of memory savings.
Zram actually creates a loopback device which is stored in ram. It can be used for SWAP (vritual memory partitions); Storing cache files for web servers; storing static files; and many other things!
The cool thing is that it's now built-in as a Linux module!
Let's start b y using it as a swap replacement:
Remove swap from or place it into a #
sudo vim /etc/fstab
Put the following in /etc/init/zramswap.conf
description "Initializes zram swaping"start on runlevel stop on runlevel [!2345]pre-start script# load dependency modulesmodprobe zram num_devices=2# initialize the devices using 512 ram eachecho 536870912 > /sys/block/zram0/disksizeecho 536870912> /sys/block/zram1/disksize# Creating swap filesystemsmkswap /dev/zram0mkswap /dev/zram1# Switch the swaps onswapon -p 5 /dev/zram0swapon -p 5 /dev/zram1end scriptpost-stop script# Switching off swapswapoff /dev/zram0swapoff /dev/zram1rmmod zramend script
sudo start zramswap
Or as an alternative change swappiness
/vm.swappiness and change its value as desired. If vm.swappiness does not exist, add it to the end of the file like so:
or install zram swap from ubuntu launchpad..
Now you won't have a physical SWAP partition anymore, only a virtual one. This is best used with 8GB RAM or more.
It's sometimes a little slower but hey, that's the memory compression working:D