Someone brought to my attention that if an application is using swap file (when system RAM is very low) it increases the disk I/0 and as a result of that, CPU use % and CPU Load increases.
Is this true or was that guy completely off-track?
Someone brought to my attention that if an application is using swap file (when system RAM is very low) it increases the disk I/0 and as a result of that, CPU use % and CPU Load increases.
Is this true or was that guy completely off-track?
Swap is paging memory to disk. If you've got something that's shunting things into swap from RAM, you're going to see:
How quantifiable these are or how much of an effect they have is completely debatable but follow Barney's one golden rule: More RAM is always better.
The Swap space is the area on the HDD or SSD which forms a part of the Virtual Memory of your PC. The Virtual Memory is simply a combination of your physical memory which is called RAM and the swap space which is call SWAP. The Swap space holds, temporarily, the memory that is inactive. This is because your system decides that it needs physical memory for active processes and it has insufficient unused physical memory available. If the system happens to need more memory or space, inactive memory pages in the physical memory are then moved to the swap space, freeing up that physical memory for other uses.
Since physical memory or RAM is much faster than SWAP, which is found in a HDD or SDD, typically as a partition, the access time is slower. You can however get a faster speed if you use a SSD (Solid State Drive) instead of a HDD (Hard Disk Drive, Mechanical ones).
With this in mind, the answer to your question is, in both cases yes. Yes, using SWAP will increase your CPU usage and the Disk I/O. Of course the CPU usage will be minimal, but the Disk usage won't be. The reason is that the CPU is only used to see where and what can be stored/retrieved from swap (which is a very fast procedure).
For the Disk I/O it's different. Since Swap is in the HDD or SSD, it will also use the Disk I/O while you use other programs, and it will most likely have higher priority than other user programs.
So for your question, you do not need to worry much about CPU usage than Disk usage.
To enhance performance and lower disk usage you can do a couple of things:
Change from an HDD (Typically 5400 RPM to 7200 RPM) to an SSD. The difference is 2x to 10x faster Disk performance. This will drastically change the overall performance on your system.
Add more RAM. If you have more memory RAM, the chance the system will need to swap memory will be lower, increasing the overall performance while still using all available RAM.
Use a Desktop that uses less RAM. This also expands to other apps. It is not the same to use KDE or Gnome than to use LXDE or XFCE. It is also not the same to use abiword or even nano o vim than to use LibreOffice.
Now for the last point. What you heard about Increased Disk I/O increasing CPU load. This is true, simply because:
The less RAM you have, the more the SWAP space will be needed for your Apps. The more SWAP space is used, the more CPU time will be needed to store/retrieve Swap information.
One depends on the other. So increasing the amount of RAM will directly benefit you in lowering SWAP usage and lowering CPU usage.
Here is an image to illustrate the effect:
Every time the CPU load jumped, it was because the Swap was been read/written to.
There will some SOME increase (as the kernel has to track the location of the paged memory between RAM and secondary storage), but I doubt it will be much as the kernel accesses the disk directly , bypassing caching and file-system when paging in/out of the swap file/partition. The IO performed is asynchronous, so the CPU is not waiting (causing other processes to slowdown unnecessarily).
For a full description of the swap management read https://www.kernel.org/doc/gorman/html/understand/understand014.html you will see that it is not a CPU intensive process, most of the work is around managing page mappings, not the transfer of data.
It is the reverse actually: when programs have to stop and wait for disk IO, cpu usage drops ( since they aren't using it while waiting ). Obviously lots of data being swapped in and out to disk is disk IO.