    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>Linux.com :: Freeing up memory - is there a command? Got workaround.</title>
        <link>http://www.linux.com/archive/forums/topic/3246</link>
        <description>Everything Linux and Open Source</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Linux.com Admin</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.linux.com" /> 
        <admin:errorReportsTo rdf:resource="mailto:noreply@linux.com" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>



<div class="xarbb-noteswrapper">
</div>

   <div class="xarbb-noteswrapper">
       <div class="xar-sub rightnote">
           <div>
                    <a href="http://www.linux.com/archive/forums/topic/3087">
Previous Topic</a>
|
                    <a href="http://www.linux.com/archive/forums/topic/3260">
Next Topic</a>
</div>

           <div>
                    <a href="http://www.linux.com/archive/forums/printtopic/3246?theme=print">
Print this topic</a> |
You are not subscribed            </div>
        </div>
        <div style="clear: both;"></div>
    </div>

    <h1>
        <a class="xar-title" href="http://www.linux.com/archive/forums/topic/3246">Freeing up memory - is there a command? Got workaround.</a>
   </h1>


   <div class="xarbb-topiccontrols">
<form action="http://www.linux.com/archive/forums?func=jump" method="post">
   <label for="xarbb_jump_menu">Forum Jump</label>
    <select name="f" id="xarbb_jump_menu" onchange="this.form.submit();">
        <optgroup label="Options">
            <option value="4" selected="selected">
Please select forum            </option>
            <option value="4">--------------------</option>
        </optgroup>
        <optgroup label="Forums">
                <option value="1">New to Linux</option>
                <option value="2">Hardware</option>
                <option value="3">Linux Distributions</option>
                <option value="4">Applications</option>
                <option value="5">Programming and Development</option>
                <option value="6">Miscellaneous Discussion</option>
                <option value="7">Linux.com Writers Forum</option>
                <option value="8">Jobs</option>
        </optgroup>
    </select>
    <input type="submit" class="button" value="Jump" />
</form>
<div style="clear: both;"></div>
   </div>

   <div class="xarbb-topiccontrols">

<span class="xar-sub">
    <a href="http://www.linux.com/archive/forums">
Forum Index    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/category/4181">
        Forums 
    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/forum/4">
        Applications   </a>
</span>
<div style="clear: both;"></div>
   </div>

<div class="xarbb-tablewrapper">



   <table>
       <tr>
           <th scope="col">
Author</th>
           <th scope="col">
Message</th>
       </tr>



            <tr>
                <td class="xar-norm author">
                    <div>
                        <a href="http://www.linux.com/archive/roles/412276">Konerak</a>
                   </div>
                   <div class="xar-sub">
Joined: Oct 23, 2008<br/>Posts: 2                        <br />
                        <a href="http://www.linux.com/archive/forums?by=412276&amp;func=searchtopics">
Other Topics</a>
                   </div>
               </td>

               <td class="xar-norm message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted Oct 23, 2008 at 8:09:26 AM</span>
                       </div>



<div style="float: left;">
                           <strong class="xar-sub">
Subject: Freeing up memory - is there a command? Got workaround.                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div>
                        Good morning everybody,

at my job we've recently moved our intranet-application from a server hosted by the IT-department to our own linux-server. Now I've had the pleasure of working with linux-, (Free&amp;Open)BSD- and Solaris servers in the past, and I'm adept at UNIX (ksh/bash) as well, but some of the inner workings of linux are still strange to me.

As is this particular problem. I wrote a small perlscript that displays information about our server (uptime, disk usage, memory usage, ping times to other important servers, current users, stats like that). Recently I've began noticing that the amount of free memory (as seen by the command &quot;free&quot; or &quot;free -m&quot;) is always decreasing, but never goes under a 100M. I suspect there's a memory leak somewhere (and chances are high, seeing as the intranet application is completely written in Perl by self-taught programmers (including me!))

Now, [u]funny thing is[/u], when I copy a large file (2GB) and 'sudo vi' it, the system starts responding slowly (as expected), the process uses a lot of memory (as expected) and sometimes even swap is used (as expected). But when I then terminate the vi-session, I &quot;gain&quot; free memory: where I used to have 100MB free left, [b]I now have 2GB again[/b].

So, vi demands memory from the operating system, and when vi terminates, it gives it back. What just amazes me is that the amount of free memory after that is larger than the amount of free memory before.

[b]Now, is there an explanation for that, and/or is there another (faster &amp; non-intrusive) way to reclaim this &quot;free but not free&quot; memory?[/b]

Thanks in advance for all explanations and suggestions,

Kon.</div>

                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/3246#top">
Back to top</a>
</td>
               <td class="xar-alt">

                        <a href="http://www.linux.com/archive/roles/412276">
                            <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                        </a>
                        <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=412276">
                            <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                       </a>
                            <a href="http://">
                                <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                           </a>
</td>
           </tr>





           <tr>
               <td class="xar-norm author">
                   <strong>

                            <a href="http://www.linux.com/archive/roles/401955">
                                Khabi                           </a>
</strong>

                   <span class="xar-sub">
<br />
Joined Apr 21, 2008<br/>Posts: 121<br />
                        <br />
                        <a href="http://www.linux.com/archive/forums?by=401955&amp;func=searchtopics">
Other Topics                        </a>
                    </span>
                </td>

                <td class="xar-accent message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted:
                                Oct 23, 2008 8:49:02 PM                           </span>
                       </div>
                       <div class="rightnote">
</div>
                       <div style="float:left;">
                           <strong class="xar-sub">
Subject:
                                <a name="1201461" href="http://www.linux.com/archive/forums/topic/3246#1201461">
                                    Re:  Freeing up memory - is there a command? Got workaround.                                </a>
                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div style="clear: left;">
                        First off, are you taking into account the cached field in the 'free' command?
[quote]
kalmiya vhosts.d # free -m
             total       used       free     shared    buffers     [b]cached[/b]
Mem:           937        436        501          0        179        119
-/+ buffers/cache:        137        800
Swap:          486          0        486
[/quote]

People always seem to forget about that.  Cached memory is still techincaly *free* memory that can be used.  The OS just doesn't free it, it keeps it there to help speed up other applications that may need the data there.

If thats the case, and it bothers you that its not really *freeing* the memory, you can force the cached memory to clear out by doing:
[quote]echo 1 &gt; /proc/sys/vm/drop_caches[/quote]

There may be a way to configure the kernel to not keep so much in cached memory, but off the top of my head I'm not sure how.
                    </div>
                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/3246#top">
Back to top</a>
</td>

               <td class="xar-alt">

                            <a href="http://www.linux.com/archive/roles/401955">
                                <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                            </a>
                            <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=401955">
                                <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                           </a>
                                <a href="http://">
                                    <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                               </a>
</td>
           </tr>

           <tr>
               <td class="xar-norm author">
                   <strong>

                            <a href="http://www.linux.com/archive/roles/412276">
                                Konerak                           </a>
</strong>

                   <span class="xar-sub">
<br />
Joined Oct 23, 2008<br/>Posts: 2<br />
                        <br />
                        <a href="http://www.linux.com/archive/forums?by=412276&amp;func=searchtopics">
Other Topics                        </a>
                    </span>
                </td>

                <td class="xar-norm message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted:
                                Oct 24, 2008 8:30:37 AM                           </span>
                       </div>
                       <div class="rightnote">
</div>
                       <div style="float:left;">
                           <strong class="xar-sub">
Subject:
                                <a name="1201508" href="http://www.linux.com/archive/forums/topic/3246#1201508">
                                    Freeing up memory - is there a command? Got workaround.                                </a>
                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div style="clear: left;">
                        This was exactly the issue! I was looking for the memory using &quot;top&quot; and sorting on VIRT, and wondered where it went to. Thanks a lot, Khabi, kudos!                    </div>
                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/3246#top">
Back to top</a>
</td>

               <td class="xar-alt">

                            <a href="http://www.linux.com/archive/roles/412276">
                                <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                            </a>
                            <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=412276">
                                <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                           </a>
                                <a href="http://">
                                    <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                               </a>
</td>
           </tr>
</table>
</div>

<div class="xarbb-topiccontrols">

<span class="xar-sub">
    <a href="http://www.linux.com/archive/forums">
Forum Index    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/category/4181">
        Forums 
    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/forum/4">
        Applications   </a>
</span>

</div>



            </channel>
</rss>
