{"id":1678,"date":"2026-11-07T06:37:00","date_gmt":"2026-11-07T06:37:00","guid":{"rendered":"https:\/\/affordablevpsserver.com\/blog\/?p=1678"},"modified":"2026-11-07T06:37:00","modified_gmt":"2026-11-07T06:37:00","slug":"swap-file-tuning-one-gigabyte-vps","status":"publish","type":"post","link":"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/","title":{"rendered":"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life"},"content":{"rendered":"<p><strong>TL;DR \/ Summary:<\/strong> A 1 GB VPS does not run out of memory suddenly; it gets killed by the kernel when cache and processes crowd the last hundred megabytes. A swap file sized at 1\u20132 GB, low swappiness, and a weekly look at swap-in and swap-out rates will keep a small box stable without shredding the disk.<\/p>\n<h2>Why a 1 GB box dies at 900 MB<\/h2>\n<p>Linux uses free memory for page cache, so a healthy small server usually shows very little &#8220;free&#8221; RAM and that is not a problem. The problem starts when an application allocates faster than the kernel can reclaim cache, the OOM killer picks the largest process, and your database or web worker disappears without a stack trace.<\/p>\n<p>Swap does not add performance. It adds a pressure valve, so the kernel can move cold anonymous pages to disk instead of killing something. On a budget VPS that valve is often the difference between a slow minute and a dead service.<\/p>\n<h2>Swap file size: what actually fits<\/h2>\n<p>The old advice of twice the RAM was written for machines that hibernated. A server does not hibernate, so the useful question is how much cold memory you need to park. For a 1 GB box running a web app and a small database, 1 GB of swap is usually enough; 2 GB is generous and still cheap.<\/p>\n<p>Check disk first. Many budget plans ship with 20\u201325 GB of SSD, and a 2 GB swap file plus logs plus images can push you toward a full filesystem, which is a worse failure than memory pressure. Reserve at least 3 GB of free disk after creating the file.<\/p>\n<h3>Sizing shortcuts by workload<\/h3>\n<ul>\n<li><strong>Static site or reverse proxy<\/strong> \u2014 512 MB swap is plenty<\/li>\n<li><strong>Small database plus app<\/strong> \u2014 1 GB, watch the cache hit rate<\/li>\n<li><strong>Build jobs or image processing<\/strong> \u2014 2 GB, and expect it to be used<\/li>\n<\/ul>\n<h2>Creating and mounting the file correctly<\/h2>\n<p>Allocate with <code>fallocate -l 1G \/swapfile<\/code> on ext4 or xfs, set permissions to <code>600<\/code>, run <code>mkswap<\/code>, then <code>swapon<\/code>. On btrfs, <code>fallocate<\/code> creates an unreclaimable extent, so use <code>dd<\/code> or a dedicated swap subvolume instead. Getting this wrong produces a file that works until the disk fills.<\/p>\n<p>Add the entry to <code>\/etc\/fstab<\/code> so the swap returns after a reboot, and confirm with <code>swapon --show<\/code> plus <code>free -h<\/code>. A swap file that only exists until the next provider maintenance window is worse than none, because you will have stopped watching for memory issues.<\/p>\n<h2>Swappiness and cache pressure<\/h2>\n<p><code>vm.swappiness<\/code> controls how eagerly the kernel moves anonymous pages to swap. A value of 60 is the default and is too eager for a server that wants hot application memory to stay resident. Set 10 for a small box, or 20 if you would rather avoid OOM kills at the cost of a little latency.<\/p>\n<p><code>vm.vfs_cache_pressure<\/code> controls how aggressively inode and dentry caches are reclaimed. Dropping it to 50 keeps directory lookups fast on a busy file tree. Persist both in <code>\/etc\/sysctl.d\/99-tuning.conf<\/code>, then apply with <code>sysctl --system<\/code> so the settings survive upgrades.<\/p>\n<h2>Watching for thrash instead of guessing<\/h2>\n<p>Look at <code>vmstat 5<\/code> and read the <code>si<\/code> and <code>so<\/code> columns. Occasional small values are normal. Sustained swap-in above a few hundred kilobytes per second means the working set does not fit, and adding more swap will only make the machine slower. That is the signal to remove a process or buy more RAM.<\/p>\n<p>Also read <code>SwapCached<\/code> in <code>\/proc\/meminfo<\/code>. If it grows steadily and never shrinks, pages are being written out and read back repeatedly. A single spike during a nightly backup is fine; a rising line all afternoon is not.<\/p>\n<h2>When swap hides a memory leak<\/h2>\n<p>Swap is a diagnostic tool as much as a safety net. If a service&#8217;s resident memory climbs every day and swap slowly fills behind it, you have a leak, and a bigger swap file buys you a longer interval between crashes rather than a fix.<\/p>\n<p>Compare <code>RSS<\/code> for the process over a week with <code>ps -o rss= -p PID<\/code>. Flat RSS with rising swap means normal cold pages. Both rising together means restart the service on a schedule while you find the cause, and set a memory limit so it fails predictably rather than dragging the whole box down.<\/p>\n<blockquote><p>Adding swap to a leaking service is like adding a bigger bucket under a leaking roof. It changes when you notice, not what happens.<\/p><\/blockquote>\n<h2>SSD wear and an honest threshold<\/h2>\n<p>Modern SSDs tolerate far more writes than a small VPS will generate, and a swap file on a provider&#8217;s redundant storage is not a serious wear concern at this scale. What does hurt is constant thrashing, which multiplies writes and slows everything else on the host.<\/p>\n<p>Set a simple alarm: alert when used swap exceeds 60 percent for more than fifteen minutes, and when <code>si<\/code>\/<code>so<\/code> stay nonzero for ten consecutive samples. Two alerts, checked by any monitoring tool, catch both the leak and the undersized box.<\/p>\n<h2>Reading your own numbers after a week<\/h2>\n<p>Give the change seven days, then look at three numbers: peak swap used, peak swap-out rate, and free disk. If swap never moved, keep it anyway as insurance and stop tuning. If it filled once during a deploy and recovered, you are sized correctly.<\/p>\n<p>If it sits above half permanently, the honest conclusion is that the workload needs more RAM than a budget plan provides. <a href=\"https:\/\/affordablevpsserver.com\/\">Affordable VPS servers<\/a> with 2 GB double the headroom for a few dollars more, and that is usually a better purchase than a third gigabyte of swap on a disk that was never meant to be memory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR \/ Summary: A 1 GB VPS does not run out of memory suddenly; it gets killed by the kernel when cache and processes crowd the last hundred megabytes. A swap file sized at 1\u20132 GB, low swappiness, and a weekly look at swap-in and swap-out rates will keep a small box stable without shredding [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1678","post","type-post","status-publish","format-standard","hentry","category-cost-optimization-tips"],"blocksy_meta":[],"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>Configuring Swap on a 1 GB VPS Without Wrecking Disk Life - Affordable VPS Server Blog<\/title>\n<meta name=\"description\" content=\"TL;DR \/ Summary: A 1 GB VPS does not run out of memory suddenly; it gets killed by the kernel when cache and processes crowd the last hundred megabytes. A\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life\" \/>\n<meta property=\"og:description\" content=\"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life\" \/>\n<meta property=\"og:url\" content=\"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Affordable VPS Server Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-07T06:37:00+00:00\" \/>\n<meta name=\"author\" content=\"Affordable-Vps-Server-Author\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Affordable-Vps-Server-Author\" \/>\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:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/\",\"url\":\"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/\",\"name\":\"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life - Affordable VPS Server Blog\",\"isPartOf\":{\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#website\"},\"datePublished\":\"2026-11-07T06:37:00+00:00\",\"author\":{\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7\"},\"description\":\"TL;DR \/ Summary: A 1 GB VPS does not run out of memory suddenly; it gets killed by the kernel when cache and processes crowd the last hundred megabytes. A\",\"breadcrumb\":{\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/affordablevpsserver.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#website\",\"url\":\"https:\/\/affordablevpsserver.com\/blog\/\",\"name\":\"Affordable VPS Server Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/affordablevpsserver.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7\",\"name\":\"Affordable-Vps-Server-Author\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8fa20973a7dd04621d396c26ba26b5c5e6c19595583335121958527393f6f95e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8fa20973a7dd04621d396c26ba26b5c5e6c19595583335121958527393f6f95e?s=96&d=mm&r=g\",\"caption\":\"Affordable-Vps-Server-Author\"},\"sameAs\":[\"https:\/\/affordablevpsserver.com\/blog\"],\"url\":\"https:\/\/affordablevpsserver.com\/blog\/author\/affordablevpsserver\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life - Affordable VPS Server Blog","description":"TL;DR \/ Summary: A 1 GB VPS does not run out of memory suddenly; it gets killed by the kernel when cache and processes crowd the last hundred megabytes. A","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:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/","og_locale":"en_US","og_type":"article","og_title":"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life","og_description":"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life","og_url":"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/","og_site_name":"Affordable VPS Server Blog","article_published_time":"2026-11-07T06:37:00+00:00","author":"Affordable-Vps-Server-Author","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Affordable-Vps-Server-Author","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/","url":"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/","name":"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life - Affordable VPS Server Blog","isPartOf":{"@id":"https:\/\/affordablevpsserver.com\/blog\/#website"},"datePublished":"2026-11-07T06:37:00+00:00","author":{"@id":"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7"},"description":"TL;DR \/ Summary: A 1 GB VPS does not run out of memory suddenly; it gets killed by the kernel when cache and processes crowd the last hundred megabytes. A","breadcrumb":{"@id":"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/affordablevpsserver.com\/blog\/swap-file-tuning-one-gigabyte-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/affordablevpsserver.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Configuring Swap on a 1 GB VPS Without Wrecking Disk Life"}]},{"@type":"WebSite","@id":"https:\/\/affordablevpsserver.com\/blog\/#website","url":"https:\/\/affordablevpsserver.com\/blog\/","name":"Affordable VPS Server Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/affordablevpsserver.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7","name":"Affordable-Vps-Server-Author","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8fa20973a7dd04621d396c26ba26b5c5e6c19595583335121958527393f6f95e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8fa20973a7dd04621d396c26ba26b5c5e6c19595583335121958527393f6f95e?s=96&d=mm&r=g","caption":"Affordable-Vps-Server-Author"},"sameAs":["https:\/\/affordablevpsserver.com\/blog"],"url":"https:\/\/affordablevpsserver.com\/blog\/author\/affordablevpsserver\/"}]}},"_links":{"self":[{"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts\/1678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/comments?post=1678"}],"version-history":[{"count":1,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts\/1678\/revisions"}],"predecessor-version":[{"id":1679,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts\/1678\/revisions\/1679"}],"wp:attachment":[{"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/media?parent=1678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/categories?post=1678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/tags?post=1678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}