On Sat, Oct 15, 2011 at 9:31 AM, Mulyadi Santosa <span dir="ltr">&lt;<a href="mailto:mulyadi.santosa@gmail.com" target="_blank">mulyadi.santosa@gmail.com</a>&gt;</span> wrote:<br>
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi.... :)<br>
<div><br>
On Fri, Oct 14, 2011 at 16:15, pankaj singh &lt;<a href="mailto:psingh.ait@gmail.com" target="_blank">psingh.ait@gmail.com</a>&gt; wrote:<br>
&gt; Nice doc ...:)<br>
&gt;<br>
&gt; On Fri, Oct 14, 2011 at 10:28 AM, rohan puri &lt;<a href="mailto:rohan.puri15@gmail.com" target="_blank">rohan.puri15@gmail.com</a>&gt; wrote:<br>
</div><div>&gt;&gt; Reference to an article by Mulayadi Santosa :-<br>
&gt;&gt;<br>
&gt;&gt; <a href="http://linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-memory.html" target="_blank">http://linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-memory.html</a><br>
&gt;&gt;<br>
&gt;&gt; AWESOME ARTICLE SIR :)<br>
<br>
<br>
</div>Thank you, thank you very much for your appreciation :) I just hope,<br>
besides getting adequate money, you all got something meaningful from<br>
that article. And I believe, as long as there are people who have same<br>
concerned, that article will be refined over and over and overall will<br>
be better through the time :)<br>
<font color="#888888"><br>
--<br>
regards,<br>
<br>
Mulyadi Santosa<br>
Freelance Linux trainer and consultant<br>
<br>
blog: <a href="http://the-hydra.blogspot.com" target="_blank">the-hydra.blogspot.com</a><br>
training: <a href="http://mulyaditraining.blogspot.com" target="_blank">mulyaditraining.blogspot.com</a><br>
</font><div><div></div><div><br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br></div></div></blockquote><div><br> Hi,<br><br>It&#39;s really a fabulous article.<br>
Many many thanks to  Mulyadi for such a great article and thank for Rohan for sharing the link.<br><br>I read the article and correlate contents  with my current issue.<br>Here are my observations. Do please correct me if I&#39;m wrong at any point.<br>
 <br></div></div>The leak  which I was observed in my program is due to big memory buffers of size 5MB allocation from heap.I&#39;ve 6 such character buffers.<br><br>So as per below lines from the article memory should be allocated with mmap and it immediately releases memory to kernel  upon free/delete call from user land process.<br>

<p style="color: rgb(0, 0, 153);">The allocator uses two functions to get a chunk of memory from the kernel:</p>
<span style="color: rgb(0, 0, 153);">





</span>
<ul style="color: rgb(0, 0, 153);"><li><code>brk()</code> sets the end of the process&#39;s data segment.</li><li><code>mmap()</code> creates a new VMA and passes it to the allocator.</li></ul>
<span style="color: rgb(0, 0, 153);">The decision on whether to use </span><code style="color: rgb(0, 0, 153);">brk()</code><span style="color: rgb(0, 0, 153);"> or </span><code style="color: rgb(0, 0, 153);">mmap()</code><span style="color: rgb(0, 0, 153);"> requires one simple check. If the request is equal or larger than </span><code style="color: rgb(0, 0, 153);">M_MMAP_THRESHOLD</code><span style="color: rgb(0, 0, 153);">, the allocator uses </span><code style="color: rgb(0, 0, 153);">mmap()</code><span style="color: rgb(0, 0, 153);">. If it is smaller, the allocator calls </span><code style="color: rgb(0, 0, 153);">brk()</code><span style="color: rgb(0, 0, 153);">. By default, </span><code style="color: rgb(0, 0, 153);">M_MMAP_THRESHOLD</code><span style="color: rgb(0, 0, 153);"> is 128KB</span><br style="color: rgb(0, 0, 153);">
<br>But It seems I&#39;m landed with a case which uses brk() for allocation and so it just marks as free when I my program frees the memory and hence 30 MB memory (I&#39;ve 6 , 5MB buffers from heap)was kept on allocator&#39;s control leading to a 30MB leak of user land process.<br>
Please note that I&#39;m freeing memory for 6 buffers (I&#39;m sure about that).<br><br>Regards,<br>Ravi<br><br><br>