{"id":5507,"date":"2016-06-23T10:04:37","date_gmt":"2016-06-23T15:04:37","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=5507"},"modified":"2017-06-14T06:03:18","modified_gmt":"2017-06-14T11:03:18","slug":"great-writeup-on-linux-memory-management","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2016\/06\/23\/great-writeup-on-linux-memory-management\/","title":{"rendered":"Great writeup on Linux memory management"},"content":{"rendered":"<p>&#8230;especially as it relates to committed memory&#8230;<\/p>\n<p><a href=http:\/\/www.etalabs.net\/overcommit.html target=_blank>http:\/\/www.etalabs.net\/overcommit.html<\/a><\/p>\n<pre>\r\nint main() {\r\n  void *m = malloc(6000*1024*1024);\r\n  if (m)\r\n    printf(\"Memory allocation succeeded!\\n\");\r\n  else\r\n    printf(\"Memory allocation failed!\\n\");\r\n  \/\/memset(m,0,2000*1024*1024);\r\n  sleep(30);\r\n  return 0;\r\n}\r\n<\/pre>\n<pre>\r\n[root@cmhlcarchapp01 ~]# sysctl -w vm.overcommit_memory=2\r\n[root@cmhlcarchapp01 ~]# .\/mem &\r\n[1] 7890\r\n[root@cmhlcarchapp01 ~]# Memory allocation succeeded!\r\n\r\n[root@cmhlcarchapp01 ~]# .\/mem &\r\n[2] 7883\r\n[root@cmhlcarchapp01 ~]# Memory allocation failed!\r\n\r\n\r\n[root@cmhlcarchapp01 ~]# sysctl -w vm.overcommit_memory=0\r\n[root@cmhlcarchapp01 ~]# .\/mem &\r\n[1] 7890\r\n[root@cmhlcarchapp01 ~]# Memory allocation succeeded!\r\n\r\n[root@cmhlcarchapp01 ~]# .\/mem &\r\n[2] 7891\r\n[root@cmhlcarchapp01 ~]# Memory allocation succeeded!\r\n<\/pre>\n<p>You can also see an example of the JVM failing if overcommit is disabled&#8230;<\/p>\n<pre>\r\n[root@cmhlcarchapp01 ~]# sysctl -a | grep overcom\r\nvm.overcommit_memory = 0\r\nvm.overcommit_ratio = 50\r\nvm.overcommit_kbytes = 0\r\nvm.nr_overcommit_hugepages = 0\r\n[root@cmhlcarchapp01 ~]# java -Xms6144m -version\r\njava version \"1.7.0_91\"\r\nJava(TM) SE Runtime Environment (build 1.7.0_91-b33)\r\nJava HotSpot(TM) 64-Bit Server VM (build 24.91-b03, mixed mode)\r\n[root@cmhlcarchapp01 ~]# sysctl -w vm.overcommit_memory=2\r\nvm.overcommit_memory = 2\r\n[root@cmhlcarchapp01 ~]# java -Xms6144m -version\r\nError occurred during initialization of VM\r\nCould not reserve enough space for object heap\r\nError: Could not create the Java Virtual Machine.\r\nError: A fatal exception has occurred. Program will exit.\r\n[root@cmhlcarchapp01 ~]#\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8230;especially as it relates to committed memory&#8230; http:\/\/www.etalabs.net\/overcommit.html int main() { void *m = malloc(6000*1024*1024); if (m) printf(&#8220;Memory allocation succeeded!\\n&#8221;); else printf(&#8220;Memory allocation failed!\\n&#8221;); \/\/memset(m,0,2000*1024*1024); sleep(30); return 0; } [root@cmhlcarchapp01 ~]# sysctl -w vm.overcommit_memory=2 [root@cmhlcarchapp01 ~]# .\/mem &#038; [1] 7890&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2016\/06\/23\/great-writeup-on-linux-memory-management\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[28,27],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5507"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=5507"}],"version-history":[{"count":6,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5507\/revisions"}],"predecessor-version":[{"id":6331,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5507\/revisions\/6331"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=5507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=5507"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=5507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}