With swap disabled, performance issues become noticeable very fast, and the OOM killer may get you! :)įor comparison, here’s the output of free using an older version of free from procps-ng-3.3.1 on the same server: total used free shared buffers cached This is usually not the case, thus the “almost always” title of this blog post. If memory pages cannot be swapped only when the server is idle, you should tune or disable swap. If your swap space “used” is always ‘0’ then you do indeed have a ton of freely available RAM, in which case it may be safe to remove the swap space… or you can adjust your Kernel’s cache pressure to make use of even more RAM. Also, look at the last section, “ Kernel cache pressure and swappiness,” of my other blog post for tips on tuning Linux swap space usage by the Kernel. As a last resort, the Kernel will deploy OOM killer to nuke high-memory processes (usually MySQL, java, etc.).įor a more detailed look at Linux swap space, read the Swap Management and Page Frame Reclamation chapters from docs. If you don’t have enough memory and no swap space, this will often cause failure to allocate memory for requests needing more memory pages. Unlike the case above, if you don’t have enough memory, swap will be used quite often and noticeably more during any memory requirement spikes. Avoid setting your swap space too large if it will result in prolonging performance issues, outages, or your response time (without proper monitoring/alerts). It’s better to swap out memory pages that have been inactive for a while, keeping often-used data in cache, and this should happen when the server is most idle, which is the aim of the Kernel. Even if there is still available RAM, the Linux Kernel will move memory pages that are hardly ever used into swap space. It’s designed to be complementary to the performance of healthy systems. Swap does not change the amount of RAM required for a healthy server, or desktop for that matter. However, this is hardly the case on servers, and you should instead balance your decision with the effects swap will have on your specific applications. If you can come up with valid reasons for this, then that maybe your choice. Some recommend no swap or swap size slightly larger than the total RAM. It can even be smaller, especially if you have monitoring and/or alerting in place. For example, MySQL’s configured memory in my.cnf. So usually, I would advise setting swap space to about the size of your largest process. Without swap (as described in the next section), running out of memory can create much more sudden and severe chain reactions. We will often notice the server acting slowly and, upon login, will notice heavy swapping. Swap usage becomes a performance problem when the Kernel is pressured to continuously move memory pages in and out of memory and swap space.Īnother advantage is that swap gives admins time to react to low memory issues. The Linux Kernel will move memory pages that are hardly ever used into swap space to ensure that even more cachable space is made available in-memory for more frequently used memory pages (a page is a piece of memory). It is normal and can be a good thing for Linux systems to use some swap, even if there is still available RAM. It now comes with ZRAM enabled by default.Īdvantages of swap space on systems with adequate RAM Update: Recently, I installed Manjoro i3 on my Pinebook Pro. Now, let’s look at how swap space can actually help Linux server performance. …so in this case, as in many, swap usage is not hurting Linux server performance. To confirm, I used the following command: ps -A | grep kswap In fact, the kswap process was nowhere to be found in top (top processes sorted by CPU time). Also, the kswap service didn’t consume much CPU time. When I ran checks for swapping, there were no signs of ongoing or untimely swap I/O activity. The output of free -h here shows 308M of swap space used. See the below example from a live-chat server with around one month of uptime: total used free shared buff/cache available Even with more than adequate server memory installed, you will often find that swap space will be used after long periods of uptime.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |