I expected all the RAM to be used before experience swapping, but I have this strange result in htop:

Screenshot of htop running on the server.

Meaning that on my server with 24GB of RAM, my software swapped 1GB of memory to disk, when they only use a total of 23GB of memory.

I didn’t expect swapping when using less memory than is available on the hardware… Why is the server doing this?

  • "I expected all the RAM to be used before to experience a swap..." Why? Search Super User for swap.
    – Ron Maupin
    Dec 26, 2016 at 0:00
  • What's your swappiness setting? From the looks of it, this is normal; 90.8% of the server's RAM is in use, which is really close to full; most systems will swap when the memory is nearly full. You can force the system to not swap unless absolutely necessary by setting swappiness to 0, but this is not recommended.
    – bwDraco
    Dec 26, 2016 at 0:19
  • Based on your previous questions, I'm assuming your system is running Linux. If this isn't the case, be sure to edit your question to reflect this.
    – bwDraco
    Dec 26, 2016 at 0:41
  • Its also worth considering yoiu have nearly no ram on standby or such. Your ram is really getting heavily utilised.
    – Journeyman Geek
    Dec 26, 2016 at 1:17

2 Answers 2


This behavior is controlled through a kernel setting called vm.swappiness, which may be set on a range from 0 to 100. The default value of 60 will cause the system to swap somewhat before physical memory is completely full, which helps maintain performance under memory pressure, while not swapping so much as to degrade performance due to thrashing.

This can be disabled by setting swappiness to 0, in which case the system will not swap unless absolutely necessary. This may make sense if you usually have lots of free RAM. However, performance will fall off a cliff the moment your system's physical memory is completely filled as the system is suddenly forced to swap at an inopportune time when an application needs memory, rather than in advance, and is not recommended in your case as your server is running close to full.

It's probably better for you to set swappiness to a low (but nonzero) value like 10, which will reduce unnecessary swapping while not waiting until the last moment to free up RAM when a program needs it. The best setting depends on your environment, so experiment with different settings until you get the best results.

To change the swappiness setting, write the desired value to /proc/sys/vm/swappiness using echo as root. To make permanent changes, add a vm.swappiness line to /etc/sysctl.conf (replace 10 with your desired value as needed):

vm.swappiness = 10

Operation systems will not wait for last second to swap memory for performance reasons. The implementation will depend on the operation systems you are using, but most modern operation systems will swap well before physical memory is full. Swapping usually occur when the system is not on full load so when more work comes, it has enough RAM and is ready to handle the work.

For desktop systems, some operation systems (ex.: Windows) will even pre-load softwares you often use into memory and put data that is not currently used onto hard disk. This does not work well when the system is freshly installed but will become better and better as you use it.

  • I'm not sure the latter paragraph (describing a technology called SuperFetch) really applies here. The system simply preloads the app data into unused memory, which is immediately freed when an applications needs the memory. Other than that, +1.
    – bwDraco
    Dec 26, 2016 at 0:23
  • @bwDraco Yes, those memory will be freed if "unexpected" workload comes and another application need it, but Windows will still use Paging file (which is on hard drive) to bring more "SuperFetched" data into RAM. i.imgur.com/8hnfebN.png Dec 26, 2016 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.