4

I've a AWS ec2 instance running Ubuntu 16.04 with 64 GB RAM and have a swap file configured for 8GB. During a nightly batch process which syncs the backup data from an EBS volume of this instance to a S3 bucket, the swap memory is almost 100% utilised but the main memory still has abundant space in the range of 10-15 GB available.

Here's the swappiness default:

$ cat /proc/sys/vm/swappiness
60

Is it worrying? If yes, shall I add more swap space by having a larger swap file or opt for swap partitions instead?

Deb
  • 143
  • 1
  • 4

3 Answers3

5

This observation where you see significant swap use after a nightly batch job despite having plenty of RAM is not worrying. It is especially not worrying, because it happens during the night with no users in front of the computer. Thus,your user experience is in no way affected by this use of swap. Likely, as it stands now, your specific batch processes are performed with maximum efficiency and speed.

This high swap usage would only be of practical concern if you were in front of the computer during that time, doing other tasks. A high tendency to swap would then lead at times to a slight delay in response of the user interface, as certain RAM of your applications needs to be retrieved from swap as you need it. Having a lower swap tendency will decrease the likelihood that software is swapped out, and that you experience delays. You will perceive this as snappier performance, i.e. instant response of the system throughout, but at the expense of other processes that have less "breathing room" to do their activities because you keep occupying the RA even for processes yo do not immediately need again.

vanadium
  • 88,010
2

If you want a stricter swap policy you can lower the swapiness setting you posted. This answer nicely explains what swapiness is all about.

In my personal experience I've seen that a swapiness of 10 works fine if you want to utilize as much of your RAM as possible without losing system stability.

2

This is not necessarily cause for concern and it doesn't indicate reducing or tweaking swappiness.

The answer by vandium is pretty comprehensive but I'd also like to mention a couple of things.

It can help to think of lower swappiness values as riskier, and higher values are more conservative. That is, lower swappiness values will wait until the memory situation is more dire and strained with little left for cache before it swaps while a higher swappiness will swap when the available memory and cache size is only slightly threatened. Many people think of reducing swappiness as a blanket way to reduce swapping but it's so often the case that you will still swap, but at a later time when your system is more desperate for memory. The real blanket solution to reduce swapping is adding more RAM.

Secondly, the behaviour for swapped data is for it to remain in swap until it's requested again, instead of being swapped out as soon as the memory demand decreases again. Some people see this and think it undesirable; they think swap should be avoided, but the justification for this is that the performance penalty for swapping out is around the same as swapping in, so the system avoids unnecessary swapping out. If you do end up needing something that's in swap, it's a swap out that would have happened anyway at some stage but by delaying it until it's requested it leaves the available memory and cache space nice and high (for good system performance, and for better response in case memory demand quickly goes back to its previous high again, such as if the high memory event was on a schedule) and avoids unnecessary I/O.

thomasrutter
  • 36,774