Because it is directly associated with the overall responsiveness, any operating system prefers to keep the users’ most frequently used data (programs, files etc) in RAM because data on RAM can be accessed extremely fast when compared to other storage mediums (disk drives, flash drives …).
That said however, since RAM is not cheap, its capacity is limited on most occasions and thus, when dealing with memory hungry programs (and while trying to find ‘room’ for opening new applications), the OS is going to have to move some of the currently unused data into another storage medium (temporarily), which is usually the disk drive.
This (special) location on a disk where data from RAM is moved into (it could be a file or a separate partition), is called ‘Swap Space’, in GNU/Linux. The process of moving data from RAM to a ‘Swap Space’ or moving data into RAM from a ‘Swap Space’, is called ‘page swapping’. Again, the OS only does this if it has no other choice because when compared to RAM, ‘Swap Space’ is very slow and thus loading programs or opening files can take a long time, which if not intelligent managed, can affect the OS’s responsiveness in a very negative manner.
As a result, OS developers have come up with few ways (mainly 2, that I am aware of) of decreasing the ‘page swapping’. One suggestion is to intelligently manage the data on RAM. The other method is to compress data that is about to be sent off to a ‘Swap Space’, within the RAM itself, with high compression ratios, so that RAM at the end can hold more data, hence reducing the need to move data into a horribly slow ‘Swap Space’.
‘Zswap’ in that sense, is a tool that was introduced with the 3.11 Kernel that compresses data which is about to be sent off to a ‘Swap Space’. ‘Zswap’ however is disabled by default, and if you are running under limited RAM capacity, then you can safely enable it in Ubuntu 13.10 (or any distribution that has 3.11 or newer Kernel installed) to see if it improves the overall system responsiveness. For enabling it, please follow the below procedure.
Open your Terminal window and enter the below command.
sudo gedit /etc/default/grub
This will open up the GRUB configuration file. Then as shown in the below screenshot, locate the ‘
GRUB_CMDLINE_LINUX_DEFAULT‘ line and put the below code between the quotation marks (make sure to add a ‘space’ after the existing quiet splash argument).
Then save your changes and enter the below command to update ‘GRUB’ entries.
Once that command finishes running, reboot the computer and when the next time the desktop loads ‘Zswap’ should be running.
Does it really work ?
Well, since it is unwise to take someone’s opinion just for the sake of it ;-), I decided to come up with a very simple test for measuring the performance of ‘Zswap’. Below is a brief info about my hardware.
Intel Core i3-2330M CPU, Intel HD 3000 GPU, 4GB RAM (DDR3), Toshiba 7200 RPM (320GB) SATA HDD, Intel N-1030 Wireless adapter, Realtek network adapter ('RTL8168'), LED display with 1366x768 resolution (60Hz/60FPS). It's a Dell Vostro V-131 notebook.
*. I first performed a clean installation of Ubuntu 13.10 and then I made sure that only 1GB of my 4GB RAM is available to Ubuntu 13.10 (you can easily do that by passing an argument using GRUB configuration file). Then I created a 1GB of ‘Swap Space’ (a ‘swap file’, not a partition) as well.
*. Later I added ‘GIMP’ image editor, VLC (they were both manually installed) to the ‘application launcher’. Then I rebooted the computer and once the desktop was loaded fully, I let it idle for about 30 seconds, then opened: ‘Gnome-Terminal’, Firefox, LibreOffice Writer/Calc/Impress, VLC, GIMP and Ubuntu Software Center.
*. When they were fully loaded I measured the ‘Swap Space’ usage through Gnome-System-Monitor utility. Then I closed all of them, and re-opened some of the applications (listed in the below graphs), each by its previous order of execution (gnome-terminal, Firefox …) and took a note of their individual loading times. Then I rebooted the computer and carried out the same test again and again for 3 times for getting average results.
After that was done, I enabled ‘Zswap’ and ran the same tests (3 times) all over again.
Why did you re-opened the apps and measured their loading times ?
Because if ‘Zswap’ actually works, then application loading times with it enabled should be shorter (compared to the application loading times with it disabled) as more application data can (and should) now be kept in RAM (which again improves their loading times since it minimizes the data exchange with the ‘Swap Space’ which is terribly slow). And the only way to know that for sure it to measure them :).
In any case, by using the gathered data, I came up with the below graphs for comparing.
As you can see, after enabling ‘Zswap’ the ‘Swap Space’ usage has actually increased by about 75.2 MiB (72%) which is the opposite of what it promises of being able to achieve.
Below are two graph of the (re) loading times of some of the individual applications.
Below is the second graph.
As you can see, except for LibreOffice Writer and despite the increased ‘Swap Space’ usage, ‘Zswap’ has been able to reduce the application loading times, though it is nowhere near being exceptional or useful, for that matter. I also noticed that the overall system responsiveness actually got worsened after enabling ‘Zswap’! (while opening all the applications for the first time).
As an example, ‘Compiz’ (window manager of ‘Unity’ desktop shell) dims-out application windows that are not responding, and when you open a lot of memory hungry apps, ‘Compiz’ sometimes dims them out for few seconds, even though in reality they are not actually stuck. This happened on both occasions, but it got worsened after enabling ‘Zswap’. Also, the whole PC got stuck (not being able to move the mouse …) for few seconds in all 3 tests after enabling ‘Zswap’ and it did not occur in such magnitudes while running tests without it being enabled.
So from the perspective of this simple test, ‘Zswap’ has failed because the responsiveness was not improved, though the re-loading of applications were improved slightly. However, a simple test as this one is not enough for making claims such as that says ‘Zswap’ is going to fail on your computer too, as one has to take many things into account before making such claims, but I tried hard for not being careless, thus I stand firmly behind the results.
In any case, I humbly advice anyone to actually enable ‘Zswap’ if you are running a computer with limited RAM availability to see whether it improves things or not. And if it makes things worse, you can always disable it with ease. You can read more detailed articles (with benchmark results) from here and here.
If you think the test is not that accurate in terms of trying to measure ‘Zswap’, then you are more than welcome to send suggestions, and correct me where I am wrong.