0

Is there a way to completely restrict using swap if there are buffers/cache in use? And use swap only to prevent Out-Of-Memory Killer.

Is there a way to forbid using swap if are there still buffers/caches that could be flushed?

What options should I tweak? My guess would be something along the lines of

swappiness 
vm.dirty_bytes
vm.dirty_background_bytes 
vm.dirty_bytes

The reason why I need it: I have proprietary software that doesn't work properly if a swap is used, but the system consumes a lot of buff/cashe.

If I manually (and regularly every 2-3 hours) clean buff/cache by using this command

sync; echo 3 > /proc/sys/vm/drop_caches 

everything works fine.

But if I just let it be, the software starts to perform badly, even if I have set up vm.swappiness=1, it just give it a little bit more time to live ...

AdminBee
  • 22,803
  • 1
    Have you tried disabling swap altogether? – Stephen Kitt Dec 29 '21 at 18:34
  • How does the application even know that part of it has been swapped out? Swapping should be transparent. – doneal24 Dec 29 '21 at 18:47
  • Swapping in the Linux kernel and other OSes which support paging/swapping out is normally "transparent" in terms of being invisible for the application - it simply doesn't need to know it's been swapped out. – Artem S. Tashkinov Dec 29 '21 at 20:22
  • 5
  • the application doesn't know that it is being swapped, but because I use usual hard drives, which I can't change to SSDs, the application starts to break because of the timeout (it takes more time to access memory in the swap area on the HDD).

    Yep, I tried to disable swap altogether, but It didn't work well. Because there are rare cases when there is a high load it is better than the application giving timeout error, which just breaks because out of memory error.

    – glorsh66 Dec 31 '21 at 16:49
  • It is possible to limit a single app from being swapped. This is easier if it is containerized with docker. Although you might need to enable it in the kernel. If this is a Java app that might be desirable because you can otherwise limit the memory used by Java – Philip Couling Jan 11 '22 at 10:28
  • @ArtemS.Tashkinov Java webserver apps are just one example edge cases were that isn't quite true. They sit on huge chunks of RAM for a very long time, not using it... and then occasionally the garbage collector kicks in and locks the whole app while it re-reads 80% of it's memory. The result is all your users have to sit and wait while it claws back 2GB (or more) from swap just to check that it still needs it. It's pretty annoying to the users, but it's caused by the fundamental way Java manages memory. – Philip Couling Jan 11 '22 at 10:35
  • Which kernel version your machine uses? – aviro Jan 19 '22 at 08:59

0 Answers0