{"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-08-01T22:13:34","modified_gmt":"2026-08-01T22:13:34","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 Tuning: Swap, OOM Killer, and vm.* Settings"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">On a 1\u20132 GB RAM VPS, memory is the resource you run out of first \u2014 and how the kernel reacts when you do determines whether your site slows down or your process gets killed mid-request. The default Linux memory settings are tuned for workstations with plenty of RAM, not for small virtual servers under constant load. This guide covers the three levers that actually matter: swap sizing and <code>vm.swappiness<\/code>, the OOM killer&#8217;s decision process, and the <code>vm.*<\/code> kernel parameters that control how aggressively the kernel reclaims memory. If you&#8217;re still shopping for hardware, <a href=\"https:\/\/virtualserversvps.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">see how RAM sizing differs across VPS plans<\/a> before committing to a 1 GB instance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Read <code>free -h<\/code> Like a Sysadmin, Not a Beginner<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before tuning anything, you need to know which numbers matter. Here&#8217;s typical output on a 2 GB VPS:<\/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\nSwap:          2.0Gi        80Mi       1.9Gi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>available<\/strong> column is the only one that reflects real spare capacity \u2014 memory the kernel can reclaim from cache the moment an application asks for it. A low <code>free<\/code> value is normal and healthy on Linux; <code>buff\/cache<\/code> is not wasted RAM, it&#8217;s the page cache accelerating your disk I\/O. If <code>available<\/code> is consistently close to zero and swap usage keeps climbing, you have a genuine memory shortage and need the tuning below \u2014 or a bigger plan.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Right-Size Swap for Your RAM<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Swap is disk pretending to be RAM \u2014 roughly 1000x slower \u2014 but on a small VPS it&#8217;s the difference between a slow response and a crashed process. Sensible starting points:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>1 GB RAM:<\/strong> 2 GB swap (2x RAM).<\/li><li><strong>2\u20134 GB RAM:<\/strong> swap equal to RAM size.<\/li><li><strong>4 GB+ RAM:<\/strong> 2 GB swap is usually enough; rely on it only as a safety net.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Create it with <code>fallocate<\/code> (fast on modern filesystems) and mount it permanently:<\/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\necho '\/swapfile none swap sw 0 0' | sudo tee -a \/etc\/fstab\n\n# Verify\nswapon --show\nfree -h<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Tune <code>vm.swappiness<\/code>: When the Kernel Decides to Swap<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>vm.swappiness<\/code> (default 60) controls how eagerly the kernel pushes anonymous pages to swap versus reclaiming page cache. The higher the value, the sooner the kernel swaps under pressure. On a server, you want the kernel to prefer dropping cache \u2014 which is free to re-read \u2014 over swapping application memory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1-2 GB RAM VPS: start at 10\n# 4+ GB RAM: can go as low as 1\necho 'vm.swappiness=10' | sudo tee \/etc\/sysctl.d\/99-memory.conf\nsudo sysctl --system\ncat \/proc\/sys\/vm\/swappiness<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set it too low (0) and the kernel will starve the page cache, causing heavy disk reads under load; set it too high and your application threads block on disk I\/O while idle pages get swapped out. Ten is a solid default for small VPS instances; adjust after observing <code>si<\/code>\/<code>so<\/code> columns in <code>vmstat 5<\/code> \u2014 sustained swap-in activity means you&#8217;re too aggressive.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Keep Metadata in RAM with <code>vm.vfs_cache_pressure<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Linux caches directory entries and inodes (the VFS cache) to avoid repeated disk metadata lookups. The default <code>vm.vfs_cache_pressure=100<\/code> lets the kernel reclaim this cache as aggressively as page cache. On a web server hammered with file stat() calls \u2014 think PHP-FPM or Node.js serving many small files \u2014 dropping that cache forces expensive disk seeks. Lowering the value to 50 makes the kernel retain inode\/dentry caches twice as long:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 'vm.vfs_cache_pressure=50' | sudo tee -a \/etc\/sysctl.d\/99-memory.conf\nsudo sysctl --system<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Don&#8217;t go below ~40 on a tiny VPS: metadata cache still consumes RAM, and on a 1 GB instance you can trade one bottleneck for another.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Control the OOM Killer Instead of Fighting It<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When memory is exhausted, the kernel&#8217;s OOM killer picks a process to terminate using a heuristic <code>oom_score<\/code> \u2014 and its picks are often surprising (it has a known bias against long-running root daemons). You can steer it deterministically:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Protect your database: lower its score so it's never the first choice\nsudo systemctl set-property postgresql.service OOMScoreAdjust=-500\n\n# Sacrifice a batch job first: raise its score\nsudo systemctl set-property celery-worker.service OOMScoreAdjust=500\n\n# Inspect current scores (higher = more likely to be killed)\nfor p in $(pgrep -f postgres); do\n  echo \"PID $p: $(cat \/proc\/$p\/oom_score)\";\ndone<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For interactive protection, install <code>earlyoom<\/code> \u2014 it watches memory pressure and kills the largest consumer before the kernel&#8217;s OOM killer panics the whole box:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install earlyoom -y\nsudo systemctl enable --now earlyoom\n# It fires at 90% RAM \/ 10% swap by default; tune with -r and -m flags\nsudo systemctl status earlyoom<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the Tuning Under Real Pressure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Load-test your tuned memory settings with a controlled allocation bomb (in a disposable container or on a test instance \u2014 it will freeze your shell briefly):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Allocate 150% of RAM in 100 MB chunks\npython3 -c \"\nimport time\nbuf = []\nfor i in range(int(__import__('os').sysconf(2) * 1.5) \/\/ (100*1024*1024) + 1):\n    buf.append(bytearray(100*1024*1024)); time.sleep(0.2)\n\"\n# In a second terminal, watch:\nvmstat 1\ndmesg -T | tail -20   # OOM \/ earlyoom messages land here<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You want to see the kernel reclaim cache, then swap gradually, and finally earlyoom (or the OOM killer) terminating the allocator \u2014 not your web server. If the wrong process dies, adjust <code>OOMScoreAdjust<\/code> accordingly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When Tuning Isn&#8217;t Enough<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Memory tuning squeezes the last drops out of 1\u20132 GB, but if <code>available<\/code> sits at zero and swap is permanently active even after tuning, the honest fix is more RAM. Before you pay for an upgrade, <a href=\"https:\/\/virtualserversvps.com\/#providers\" target=\"_blank\" rel=\"noreferrer noopener\">compare VPS providers on our comparison table<\/a> \u2014 some charge a premium for the same 2 GB that others include at half the price. If you&#8217;d rather not babysit kernel parameters, <a href=\"https:\/\/cloudways.com\/en\/?id=2010927&amp;data1=virtualserversvps\" target=\"_blank\" rel=\"noreferrer noopener sponsored\">Cloudways managed plans<\/a> apply sane memory defaults out of the box, and <a href=\"https:\/\/interserver.net\/vps?id=1067805&amp;sid=virtualserversvps\" target=\"_blank\" rel=\"noreferrer noopener sponsored\">InterServer&#8217;s unmanaged VPS line<\/a> gives you full control at a low fixed price if you prefer the DIY route.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start with swap sizing, set <code>swappiness<\/code> to 10 and <code>vfs_cache_pressure<\/code> to 50, assign explicit OOM scores to your critical services, and verify under load. That sequence has kept 1 GB instances serving production traffic comfortably \u2014 and it&#8217;s entirely reversible if your workload behaves differently.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>On a 1\u20132 GB RAM VPS, memory is the resource you run out of first \u2014 and how the kernel reacts when you do determines whether your site slows down&#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":7,"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 Tuning: Swap, OOM Killer, and vm.* Settings - 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 Tuning: Swap, OOM Killer, and vm.* Settings\" \/>\n<meta property=\"og:description\" content=\"VPS Memory Tuning: Swap, OOM Killer, and vm.* Settings\" \/>\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-08-01T22:13:34+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 Tuning: Swap, OOM Killer, and vm.* Settings - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-07-11T02:40:11+00:00\",\"dateModified\":\"2026-08-01T22:13:34+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 Tuning: Swap, OOM Killer, and vm.* Settings\"}]},{\"@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 Tuning: Swap, OOM Killer, and vm.* Settings - 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 Tuning: Swap, OOM Killer, and vm.* Settings","og_description":"VPS Memory Tuning: Swap, OOM Killer, and vm.* Settings","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-08-01T22:13:34+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 Tuning: Swap, OOM Killer, and vm.* Settings - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-07-11T02:40:11+00:00","dateModified":"2026-08-01T22:13:34+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 Tuning: Swap, OOM Killer, and vm.* Settings"}]},{"@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":4,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions"}],"predecessor-version":[{"id":773,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions\/773"}],"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}]}}