{"id":11966,"date":"2025-10-23T11:17:03","date_gmt":"2025-10-23T11:17:03","guid":{"rendered":"https:\/\/mainvps.net\/blog\/?p=11966"},"modified":"2026-02-02T07:39:13","modified_gmt":"2026-02-02T07:39:13","slug":"ubuntu-servers-swap-memory-configuration","status":"publish","type":"post","link":"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/","title":{"rendered":"Best Swap &amp; Memory Configurations on Ubuntu Servers"},"content":{"rendered":"\r\n<p>When it comes to server optimization in the year 2026, the knowledge of swap and memory configuration on Ubuntu servers is what will make or break your system\u2019s efficiency and stability. Whether you are running a personal VPS, a production server with a lot of traffic, or a containerized application, the way your system handles memory and swap will have a direct effect on its uptime, speed, and reliability.<\/p>\r\n<p>Today\u2019s applications are more resource-intensive than ever before. Web applications, databases, Docker containers, and background processes all fight for memory. If memory is not handled correctly, your server could slow down, freeze, or even crash. This is where effective memory optimization comes into play to keep your server responsive even during traffic spikes or heavy processing.<\/p>\r\n<p>Swap is also a safety net when the physical RAM is fully utilized. Although it is not a substitute for physical RAM, a properly tuned swap configuration can help prevent unexpected service crashes and OOM kills and give your system some leeway during peak times. However, it can also cause performance bottlenecks if it is overutilized or improperly tuned.<\/p>\r\n<p>In this tutorial, we will walk you through some effective and contemporary methods to help you get the most out of your <a href=\"https:\/\/mainvps.net\/blog\/almalinux-vs-ubuntu-enterprise-hosting\/\">Ubuntu<\/a> server in 2026. You will learn how to properly utilize swap, how much swap to allocate, how to properly tune the swappiness for optimal performance, and how to monitor memory usage effectively. Whether you are looking to achieve maximum performance, enhance system stability, or optimize resource usage, these tried-and-true methods will help you create a faster and more stable Ubuntu server configuration.<\/p>\r\n\r\n\r\n\r\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#What_Is_Swap_Space_and_Why_Does_It_Still_Matter_in_2026\" >What Is Swap Space and Why Does It Still Matter in 2026<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Recommended_Swap_Size_for_Ubuntu_Servers_in_2026\" >Recommended Swap Size for Ubuntu Servers in 2026<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Choosing_Between_Swap_Partition_vs_Swap_File\" >Choosing Between Swap Partition vs Swap File<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Swap_Partition\" >Swap Partition<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Swap_File\" >Swap File<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Understanding_Swappiness_and_How_to_Tune_It\" >Understanding Swappiness and How to Tune It<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Recommended_Swappiness_Values_2026\" >Recommended Swappiness Values (2026):<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Tuning_vmvfs_cache_pressure_for_Better_Memory_Efficiency\" >Tuning vm.vfs_cache_pressure for Better Memory Efficiency<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Optimizing_Swap_on_SSDs_and_NVMe_Drives\" >Optimizing Swap on SSDs and NVMe Drives<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Modern_Swap_Technologies_zswap_zram_and_Compressed_Memory\" >Modern Swap Technologies: zswap, zram, and Compressed Memory<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#1_zswap\" >1. zswap<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#2_zram\" >2. zram<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#3_Hybrid_Setup_zram_Swap_File\" >3. Hybrid Setup (zram + Swap File)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Monitoring_Memory_and_Swap_Usage_Effectively\" >Monitoring Memory and Swap Usage Effectively<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Practical_Tips_for_Maintaining_Healthy_Memory_Performance\" >Practical Tips for Maintaining Healthy Memory Performance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Final_Thoughts\" >Final Thoughts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#FAQs\" >FAQs:<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/#Suggestions\" >Suggestions:<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Is_Swap_Space_and_Why_Does_It_Still_Matter_in_2026\"><\/span><strong>What Is Swap Space and Why Does It Still Matter in 2026<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<p>In practical server environments, memory utilization is rarely steady. Traffic spikes, background jobs, software updates, and database queries are just a few examples of memory-intensive activities that can happen suddenly. Swap space can mitigate these sudden memory spikes, giving the server time to recover without affecting already running processes.<\/p>\r\n<p>In 2026, many modern applications, including containerized applications, WordPress sites running multiple plugins, and cloud infrastructure, exhibit unpredictable memory usage. Swap space ensures that non-critical or idle processes are prioritized for removal from RAM first, keeping critical processes such as web servers and databases running smoothly.<\/p>\r\n<p>Swap space also mitigates the chances of the <a href=\"https:\/\/mainvps.net\/blog\/linux-vps-hosting-india\/\">Linux<\/a> OOM (Out of Memory) killer process intervening. In the absence of swap space, the kernel will suddenly kill critical processes to reclaim memory, resulting in lost data or server downtime. With swap space enabled, the server has more leeway to handle memory usage safely.<\/p>\r\n<p>However, steady swap space usage is a sign of a problem. It typically indicates that the server has reached the end of its RAM capacity or that applications are memory-inefficient. In such scenarios, swap space should be a supplement, not a substitute.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Recommended_Swap_Size_for_Ubuntu_Servers_in_2026\"><\/span><strong>Recommended Swap Size for Ubuntu Servers in 2026<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<p>Gone are the days of the \u201c2x your RAM\u201d rule. Modern servers and workloads demand a more nuanced approach:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table class=\"has-fixed-layout\">\r\n<thead>\r\n<tr>\r\n<th><strong>System RAM<\/strong><\/th>\r\n<th><strong>Recommended Swap (2026)<\/strong><\/th>\r\n<th><strong>Use Case<\/strong><\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td>&lt; 4 GB<\/td>\r\n<td>2x RAM<\/td>\r\n<td>Light workloads, basic VPS hosting<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>4\u201316 GB<\/td>\r\n<td>Equal to RAM (1x)<\/td>\r\n<td>Web servers, moderate applications<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>16\u201364 GB<\/td>\r\n<td>4\u20138 GB minimum<\/td>\r\n<td>Databases, Docker hosts<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>64+ GB<\/td>\r\n<td>2\u20134 GB (plus hibernation if needed)<\/td>\r\n<td>Enterprise workloads<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<p>For most Ubuntu 22.04\/24.04 servers in 2026, a <strong>4\u20138 GB swap<\/strong> is sufficient, assuming you monitor your system properly. You can check current usage with:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>free -h\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>and adjust swap dynamically as needed.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Choosing_Between_Swap_Partition_vs_Swap_File\"><\/span><strong>Choosing Between Swap Partition vs Swap File<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<p>In earlier Ubuntu versions, <strong>swap partitions<\/strong> were standard. But since Ubuntu 20.04, <strong>swap files<\/strong> have become the default, and for good reason. Here\u2019s why:<\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Swap_Partition\"><\/span><strong>Swap Partition<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Slightly faster on dedicated SSDs.<\/li>\r\n\r\n\r\n\r\n<li>Fixed size, difficult to resize dynamically.<\/li>\r\n\r\n\r\n\r\n<li>Best for systems where swap use is predictable.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Swap_File\"><\/span><strong>Swap File<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Easier to resize or move.<\/li>\r\n\r\n\r\n\r\n<li>Works on most file systems (ext4, xfs, etc.).<\/li>\r\n\r\n\r\n\r\n<li>Now the default and recommended approach for most Ubuntu 22.04+ setups.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>To create a swap file:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>sudo fallocate -l 8G \/swapfile\r\nsudo chmod 600 \/swapfile\r\nsudo mkswap \/swapfile\r\nsudo swapon \/swapfile\r\necho '\/swapfile none swap sw 0 0' | sudo tee -a \/etc\/fstab\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>This setup gives flexibility to modify or disable swap later without repartitioning disks.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Understanding_Swappiness_and_How_to_Tune_It\"><\/span><strong>Understanding Swappiness and How to Tune It<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<p>Swappiness is one of the most important yet misunderstood kernel parameters. It controls <strong>how aggressively Ubuntu uses swap<\/strong>. A higher value (e.g., 60) means the system swaps sooner, while a lower value (e.g., 10) makes the OS rely more on RAM.<\/p>\r\n\r\n\r\n\r\n<p>You can check the current setting with:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>cat \/proc\/sys\/vm\/swappiness\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>To adjust it:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>sudo sysctl vm.swappiness=10\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>And to make it permanent:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>echo 'vm.swappiness=10' | sudo tee -a \/etc\/sysctl.conf\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Recommended_Swappiness_Values_2026\"><\/span><strong>Recommended Swappiness Values (2026)<\/strong>:<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><strong>Desktop systems:<\/strong> 40\u201360 (to prevent UI lag)<\/li>\r\n\r\n\r\n\r\n<li><strong>Web servers \/ Databases:<\/strong> 10\u201320 (favor in-memory performance)<\/li>\r\n\r\n\r\n\r\n<li><strong>Low-memory VPS:<\/strong> 30\u201340 (balance between responsiveness and stability)<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>For most production Ubuntu servers, <strong>10\u201315<\/strong> hits the sweet spot just enough to use swap when truly necessary without killing performance.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Tuning_vmvfs_cache_pressure_for_Better_Memory_Efficiency\"><\/span><strong>Tuning vm.vfs_cache_pressure for Better Memory Efficiency<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Another critical parameter for optimizing memory behavior is <strong>vfs_cache_pressure<\/strong>. It determines how aggressively the kernel reclaims memory used for caching directory and inode information.<\/p>\r\n\r\n\r\n\r\n<p>By default, it\u2019s set to <strong>100<\/strong>, meaning Ubuntu reclaims cache at a normal rate. Lowering it (e.g., to 50) makes the system <strong>keep cached data longer<\/strong>, which can improve filesystem access performance.<\/p>\r\n\r\n\r\n\r\n<p>To adjust:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>sudo sysctl vm.vfs_cache_pressure=50\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>Make it permanent:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>echo 'vm.vfs_cache_pressure=50' | sudo tee -a \/etc\/sysctl.conf\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>When used together, <code>swappiness<\/code> and <code>vfs_cache_pressure<\/code> create a balanced memory ecosystem\u2014less disk thrashing, better I\/O performance, and smoother multi-user environments.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Optimizing_Swap_on_SSDs_and_NVMe_Drives\"><\/span><strong>Optimizing Swap on SSDs and NVMe Drives<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>In 2026, most servers are running SSD or NVMe storage. While these drives are fast, <strong>constant swap I\/O can still shorten their lifespan<\/strong>. Here\u2019s how to optimize swap on SSDs:<\/p>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li><strong>Use zswap or zram<\/strong> (more below).<\/li>\r\n\r\n\r\n\r\n<li>Keep swap sizes moderate (not excessive).<\/li>\r\n\r\n\r\n\r\n<li>Monitor wear-leveling with <code>smartctl<\/code>.<\/li>\r\n\r\n\r\n\r\n<li>Avoid swap partitions; prefer files (easier to move or limit).<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<p>You can also enable TRIM support for swap files to keep SSDs healthy:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>sudo systemctl enable fstrim.timer\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Modern_Swap_Technologies_zswap_zram_and_Compressed_Memory\"><\/span><strong>Modern Swap Technologies: zswap, zram, and Compressed Memory<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<p>Ubuntu 24.04 LTS and later support advanced swap compression technologies that can drastically improve memory efficiency.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_zswap\"><\/span><strong>1. zswap<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>zswap is a <strong>compressed swap cache<\/strong> inside RAM. Instead of writing pages to disk, Ubuntu compresses them and keeps them in memory until necessary, reducing I\/O load and speeding up swapping.<\/p>\r\n\r\n\r\n\r\n<p>Enable it by editing GRUB:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/default\/grub\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>Add:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>GRUB_CMDLINE_LINUX_DEFAULT=\"zswap.enabled=1\"\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>Then:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>sudo update-grub\r\nsudo reboot\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_zram\"><\/span><strong>2. zram<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>zram creates a <strong>compressed block device in RAM<\/strong> for swap usage, perfect for low-memory <a href=\"https:\/\/mainvps.net\/vps\">VPS<\/a> or IoT servers.<\/p>\r\n\r\n\r\n\r\n<p>To enable zram:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>sudo apt install zram-tools\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>Ubuntu automatically creates compressed swap devices after enabling them. This can double or triple your effective RAM for lightweight workloads.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Hybrid_Setup_zram_Swap_File\"><\/span><strong>3. Hybrid Setup (zram + Swap File)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>For high-performance setups, use both. zram handles quick bursts, while a small disk-based swap file provides backup for overflow situations.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Monitoring_Memory_and_Swap_Usage_Effectively\"><\/span><strong>Monitoring Memory and Swap Usage Effectively<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Once you\u2019ve optimized configurations, regular monitoring ensures long-term stability. Use these commands:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><code>free -h<\/code> \u2014 quick overview of RAM and swap usage<\/li>\r\n\r\n\r\n\r\n<li><code>vmstat 5<\/code> \u2014 live performance snapshot<\/li>\r\n\r\n\r\n\r\n<li><code>htop<\/code> or <code>glances<\/code> \u2014 interactive system monitor<\/li>\r\n\r\n\r\n\r\n<li><code>smem<\/code> \u2014 more accurate memory usage breakdown<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>You can also install <strong>Netdata<\/strong> or <strong>Prometheus + Grafana<\/strong> for visual or for <a href=\"https:\/\/mainvps.net\/blog\/monitoring-kvm-vps-performance-essential-tools-and-techniques\/\">VPS monitoring<\/a>, historical tracking of memory and swap trends.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Practical_Tips_for_Maintaining_Healthy_Memory_Performance\"><\/span><strong>Practical Tips for Maintaining Healthy Memory Performance<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Keep background processes minimal.<\/li>\r\n\r\n\r\n\r\n<li>Restart long-running applications occasionally to clear memory leaks.<\/li>\r\n\r\n\r\n\r\n<li><code>Enable OOMDoomd<\/code> (Out-Of-Memory Daemon) in <a href=\"https:\/\/mainvps.net\/blog\/ubuntu-guide\/\">Ubuntu 24.04<\/a>+ for smart process killing instead of total crashes.<\/li>\r\n\r\n\r\n\r\n<li>Regularly update your kernel memory management; improvements continue to arrive with each release.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>A stable Ubuntu server isn\u2019t just about having more RAM; it\u2019s about <strong>teaching your system how to use it wisely<\/strong>.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Final_Thoughts\"><\/span>Final Thoughts<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>In the year 2026, there is no one \u201cperfect\u201d swap and memory configuration for Ubuntu servers. The trick is finding the right balance using the right amount of swap, properly configuring the kernel, and leveraging the latest memory optimizations, such as zram or zswap. With a few tweaks, such as tweaking swappiness, adjusting vfs_cache_pressure, and enabling compressed memory, you can dramatically improve the reliability of your server and get the most out of every gigabyte of RAM.<\/p>\r\n<p>It is worth noting that having a swap is not a problem; it is a crutch. With a little bit of tweaking, you can ensure that your server runs smoothly even when memory is at a premium.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span><strong>FAQs:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<ol data-start=\"199\" data-end=\"2307\">\r\n<li data-start=\"199\" data-end=\"412\">\r\n<p data-start=\"202\" data-end=\"412\"><strong data-start=\"202\" data-end=\"249\">Is a swap still necessary if I have 64GB RAM?<\/strong><br data-start=\"249\" data-end=\"252\" \/>Yes. Even with large amounts of RAM, swap acts as a safety net for sudden memory spikes and ensures critical processes aren\u2019t killed during unexpected loads.<\/p>\r\n<\/li>\r\n<li data-start=\"414\" data-end=\"683\">\r\n<p data-start=\"417\" data-end=\"683\"><strong data-start=\"417\" data-end=\"466\">What\u2019s the difference between zswap and zram?<\/strong><br data-start=\"466\" data-end=\"469\" \/>zswap compresses and caches memory pages in RAM before writing to disk, while zram creates a fully compressed in-memory swap device. zram remains faster and ideal for servers with limited RAM or heavy workloads.<\/p>\r\n<\/li>\r\n<li data-start=\"685\" data-end=\"899\">\r\n<p data-start=\"688\" data-end=\"899\"><strong data-start=\"688\" data-end=\"716\">Does swapping wear out SSDs?<\/strong><br data-start=\"716\" data-end=\"719\" \/>Modern SSDs are highly durable, so moderate swap usage has minimal impact. Excessive swapping can increase writes, but for most workloads in 2026,<a href=\"https:\/\/en.wikipedia.org\/wiki\/Solid-state_drive\" target=\"_blank\" rel=\"nofollow noopener\"> SSD<\/a> longevity isn\u2019t a concern.<\/p>\r\n<\/li>\r\n<li data-start=\"901\" data-end=\"1119\">\r\n<p data-start=\"904\" data-end=\"1119\"><strong data-start=\"904\" data-end=\"946\">How can I tell if my swap is overused?<\/strong><br data-start=\"946\" data-end=\"949\" \/>Use commands like <code data-start=\"970\" data-end=\"980\">vmstat 5<\/code>, <code data-start=\"982\" data-end=\"991\">free -h<\/code>, or monitoring tools like <code data-start=\"1018\" data-end=\"1024\">htop<\/code>. High swap-in (\u201csi\u201d) or swap-out (\u201cso\u201d) values indicate the system is relying heavily on swap.<\/p>\r\n<\/li>\r\n<li data-start=\"1121\" data-end=\"1311\">\r\n<p data-start=\"1124\" data-end=\"1311\"><strong data-start=\"1124\" data-end=\"1161\">Should I disable swap completely?<\/strong><br data-start=\"1161\" data-end=\"1164\" \/>No. Swap is essential for stability, hibernation, and handling unexpected memory spikes. Instead, optimize swap usage by adjusting <code data-start=\"1298\" data-end=\"1310\">swappiness<\/code>.<\/p>\r\n<\/li>\r\n<li data-start=\"1313\" data-end=\"1531\">\r\n<p data-start=\"1316\" data-end=\"1531\"><strong data-start=\"1316\" data-end=\"1360\">How much swap should I allocate in 2026?<\/strong><br data-start=\"1360\" data-end=\"1363\" \/>For modern servers, 4\u20138GB of swap is usually sufficient for systems with 64GB+ RAM. The exact size depends on workload intensity and whether compressed swap is used.<\/p>\r\n<\/li>\r\n<li data-start=\"1533\" data-end=\"1718\">\r\n<p data-start=\"1536\" data-end=\"1718\"><strong data-start=\"1536\" data-end=\"1587\">Where should the swap be located: SSD, NVMe, or HDD?<\/strong><br data-start=\"1587\" data-end=\"1590\" \/>SSDs or NVMe drives are preferred for speed. HDD-based swap works but may slow down performance during heavy memory pressure.<\/p>\r\n<\/li>\r\n<li data-start=\"1720\" data-end=\"1888\">\r\n<p data-start=\"1723\" data-end=\"1888\"><strong data-start=\"1723\" data-end=\"1758\">Can swapping improve server uptime?<\/strong><br data-start=\"1758\" data-end=\"1761\" \/>Absolutely. Swap prevents crashes during memory spikes, allowing critical services to continue running without interruption.<\/p>\r\n<\/li>\r\n<li data-start=\"1890\" data-end=\"2105\">\r\n<p data-start=\"1893\" data-end=\"2105\"><strong data-start=\"1893\" data-end=\"1940\">How do I optimize swap performance in 2026?<\/strong><br data-start=\"1940\" data-end=\"1943\" \/>Adjust kernel parameters like <code data-start=\"1976\" data-end=\"1988\">swappiness<\/code> and <code data-start=\"1993\" data-end=\"2013\">vfs_cache_pressure<\/code>, and use compressed swap solutions like <strong data-start=\"2054\" data-end=\"2062\">zram<\/strong> or <strong data-start=\"2066\" data-end=\"2075\">zswap<\/strong> to improve memory efficiency.<\/p>\r\n<\/li>\r\n<li data-start=\"2107\" data-end=\"2307\">\r\n<p data-start=\"2111\" data-end=\"2307\"><strong data-start=\"2111\" data-end=\"2148\">Is constant swap usage a problem?<\/strong><br data-start=\"2148\" data-end=\"2151\" \/>Yes. Frequent swapping indicates RAM may be insufficient or workloads need optimization. Swap should remain a safety buffer, not a primary memory source.<\/p>\r\n<\/li>\r\n<\/ol>\r\n<h3><span class=\"ez-toc-section\" id=\"Suggestions\"><\/span><strong>Suggestions:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<ol>\r\n<li><a href=\"https:\/\/mainvps.net\/blog\/mainvps-vs-bluehost-which-web-hosting-provider\/\">https:\/\/mainvps.net\/blog\/mainvps-vs-bluehost-which-web-hosting-provider\/<\/a><\/li>\r\n<li><a href=\"https:\/\/mainvps.net\/blog\/low-cost-windows-vps-hosting-in-india\/\">https:\/\/mainvps.net\/blog\/low-cost-windows-vps-hosting-in-india\/<\/a><\/li>\r\n<li><a href=\"https:\/\/mainvps.net\/blog\/linux-vps-hosting-india\/\">https:\/\/mainvps.net\/blog\/linux-vps-hosting-india\/<\/a><\/li>\r\n<li><a href=\"https:\/\/mainvps.net\/blog\/how-to-install-moltbot-clawdbot-on-a-vps\/\">https:\/\/mainvps.net\/blog\/how-to-install-moltbot-clawdbot-on-a-vps\/<\/a><\/li>\r\n<li><a href=\"https:\/\/mainvps.net\/blog\/windows-server-guide-dde-dns-tls-1-2-uptime\/\">https:\/\/mainvps.net\/blog\/windows-server-guide-dde-dns-tls-1-2-uptime\/<\/a><\/li>\r\n<\/ol>\r\n","protected":false},"excerpt":{"rendered":"<p>When it comes to server optimization in the year 2026, the knowledge of swap and memory configuration on Ubuntu servers is what will make or break <a class=\"read-more-link\" href=\"https:\/\/mainvps.net\/blog\/ubuntu-servers-swap-memory-configuration\/\">Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":11976,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[321,320,322,315],"class_list":["post-11966","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-hosting","tag-best-swap-settings-ubuntu","tag-swap-and-memory-configuration","tag-ubuntu-server-memory-optimization","tag-ubuntu-servers"],"_links":{"self":[{"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/posts\/11966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/comments?post=11966"}],"version-history":[{"count":4,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/posts\/11966\/revisions"}],"predecessor-version":[{"id":12256,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/posts\/11966\/revisions\/12256"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/media\/11976"}],"wp:attachment":[{"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/media?parent=11966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/categories?post=11966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mainvps.net\/blog\/wp-json\/wp\/v2\/tags?post=11966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}