<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Why (on Linux) am I seeing so much RAM usage?</title>
	<atom:link href="http://chrisjohnston.org/2009/why-on-linux-am-i-seeing-so-much-ram-usage/feed" rel="self" type="application/rss+xml" />
	<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage</link>
	<description>a blog about whatever i feel like blogging about</description>
	<lastBuildDate>Thu, 08 Mar 2012 18:59:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: alieblice</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-26841</link>
		<dc:creator>alieblice</dc:creator>
		<pubDate>Sun, 24 Jul 2011 17:30:03 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-26841</guid>
		<description>nice story</description>
		<content:encoded><![CDATA[<p>nice story</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: babagau</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-8878</link>
		<dc:creator>babagau</dc:creator>
		<pubDate>Wed, 07 Apr 2010 11:46:25 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-8878</guid>
		<description>Excellent and explanatory!</description>
		<content:encoded><![CDATA[<p>Excellent and explanatory!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nate Johnston</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-6423</link>
		<dc:creator>Nate Johnston</dc:creator>
		<pubDate>Tue, 26 Jan 2010 22:05:42 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-6423</guid>
		<description>Chris,

There are some applications that will have issues when confronting a large cache size.  In particular, I had a tomcat that was complaining of memory exhaustion on an 8GB linux host I was able to drop the cache size from 4015 megabytes to 50 megabytes.

First, here is the status quo ante.  The &quot;cached&quot; field indicates the combination of the pagecache, the inode cache, and the dentries cache.  The pagecache is a copy of files on disk for speedier access.  Since this application does not need speedier access to files on disk, the size of this can be tuned down.

[natej@iloga-m02]~% free
            total       used       free     shared    buffers     cached
Mem:       8176800    8111792      65008          0     255144    4109096
-/+ buffers/cache:    3747552    4429248
Swap:      4192880          0    4192880

I checked the kernel cache, but the kernel only reported ~267 megabytes cache.  See the &quot;Active / Total Size&quot; line in the top block of slabtop output:

[natej@iloga-m02]~% slabtop -s c
 Active / Total Objects (% used)    : 1385680 / 1402585 (98.8%)
 Active / Total Slabs (% used)      : 76175 / 76188 (100.0%)
 Active / Total Caches (% used)     : 85 / 133 (63.9%)
 Active / Total Size (% used)       : 271147.38K / 273534.20K (99.1%)
 Minimum / Average / Maximum Object : 0.02K / 0.19K / 128.00K

 OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME
134296 134271  99%    0.82K  33574        4    134296K ext3_inode_cache
1006335 1006166  99%    0.09K  22363       45     89452K buffer_head
169552 169429  99%    0.23K  10597       16     42388K dentry_cache
 37933  37857  99%    0.52K   5419        7     21676K radix_tree_node
 2968   2968 100%    0.55K    424        7      1696K inode_cache
  750    718  95%    2.00K    375        2      1500K size-2048
 2016   2016 100%    0.59K    336        6      1344K proc_inode_cache
  608    608 100%    1.94K    304        2      1216K task_struct
 1112    529  47%    1.00K    278        4      1112K size-1024
  256    256 100%    4.00K    256        1      1024K biovec-(256)
 4686   4461  95%    0.17K    213       22       852K vm_area_struct
  198    188  94%    4.00K    198        1       792K size-4096
 5828   5619  96%    0.12K    188       31       752K size-128

Then I checked the kernel variables for cacheability:

[natej@iloga-m02]/proc/sys/vm% sysctl -A &#124; egrep &quot;swap&#124;cache&quot;
vm.drop_caches = 0
vm.pagecache = 100
vm.vfs_cache_pressure = 100
vm.swappiness = 60
fs.quota.cache_hits = 0

Adjusting the vfs_cache_pressure variable to more aggressively prune the dentry and inode caches doesn&#039;t do much of anything.

But adjusting the maximum size of the pagecache instructing the kernel not to use 100% of memory for cache does help for new cache allocations.

[root@iloga-m02]/proc/sys/vm# echo &quot;10 20 40&quot; &gt; /proc/sys/vm/pagecache

Finally, in order to cause the cache to be freed I used the drop_cache to drop just the clean pages in the pagecache.  Always, always sync thrice before doing this, because in very rare instances it can cause a kernel panic if the number of dirty pages causes the swapout mechanism to choke.

[root@iloga-m02]/proc/sys/vm# free
            total       used       free     shared    buffers     cached
Mem:       8176800    8115404      61396          0     255148    4110724
-/+ buffers/cache:    3749532    4427268
Swap:      4192880          0    4192880
[root@iloga-m02]/proc/sys/vm# sync &amp;&amp; sync &amp;&amp; sync
[root@iloga-m02]/proc/sys/vm# echo 1 &gt; /proc/sys/vm/drop_caches
[root@iloga-m02]/proc/sys/vm# free
            total       used       free     shared    buffers     cached
Mem:       8176800    3680508    4496292          0        608      38832
-/+ buffers/cache:    3641068    4535732
Swap:      4192880          0    4192880

The pagecache can vary upwards, but hopefully it should not grow larger than 20% of RAM under this configuration.  That would be the second of the three numbers page cache is set to.  The pagecache setting could be made permanent across reboots by adding it to /etc/sysctl.conf with the following line syntax. 

vm.pagecache = 10 20 40

Conclusion:
Tuning the dentry and inode caches via vfs_cache_pressure is not necessary.  Those caches were not dropped when I did a drop_cache, yet the requisite bulk of memory was dropped.  I think that in a system with the webserver-like high-network I/O and low disk-I/O profile of the iloga hosts, that adjusting the pagecache variable is enough to get the system to a state where the memory is visibly free.

Information on:
* /proc/sys/vm/drop_caches: &lt;a href=&quot;http://www.redhat.com/magazine/001nov04/features/vm/#pagecache&quot; rel=&quot;nofollow&quot;&gt;http://www.linuxinsight.com/proc_sys_vm_drop_caches.html&lt;/a&gt;
* /proc/sys/vm/pagecache: &lt;a href=&quot;http://www.redhat.com/magazine/001nov04/features/vm/#pagecache&quot; rel=&quot;nofollow&quot;&gt;http://www.redhat.com/magazine/001nov04/features/vm/#pagecache&lt;/a&gt;
* The basics of the pagecache: &lt;a href=&quot;http://www.linux-tutorial.info/modules.php?name=MContent&amp;pageid=310&quot; rel=&quot;nofollow&quot;&gt;http://www.linux-tutorial.info/modules.php?name=MContent&amp;pageid=310&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Chris,</p>
<p>There are some applications that will have issues when confronting a large cache size.  In particular, I had a tomcat that was complaining of memory exhaustion on an 8GB linux host I was able to drop the cache size from 4015 megabytes to 50 megabytes.</p>
<p>First, here is the status quo ante.  The &#8220;cached&#8221; field indicates the combination of the pagecache, the inode cache, and the dentries cache.  The pagecache is a copy of files on disk for speedier access.  Since this application does not need speedier access to files on disk, the size of this can be tuned down.</p>
<p>[natej@iloga-m02]~% free<br />
            total       used       free     shared    buffers     cached<br />
Mem:       8176800    8111792      65008          0     255144    4109096<br />
-/+ buffers/cache:    3747552    4429248<br />
Swap:      4192880          0    4192880</p>
<p>I checked the kernel cache, but the kernel only reported ~267 megabytes cache.  See the &#8220;Active / Total Size&#8221; line in the top block of slabtop output:</p>
<p>[natej@iloga-m02]~% slabtop -s c<br />
 Active / Total Objects (% used)    : 1385680 / 1402585 (98.8%)<br />
 Active / Total Slabs (% used)      : 76175 / 76188 (100.0%)<br />
 Active / Total Caches (% used)     : 85 / 133 (63.9%)<br />
 Active / Total Size (% used)       : 271147.38K / 273534.20K (99.1%)<br />
 Minimum / Average / Maximum Object : 0.02K / 0.19K / 128.00K</p>
<p> OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME<br />
134296 134271  99%    0.82K  33574        4    134296K ext3_inode_cache<br />
1006335 1006166  99%    0.09K  22363       45     89452K buffer_head<br />
169552 169429  99%    0.23K  10597       16     42388K dentry_cache<br />
 37933  37857  99%    0.52K   5419        7     21676K radix_tree_node<br />
 2968   2968 100%    0.55K    424        7      1696K inode_cache<br />
  750    718  95%    2.00K    375        2      1500K size-2048<br />
 2016   2016 100%    0.59K    336        6      1344K proc_inode_cache<br />
  608    608 100%    1.94K    304        2      1216K task_struct<br />
 1112    529  47%    1.00K    278        4      1112K size-1024<br />
  256    256 100%    4.00K    256        1      1024K biovec-(256)<br />
 4686   4461  95%    0.17K    213       22       852K vm_area_struct<br />
  198    188  94%    4.00K    198        1       792K size-4096<br />
 5828   5619  96%    0.12K    188       31       752K size-128</p>
<p>Then I checked the kernel variables for cacheability:</p>
<p>[natej@iloga-m02]/proc/sys/vm% sysctl -A | egrep &#8220;swap|cache&#8221;<br />
vm.drop_caches = 0<br />
vm.pagecache = 100<br />
vm.vfs_cache_pressure = 100<br />
vm.swappiness = 60<br />
fs.quota.cache_hits = 0</p>
<p>Adjusting the vfs_cache_pressure variable to more aggressively prune the dentry and inode caches doesn&#8217;t do much of anything.</p>
<p>But adjusting the maximum size of the pagecache instructing the kernel not to use 100% of memory for cache does help for new cache allocations.</p>
<p>[root@iloga-m02]/proc/sys/vm# echo &#8220;10 20 40&#8243; &gt; /proc/sys/vm/pagecache</p>
<p>Finally, in order to cause the cache to be freed I used the drop_cache to drop just the clean pages in the pagecache.  Always, always sync thrice before doing this, because in very rare instances it can cause a kernel panic if the number of dirty pages causes the swapout mechanism to choke.</p>
<p>[root@iloga-m02]/proc/sys/vm# free<br />
            total       used       free     shared    buffers     cached<br />
Mem:       8176800    8115404      61396          0     255148    4110724<br />
-/+ buffers/cache:    3749532    4427268<br />
Swap:      4192880          0    4192880<br />
[root@iloga-m02]/proc/sys/vm# sync &amp;&amp; sync &amp;&amp; sync<br />
[root@iloga-m02]/proc/sys/vm# echo 1 &gt; /proc/sys/vm/drop_caches<br />
[root@iloga-m02]/proc/sys/vm# free<br />
            total       used       free     shared    buffers     cached<br />
Mem:       8176800    3680508    4496292          0        608      38832<br />
-/+ buffers/cache:    3641068    4535732<br />
Swap:      4192880          0    4192880</p>
<p>The pagecache can vary upwards, but hopefully it should not grow larger than 20% of RAM under this configuration.  That would be the second of the three numbers page cache is set to.  The pagecache setting could be made permanent across reboots by adding it to /etc/sysctl.conf with the following line syntax. </p>
<p>vm.pagecache = 10 20 40</p>
<p>Conclusion:<br />
Tuning the dentry and inode caches via vfs_cache_pressure is not necessary.  Those caches were not dropped when I did a drop_cache, yet the requisite bulk of memory was dropped.  I think that in a system with the webserver-like high-network I/O and low disk-I/O profile of the iloga hosts, that adjusting the pagecache variable is enough to get the system to a state where the memory is visibly free.</p>
<p>Information on:<br />
* /proc/sys/vm/drop_caches: <a href="http://www.redhat.com/magazine/001nov04/features/vm/#pagecache" rel="nofollow">http://www.linuxinsight.com/proc_sys_vm_drop_caches.html</a><br />
* /proc/sys/vm/pagecache: <a href="http://www.redhat.com/magazine/001nov04/features/vm/#pagecache" rel="nofollow">http://www.redhat.com/magazine/001nov04/features/vm/#pagecache</a><br />
* The basics of the pagecache: <a href="http://www.linux-tutorial.info/modules.php?name=MContent&amp;pageid=310" rel="nofollow">http://www.linux-tutorial.info/modules.php?name=MContent&#038;pageid=310</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kersurk</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-4321</link>
		<dc:creator>kersurk</dc:creator>
		<pubDate>Fri, 18 Sep 2009 06:11:28 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-4321</guid>
		<description>&quot;OR imagine you like a song. You record it to the beginning of a cassette tape. When you want a new song, do you re-record over the first song or record after it?&quot;

Damn, it&#039;s 2009 :) Who on earth uses the cassette tapes for recording anymore.
Anyhow, thanks for the explanation.</description>
		<content:encoded><![CDATA[<p>&#8220;OR imagine you like a song. You record it to the beginning of a cassette tape. When you want a new song, do you re-record over the first song or record after it?&#8221;</p>
<p>Damn, it&#8217;s 2009 <img src='http://chrisjohnston.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Who on earth uses the cassette tapes for recording anymore.<br />
Anyhow, thanks for the explanation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: syamsul</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-3671</link>
		<dc:creator>syamsul</dc:creator>
		<pubDate>Sun, 19 Jul 2009 05:56:39 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-3671</guid>
		<description>Thanks Chris for the insightful article. Just one question - do  OpenVZ and Xen based VPSes differ in the way they manage/allocate memory?

The reason I&#039;m asking is that on my OpenVZ VPS, I hardly see anything under Buffers or Cached after doing a free -m.

OTOH, the Xen VPS seems to be allocating quite a bit to buffers and cache like you said.</description>
		<content:encoded><![CDATA[<p>Thanks Chris for the insightful article. Just one question &#8211; do  OpenVZ and Xen based VPSes differ in the way they manage/allocate memory?</p>
<p>The reason I&#8217;m asking is that on my OpenVZ VPS, I hardly see anything under Buffers or Cached after doing a free -m.</p>
<p>OTOH, the Xen VPS seems to be allocating quite a bit to buffers and cache like you said.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JT</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-3318</link>
		<dc:creator>JT</dc:creator>
		<pubDate>Wed, 27 May 2009 07:08:43 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-3318</guid>
		<description>Re: Chris Routh&#039;s comment above about being green.

More information in RAM doesn&#039;t mean more power consumption (or vise versa). Most memory technology is made up of &quot;destructive technology&quot; (capacitors) because it&#039;s so cheap. Whenever a bit is read it&#039;s destroyed. Picture a bottle of water with the outside painted completely black. You have to empty it to know what&#039;s inside! This happens billions of times a second.

Now, pretend there&#039;s a hole in the bottle of water with the outside painted black. You&#039;d have to empty and refill it just to make sure it retained some semblance of its contents. This is true of memory too. Capacitors are like leaky water tanks that continually drain. The computer has to read (which takes power), calculate (which takes power), and write (which takes power too) thousands of times a second just to keep information in memory. More goes into it, of course, but in the grand scheme of things, it doesn&#039;t matter whether the information is full or not in terms of power consumption.

Not to mention that unallocated memory is undefined and can be all 1s, all 0s, or any combination of the two ;-).</description>
		<content:encoded><![CDATA[<p>Re: Chris Routh&#8217;s comment above about being green.</p>
<p>More information in RAM doesn&#8217;t mean more power consumption (or vise versa). Most memory technology is made up of &#8220;destructive technology&#8221; (capacitors) because it&#8217;s so cheap. Whenever a bit is read it&#8217;s destroyed. Picture a bottle of water with the outside painted completely black. You have to empty it to know what&#8217;s inside! This happens billions of times a second.</p>
<p>Now, pretend there&#8217;s a hole in the bottle of water with the outside painted black. You&#8217;d have to empty and refill it just to make sure it retained some semblance of its contents. This is true of memory too. Capacitors are like leaky water tanks that continually drain. The computer has to read (which takes power), calculate (which takes power), and write (which takes power too) thousands of times a second just to keep information in memory. More goes into it, of course, but in the grand scheme of things, it doesn&#8217;t matter whether the information is full or not in terms of power consumption.</p>
<p>Not to mention that unallocated memory is undefined and can be all 1s, all 0s, or any combination of the two <img src='http://chrisjohnston.org/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Routh</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-3175</link>
		<dc:creator>Chris Routh</dc:creator>
		<pubDate>Wed, 13 May 2009 23:13:25 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-3175</guid>
		<description>What about the green argument? Holding information in RAM requires power to keep it there, or else the computer forgets it. RAM that has nothing in it has no power cost to the system, therefore you are being more power-wise by keeping system memory clear?</description>
		<content:encoded><![CDATA[<p>What about the green argument? Holding information in RAM requires power to keep it there, or else the computer forgets it. RAM that has nothing in it has no power cost to the system, therefore you are being more power-wise by keeping system memory clear?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rod</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-3167</link>
		<dc:creator>rod</dc:creator>
		<pubDate>Wed, 13 May 2009 02:58:12 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-3167</guid>
		<description>that was a pretty awesome article, halfway trough it i had my &quot;oh.. duh&quot; moment. :D</description>
		<content:encoded><![CDATA[<p>that was a pretty awesome article, halfway trough it i had my &#8220;oh.. duh&#8221; moment. <img src='http://chrisjohnston.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrea</title>
		<link>http://chrisjohnston.org/ubuntu/why-on-linux-am-i-seeing-so-much-ram-usage/comment-page-1#comment-2845</link>
		<dc:creator>Andrea</dc:creator>
		<pubDate>Fri, 01 May 2009 22:09:44 +0000</pubDate>
		<guid isPermaLink="false">http://chrisjohnston.org/?p=358#comment-2845</guid>
		<description>Nice article :)</description>
		<content:encoded><![CDATA[<p>Nice article <img src='http://chrisjohnston.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

