I have been noticing that if I copy a file to some storage device (the system's HDD, SSD, or to a thumbdrive) a small amount of data (20 - 30 MB) is written to the swap space - and the count increases. Yes, even the systems have available RAM.
Writing to the swap space makes the device very slow. Thrashing is the obvious case.
If I turn swap off before copying, the files gets copied just fine!
Here's a screenshot:
I am copying a big file to /dev/sda2. I have available RAM, yet some data is always written to the swap. This behaviour is same across all the devices I own, and the devices I got time to play around.
I tried changing the swappiness with this command command:
sysctl vm.swappiness=n # n for a value from 0..100
Tried turning the swappiness to 0, and also tried turning the swappiness to 100. The behaviour doesn't change. Any system monitor says I am having a good amount of available RAM. It still writes data to the swap.
posix_madvise(3)
/madvise(2)
to avoid this unwanted but to be expected behaviour. – A.B Apr 07 '19 at 08:01Also note the screenshot I provided is taken after a reboot. When the swap usage was 0, it slowly increased as the copy progressed. When the copy was over, it reduced a bit. But this behaviour makes the system quite slower if you are using HDDs for swap (and swapping on SSDs makes it's life shorter, both ways you don't want that).
– 15 Volts Apr 07 '19 at 09:28