We are trying to tune our application servers, which are Amazon Linux machines ...

[myuser@mymachine ~]$ uname -a
Linux mymachine.myco.org 4.3.17-14.25.amzn1.x86_64 #1 SMP Wed May 10 01:58:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

We only have a JBoss process running on our machine (of process we have started, that is). The machine has 30GB of memory and the Jboss process allocates 25GB (using the "-Xmx25600m" Java option). When will the machine start using swap space? When I run "free -m", I don't see any swap space used, which is what I expect ...

[myuser@mymachine ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:         30103       7238      22864          0        172       4438
-/+ buffers/cache:       2627      27475
Swap:            0          0          0

I thought swap will only be used if we start running out of memory, but am told that is not necessarily true. When will the machine start using swap space?

3 Answers 3


Linux will generally try to keep things in ram, any only start swapping when you run out of available ram (that is total ram used by applications, buffers and cached files). When to start swapping is configurable however so can vary depending on your setup and is controlled by the swappiness value. To see what the current swappiness value is set to run

cat /proc/sys/vm/swappiness

Most systems default to value about 60. The lower the value the more aggressive the kernel will work to keep things inside ram and setting it to 0 disable swapping entirely (swap will be used for hibernation but not actively used while running).

Swappiness only comes into affect when your system's ram is nearly completely full from applications and buffers and caches combined. It changes what the kernel will favour when an application requests more ram, either throwing away cache data or writing some less used memory to disk. The swappiness value controls the ratio between these, where 1 basically always throws away cache and 100 will causes application data to swap most of the time.

You can configure the swappiness of a system on the fly with

sysctl vm.swappiness=10

And set it permanently by editing /etc/sysctl.conf to include

vm.swappiness = 10

For your situation where you have a server with a fair amount of ram and JVM using most of it you probably do not want to be swapping much if at all so lowering this value to 10 or even 1 might be beneficial. Lowering it to 10 is quite often beneficial on most modern systems with lots of ram.

  • Thanks for this info. Currently the value we have is 60, the default you listed.
    – Dave
    Sep 1, 2017 at 17:43

From a practical perspective, because of how Java handles memory, this reduces down to:

"My server has 5GB of RAM, when will it start swapping?"

That then becomes a question of whether or not you are using tmpfs to store temporary files, as that is the other aspect of the system that will potentially use swap space (tmpfs inhabits the regular page cache until the system needs more memory, then it gets pushed out to swap space). It's very likely that your application doesn't use this though, and in that case you can assume you probably won't need swap space during normal operations (and if you shut down your main application when running maintenance, you may not need swap space at all).

That said, you may want to consider having some just in case. In particular, since you probably would prefer to save some money (I'm assuming since you're running Amazon Linux that you're on EC2, and thus disk space costs money per unit time), I'd suggest using compressed memory for swap space using the zram driver (I'm not 100% certain if Amazon Linux includes this driver, but I would be surprised if they don't at least have it as a module).

  • How do I check if my process is using tmpfs?
    – Dave
    Sep 1, 2017 at 17:45
  • 1
    mount will list all mounted drives including location of tmpfs - if your application writes to any of those locations then it uses tmpfs. Sep 1, 2017 at 17:48

Swap partition is also used for hibernation (i.e. suspend to disk). And you could swap on some files (fill a new swap file with zero using dd, make it a swap using mkswap, use it as swap using swapon....).

Of course, if your machine runs a lot of program using memory, and if some process is inactive, it might be swapped of and that would also use swap.

  • If we assume that JBoss is constnatly running and serving requests (at least one per minute) and that there are no other programs (taht we have started) running on that machine, then am I to assume that neither of the cases you listed above woudl apply and we would never hit swap given the other info I have listed in my question?
    – Dave
    Sep 1, 2017 at 17:02
  • You probably have some system processes. Sep 1, 2017 at 17:19
  • The dfeault system processes are not goign to cause my JBoss memory to start swapping given the information I listed in my quetsion (I can list more if necessary). If I'm wrong, please correct me or give an example.
    – Dave
    Sep 1, 2017 at 17:41
  • at least one per minute - Your systems sounds massively over specced given that and you should never start swapping. The default linux system processes should never use more than a few hundred mems of ram. Most of the 5G that JBoss is not configured to use might eventually fill with cached file data if your system read/writes a lot of files. Sep 1, 2017 at 18:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .