{"id":615,"date":"2026-07-11T02:40:11","date_gmt":"2026-07-11T02:40:11","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=615"},"modified":"2026-07-15T22:16:22","modified_gmt":"2026-07-15T22:16:22","slug":"vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/","title":{"rendered":"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Memory is the most constrained resource on a budget VPS. While you can often add more CPU or disk space by scaling up, RAM is expensive and limited \u2014 especially on plans with 1 GB or 2 GB of memory. Understanding how to actively <em>tune<\/em> Linux memory management is essential for squeezing the best performance out of your hardware. This guide walks through practical tuning of swap, the Out-of-Memory (OOM) Killer, and key kernel parameters. When choosing a VPS, <a href=\"https:\/\/virtualserversvps.com\/\">compare VPS plans with different RAM configurations<\/a> to find the right balance for your workload.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Linux Uses RAM: Reading the Numbers Correctly<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before tuning anything, you need to interpret <code>free -h<\/code> output correctly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>               total        used        free      shared  buff\/cache   available\nMem:           1.9Gi       1.1Gi       145Mi       123Mi       695Mi       612Mi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>available<\/strong> column is what matters \u2014 memory that can be reclaimed by the kernel when applications need it. A low &#8220;free&#8221; value is normal and desirable on Linux because unused RAM is better used for disk caching. The <code>buff\/cache<\/code> value is not wasted memory; it accelerates file I\/O. A well-tuned server will show &#8220;available&#8221; as the only real indicator of spare capacity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tuning Swap Configuration for Low-Memory VPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Swap is disk space used as overflow memory when RAM fills up. It is roughly 1000x slower than RAM, but it prevents the system from crashing under load. The key is configuring swap so it acts as a safety net without causing performance degradation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Swap Size Recommendations<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For VPS instances, follow these guidelines:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1 GB RAM or less<\/strong>: Swap equal to 2x RAM (e.g., 2 GB swap for 1 GB RAM).<\/li>\n<li><strong>2\u20134 GB RAM<\/strong>: Swap equal to RAM size.<\/li>\n<li><strong>4 GB+ RAM<\/strong>: 2 GB swap is usually sufficient.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">On VPS plans with NVMe or SSD storage, swap performance is acceptable for occasional use. On spinning disks, heavy swap usage will cripple I\/O. Configure swap with fallocate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo fallocate -l 2G \/swapfile\nsudo chmod 600 \/swapfile\nsudo mkswap \/swapfile\nsudo swapon \/swapfile\n# Make permanent:\necho '\/swapfile none swap sw 0 0' | sudo tee -a \/etc\/fstab<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Tuning vm.swappiness: When Does the Kernel Swap?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>vm.swappiness<\/strong> parameter (0\u2013100) controls how aggressively the kernel swaps memory pages out of RAM. The default value on most distributions is 60, which is too aggressive for a VPS with limited RAM \u2014 the kernel starts swapping when memory usage hits just 40%.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a 1\u20132 GB VPS, lower swappiness keeps critical processes in RAM longer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Check current value\ncat \/proc\/sys\/vm\/swappiness\n\n# Set to 10 (swap only under real memory pressure)\nsudo sysctl vm.swappiness=10\n\n# Make permanent\necho \"vm.swappiness=10\" | sudo tee -a \/etc\/sysctl.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A swappiness of 10 means the kernel starts swapping only when approaching 90% memory pressure. Your applications run in RAM as long as possible. For database servers (MySQL, PostgreSQL), consider setting swappiness as low as 1 to prevent the kernel from swapping out database buffer pages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Protecting Critical Services from the OOM Killer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The OOM Killer is the kernel&#8217;s last resort when memory is completely exhausted. It selects a process to kill based on an <strong>oom_score<\/strong> that factors in memory usage, runtime, CPU time, and process hierarchy. You can influence which processes get killed by adjusting <strong>oom_score_adj<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Protect MySQL from OOM Killer (lower score = less likely to be killed)\nsudo sh -c 'echo -500 > \/proc\/$(pgrep mysqld)\/oom_score_adj'\n\n# Make a non-essential background task more likely to be killed\nsudo sh -c 'echo 500 > \/proc\/$(pgrep some-background-job)\/oom_score_adj'\n\n# Disable OOM killing for a critical process (use cautiously!)\nsudo sh -c 'echo -1000 > \/proc\/$(pgrep sshd)\/oom_score_adj'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Values range from -1000 (OOM killer disabled for this process) to 1000 (always killed first). Use -1000 sparingly \u2014 if you protect too many processes, the system may hang instead of recovering. A practical approach: protect your database and SSH daemon, and let the OOM Killer handle web server workers \u2014 they are easy to restart.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tuning vm.vfs_cache_pressure for Filesystem Metadata<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>vm.vfs_cache_pressure<\/strong> parameter (0\u2013200) controls how aggressively the kernel reclaims memory used for inode and dentry caches (filesystem metadata). For a memory-constrained web server, increasing this value frees RAM for applications:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Reclaim filesystem metadata cache more aggressively\nsudo sysctl vm.vfs_cache_pressure=150\n\n# Make permanent\necho \"vm.vfs_cache_pressure=150\" | sudo tee -a \/etc\/sysctl.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The trade-off: slightly slower file operations (directory listings, stat calls) in exchange for more RAM available to your web applications and database. On a VPS running a database server, this is almost always a net positive.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Dirty Page Tuning: Preventing I\/O Stalls<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The kernel buffers writes in memory (dirty pages) before flushing them to disk. Two parameters control this behavior:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>vm.dirty_background_ratio<\/strong> (default 10): % of memory that can be dirty before background flushing starts.<\/li>\n<li><strong>vm.dirty_ratio<\/strong> (default 20): % of memory that can be dirty before processes block waiting for writes to complete.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">On a low-memory VPS, lower values prevent large dirty page buildups that cause sudden I\/O spikes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Flush dirty pages sooner\nsudo sysctl vm.dirty_background_ratio=5\nsudo sysctl vm.dirty_ratio=10<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Complete Memory Tuning Configuration for 1-2 GB VPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>\/etc\/sysctl.d\/99-memory-tuning.conf<\/code> with these consolidated settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Swap behavior\nvm.swappiness=10\n\n# Reclaim filesystem metadata cache\nvm.vfs_cache_pressure=150\n\n# Reserve minimum free memory for kernel allocations\nvm.min_free_kbytes=65536\n\n# Flush dirty pages sooner\nvm.dirty_background_ratio=5\nvm.dirty_ratio=10\n\n# Reduce memory overcommit\nvm.overcommit_memory=2\nvm.overcommit_ratio=50<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Apply with <code>sudo sysctl -p \/etc\/sysctl.d\/99-memory-tuning.conf<\/code> and verify with <code>sysctl vm.swappiness vm.vfs_cache_pressure vm.min_free_kbytes<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Monitoring Your Tuning Results<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After applying changes, monitor the system for a few days:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Real-time memory usage\nwatch -n 2 free -h\n\n# Top memory consumers\nps aux --sort=-%mem | head -10\n\n# Check for OOM events\nsudo journalctl -k | grep -i \"oom\\|out of memory\"\n\n# Monitor swap activity\nvmstat 2 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you see persistent swap usage even with swappiness=10, your VPS simply needs more RAM. Tuning optimizes how efficiently you use available memory, but it cannot create memory out of thin air. <a href=\"https:\/\/virtualserversvps.com\/#providers\">Compare VPS plans<\/a> to find a provider offering the RAM your workload needs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Linux memory management does not have to be a black box. By tuning swap size, vm.swappiness, OOM Killer protections, vfs_cache_pressure, and dirty page ratios, you can significantly improve how your VPS handles memory pressure. Start with the consolidated configuration above, monitor for a few days, and adjust based on your specific workload. When your application consistently needs more RAM than tuning can provide, it is time to <a href=\"https:\/\/virtualserversvps.com\/\">upgrade to a VPS with more memory<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Memory is the most constrained resource on a budget VPS. While you can often add more CPU or disk space by scaling up, RAM is expensive and limited \u2014 especially&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-615","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance\" \/>\n<meta property=\"og:description\" content=\"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-11T02:40:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-15T22:16:22+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/\",\"name\":\"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-07-11T02:40:11+00:00\",\"dateModified\":\"2026-07-15T22:16:22+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/","og_locale":"en_US","og_type":"article","og_title":"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance","og_description":"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance","og_url":"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-07-11T02:40:11+00:00","article_modified_time":"2026-07-15T22:16:22+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/","url":"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/","name":"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-07-11T02:40:11+00:00","dateModified":"2026-07-15T22:16:22+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/vps-memory-management-understanding-swap-oom-killer-and-kernel-parameters\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"VPS Memory Management: Tuning Swap, OOM Killer, and Kernel Parameters for Better Performance"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=615"}],"version-history":[{"count":2,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions"}],"predecessor-version":[{"id":639,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions\/639"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}