{"id":1307,"date":"2026-10-05T22:02:45","date_gmt":"2026-10-05T22:02:45","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1307"},"modified":"2026-10-05T22:02:45","modified_gmt":"2026-10-05T22:02:45","slug":"diagnosing-vm-max-map-count-mmap-exhaustion-vps","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/","title":{"rendered":"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">There is a class of VPS failure that produces no CPU spike, no disk pressure and no obvious OOM message: a process simply cannot create another memory mapping and dies with <code>ENOMEM<\/code> or <code>Cannot allocate memory<\/code> while <code>free<\/code> shows gigabytes available. The culprit is usually <code>vm.max_map_count<\/code>, the kernel limit on how many distinct memory-mapped regions a single process may hold. Elasticsearch, Redis with many keys, JVMs and modern databases all hit it on small hosts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What the limit actually counts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every <code>mmap()<\/code> call creates a virtual memory area (VMA). The kernel tracks them in a per-process red-black tree, and <code>vm.max_map_count<\/code> caps the total. Allocating heap is not the same as mapping: a process can have plenty of free RAM and still exhaust its VMA budget. Read the current limit and see how close a running process is to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/proc\/sys\/vm\/max_map_count\n\n# current VMA count for a given process\nwc -l &lt; \/proc\/$(pidof elasticsearch)\/maps\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the <code>maps<\/code> line count is within a few percent of <code>max_map_count<\/code>, you are on the edge. The next allocation fails, and because the failure arrives as a generic <code>ENOMEM<\/code>, it is routinely misattributed to RAM exhaustion.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Recognising the symptom in logs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The error strings differ by runtime, but they cluster around mapping failures rather than allocation sizes. Grep for them before you start tuning memory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>journalctl -u elasticsearch --since \"1 hour ago\" | grep -iE 'max_map_count|mmap|Cannot allocate memory'\n\n# JVM instances often surface it as a native memory tracking failure\ngrep -r 'OutOfMemoryError: Map failed' \/var\/log\/*.log\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A dead giveaway is that <code>free -m<\/code> shows available memory and swap in good shape while the process still refused to start. That combination points at a limit, not a shortage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Raising the limit safely<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The commonly recommended value for Elasticsearch &mdash; 262144 &mdash; is a reasonable ceiling for a small VPS too. The cost is a slightly larger per-process kernel bookkeeping footprint, which is negligible for the handful of processes a small host runs. Apply it persistently so it survives a reboot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># apply now (non-persistent, good for testing)\nsysctl -w vm.max_map_count=262144\n\n# persist across reboots\necho 'vm.max_map_count=262144' &gt; \/etc\/sysctl.d\/99-max-map-count.conf\nsysctl --system\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Do not crank it to millions &#8220;just in case&#8221;. A process that maps unboundedly is usually leaking mappings, and hiding that behind a huge limit delays the day you find out.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Distinguish mmap exhaustion from real memory pressure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before raising any limit, confirm which failure you actually have. The two look similar in logs but need opposite fixes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Real memory pressure<\/strong> &mdash; <code>MemAvailable<\/code> is low, swap is being used heavily, and the OOM killer fires. Fix by shrinking the working set or the process, not by raising <code>max_map_count<\/code>.<\/li>\n<li><strong>VMA limit<\/strong> &mdash; <code>MemAvailable<\/code> is healthy, no swap storm, but <code>maps<\/code> is pinned at the limit. Fix by raising <code>vm.max_map_count<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Watch both signals together during startup, when mapping counts climb fastest:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>watch -n1 'echo \"maps: $(wc -l &lt; \/proc\/$(pidof mysqld)\/maps)&quot;; grep MemAvailable \/proc\/meminfo&#039;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>maps<\/code> freezes near the limit while <code>MemAvailable<\/code> stays high, the limit is your bottleneck and the fix is above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why this surfaces on small VPS specifically<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Containers, cgroup accounting and modern runtimes all add mappings: glibc arenas, thread stacks, JIT code caches and per-shard file mappings each consume VMAs. On a large host the default limit of 65530 is invisible because the workload is spread thin. On a small instance running a memory-hungry daemon directly, the same default is tight. Being able to right-size these kernel limits is part of why a <a href=\"https:\/\/virtualserversvps.com\/\">well-managed virtual server<\/a> beats a host where you have no visibility into limits at all.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prevention checklist<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set <code>vm.max_map_count=262144<\/code> in <code>\/etc\/sysctl.d\/<\/code> before deploying Elasticsearch, a JVM service, or a sharded database.<\/li>\n<li>Monitor <code>wc -l \/proc\/&lt;pid&gt;\/maps<\/code> during startup, when it peaks.<\/li>\n<li>Alert on the <code>maps<\/code> count approaching the limit, not just on RAM.<\/li>\n<li>Treat repeated mapping growth over days as a leak and profile it, rather than raising the ceiling indefinitely.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">None of this is exotic &mdash; it is one sysctl and one counter. The work is recognising that <code>ENOMEM<\/code> with free memory is a mapping-count problem, and that the fix belongs in the kernel limits of your <a href=\"https:\/\/virtualserversvps.com\/\">virtual server<\/a> rather than in the application.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A VPS can refuse new memory mappings while free RAM is plentiful. Learn to read vm.max_map_count, count a process&#8217;s VMAs in \/proc\/PID\/maps, and fix ENOMEM failures that are not about RAM.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1307","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"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>Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"A VPS can refuse new memory mappings while free RAM is plentiful. Learn to read vm.max_map_count, count a process&#039;s VMAs in \/proc\/PID\/maps, and fix ENOMEM failures that are not about RAM.\" \/>\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\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS\" \/>\n<meta property=\"og:description\" content=\"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T22:02:45+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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/\",\"name\":\"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-10-05T22:02:45+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"A VPS can refuse new memory mappings while free RAM is plentiful. Learn to read vm.max_map_count, count a process's VMAs in \/proc\/PID\/maps, and fix ENOMEM failures that are not about RAM.\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS\"}]},{\"@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":"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS - Virtual Servers VPS Blog","description":"A VPS can refuse new memory mappings while free RAM is plentiful. Learn to read vm.max_map_count, count a process's VMAs in \/proc\/PID\/maps, and fix ENOMEM failures that are not about RAM.","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\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/","og_locale":"en_US","og_type":"article","og_title":"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS","og_description":"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS","og_url":"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-10-05T22:02:45+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/","url":"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/","name":"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-10-05T22:02:45+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"A VPS can refuse new memory mappings while free RAM is plentiful. Learn to read vm.max_map_count, count a process's VMAs in \/proc\/PID\/maps, and fix ENOMEM failures that are not about RAM.","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/diagnosing-vm-max-map-count-mmap-exhaustion-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Diagnosing vm.max_map_count and mmap Exhaustion on a Small VPS"}]},{"@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\/1307","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=1307"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1307\/revisions"}],"predecessor-version":[{"id":1308,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1307\/revisions\/1308"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}