{"id":538,"date":"2013-12-13T11:17:54","date_gmt":"2013-12-13T09:17:54","guid":{"rendered":"http:\/\/www.ludovicocaldara.net\/dba\/?p=538"},"modified":"2021-07-13T15:57:31","modified_gmt":"2021-07-13T13:57:31","slug":"real-memory-usage-on-linux","status":"publish","type":"post","link":"https:\/\/www.ludovicocaldara.net\/dba\/real-memory-usage-on-linux\/","title":{"rendered":"Oracle Instances and real memory consumption on Linux and Solaris"},"content":{"rendered":"<p>There&#8217;s a way to know the REAL memory usage by Oracle Instance, including all connecting processes and using the shell rather than a connection to oracle?<\/p>\n<p>The short answer is &#8220;I think so&#8221; \ud83d\ude42<\/p>\n<p>Summing up RSS column from ps output, is not reliable because Linux uses a copy-on-write on process forks and also doesn&#8217;t take into account correctly the shared memory and other shared allocations.<\/p>\n<p>I&#8217;ve come across <a href=\"http:\/\/www.pythian.com\/blog\/oracle-instance-memory-usage\/\">this post on Pythian&#8217;s Blog from Marc Billette<\/a>.<\/p>\n<p>While it seems good I&#8217;ve had discording results depending on platform and release.<\/p>\n<p>Instead, I&#8217;ve tried to create a shell snippet that always uses pmap but works differently and SEEMS to work correctly on Linux ans Solaris.<\/p>\n<p>Basically, using the pmap script I get a lot of information about the different memory areas allocated to the process:<\/p>\n<pre class=\"lang:plsql highlight:0 decode:true\">21010:  ora_d000_db1p\r\n\r\n0000000000400000     208908K r-x--  \/ccv\/app\/oracle\/product\/11.2.0.3\/bin\/oracle\r\n\r\n000000000D012000       1536K rw---  \/ccv\/app\/oracle\/product\/11.2.0.3\/bin\/oracle\r\n\r\n000000000D192000       1040K rw---    [ heap ]\r\n\r\n0000000060000000      12288K rwxs-    [ dism shmid=0x4300000e ]\r\n\r\n0000000080000000    1036288K rwxs-    [ dism shmid=0x7600000f ]\r\n\r\n00000000C0000000         12K rwxs-    [ dism shmid=0x4f000011 ]\r\n\r\nFFFFFD7FFC7A0000         64K rwx--    [ anon ]\r\n\r\nFFFFFD7FFC7BD000        704K rw---    [ anon ]\r\n\r\nFFFFFD7FFC86E000        200K rw---    [ anon ]\r\n\r\nFFFFFD7FFC8A0000        312K rw---    [ anon ]\r\n\r\nFFFFFD7FFC8EF000       1280K rw---    [ anon ]\r\n\r\nFFFFFD7FFCA30000         64K rwx--    [ anon ]\r\n\r\nFFFFFD7FFCA4F000        256K rw---    [ anon ]\r\n\r\nFFFFFD7FFCA90000         64K rwx--    [ anon ]\r\n\r\nFFFFFD7FFCAB0000         36K r-x--  \/lib\/amd64\/libuutil.so.1\r\n...<\/pre>\n<p>&nbsp;<\/p>\n<p>Initially I&#8217;ve tried to decode correctly the different kinds of memory the same way other scripts I&#8217;ve found online do:<\/p>\n<pre class=\"lang:plsql highlight:0 decode:true\">rwxs- = shared memory\r\n\r\nrw--- = private heap\r\n\r\nrwx-- = private code stack\r\n\r\nr-x-- = shared code stack (?)\r\n\r\netc...<\/pre>\n<p>but finally the ADDRESS is the same from different processes when the memory area is shared, so my script now just get a unique line for each address and sums up the memory size (not the rss one!):<\/p>\n<pre class=\"lang:plsql decode:true \">username=`whoami`\r\n\r\nsids=`ps -eaf | grep \"^$username\" | grep pmon | grep -v \" grep \"  | awk '{print substr($NF,10)}'`\r\n\r\n\r\ntotal=0\r\nfor sid in $sids ; do\r\n        pids=`ps -eaf | grep \"^$username\" | grep -- \"$sid\" | grep -v \" grep \" | awk '{print $2}'`\r\n        mem=`pmap $pids 2&gt;&amp;1 | grep \"K \" | sort | awk '{print $1 \" \" substr($2,1,length($2)-1)}' | uniq | awk ' BEGIN { sum=0 } { sum+=$2} END {print sum}' `\r\n\r\n        echo \"$sid : $mem\"\r\n        total=`expr $total + $mem`\r\ndone\r\n\r\necho \"total :  $total\"<\/pre>\n<p>This should give the total virtual memory allocated by the different Oracle instances.<\/p>\n<p>The results I get are plausible both on Linux and Solaris.<\/p>\n<p>Example:<\/p>\n<pre class=\"lang:plsql highlight:0 decode:true\">$ .\/test_mem.ksh\r\n\r\ndb1p: 3334852\r\n\r\ndb2p: 2052048\r\n\r\ndb3p: 6765280\r\n\r\ndb4p: 2687928\r\n\r\ndb5p: 4385616\r\n\r\ntotal :  19225724<\/pre>\n<p>If you find any error let me know and I&#8217;ll fix the script!<\/p>\n<p>&#8212;<\/p>\n<p>Ludovico<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s a way to know the REAL memory usage by Oracle Instance, including all connecting processes and using the shell rather than a connection to oracle? The short answer is &#8220;I think so&#8221; \ud83d\ude42 Summing up RSS column from ps &hellip; <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/real-memory-usage-on-linux\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,326,3,6,1],"tags":[141,139,22,142,65,138,140],"class_list":["post-538","post","type-post","status-publish","format-standard","hentry","category-linux","category-oracle","category-oracledb","category-perf","category-uncategorized","tag-heap","tag-memory-usage","tag-oracle-database","tag-pmap","tag-script","tag-shared-memory","tag-stack"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/comments?post=538"}],"version-history":[{"count":7,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":2070,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/538\/revisions\/2070"}],"wp:attachment":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/media?parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/categories?post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/tags?post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}