How to free memory without rebooting?

Posted on 2006-05-02
Last Modified: 2012-06-21
In my lan I have a linux box that I keep running day and night and that I use for local web tests (php, mysql scripts).

Details: AMD Athlon(TM) XP2100+, 512 MB ram, 1.5 GB swap, 7 GB of free space available.

The other day I was browsing an application that I created using WordPress and it was damn slow. I tried the shell command "free" and in fact I saw all the memory (more than 500 MB) was used and also the swap was being used. I remembered my hosting provider (which sucks) that was often slow the same way. As solution they usually reboot their server in the night :-S ... I did the same and after reboot the the memory usage was about 150 MB. No X Server. Just apache, mysql, samba, dovecot pop3 server and some other startup applications.

Now I know why the memory usage was so high: I was downloading from irc (irssi command line irc client) a file of 700 MB.

I downloaded another file during this night, I closed irssi but now the memory usage appears as follows:

paul@t800:~$ free
             total       used       free     shared    buffers     cached
Mem:        516472     502744      13728          0      50268     303120
-/+ buffers/cache:     149356     367116
Swap:      1566328          0    1566328

Now my webserver runs quite fast but I want to know if there is a way to manually free memory in case I get slowness again.

Under windows (win95, win98) I remember there were some tools like "freemem" to manually clean hundreds of MB of used memory. Is there a linux command or tool to clean all unnecessary memory without rebooting the system?

Thanks fro letting me know.
Question by:firepol
    LVL 15

    Accepted Solution

    To free memory you need to know what is consuming it that much. Whenever you are in the situation when a lot of memory is eaten up by something, run


    and sort by memory size - this will give you a clue what application is a memory hog.

    Most likely it's the Apache with too many unnecessary modules loaded up and too many child processes allowed to run. However, without knowing what other services are running there it's hard to tell.

    If you identify the service that causes the problem you should alter the configuration to set lower memory appetite for that service. To free the memory immediately you can just restart the service, (/etc/rc.d/init.d/<svcname> restart), you don't need to reboot the whole shebang.

    Assisted Solution

    Perhaps this URL can be of some use to explain matters too?
    LVL 2

    Author Comment

    I opened a tightvnc server (fluxbox VM), remotely connected, then I runned konsole. That really slowed down the machine... Not because of kde, because of the memory. I had to wait about 1 minute, but linux freed the memory automatically.

    I'll read the article as soon as I have some time and get back to you guys. Thanks so far.
    LVL 43

    Assisted Solution

    In the above example You have 367116KB free memory - why You want free more?
    Note: -/+ buffers/cache:     149356     367116
    says, that concerning buffers and cache memory, there is 149356K memory used and 367116K free memory(currently used for cache and buffers, but can be released at anytime).
    LVL 14

    Expert Comment


    The physical memory in Linux is automatically free up by the memory management functions of the kernel. You do not need to run any Freemem kind of application.

    After swap is used, you can release the swap memory space by running these 2 commands:

    swapoff -a
    swapon -a

    After that, Linux will only make use of swap the next time when physical RAM is insufficient again, and would not touch the swap when RAM is sufficient.

    LVL 43

    Expert Comment

    The above is not totally true for linux.
    Linux would use swap even there is available memory(instead of freeing cache/buffers it can swap off some long time unused pages)
    Also, I don't recommed using swapoff. First of all it would consume precious RAM, second - Your swap is at 0K usage anyway, third - if the swap is used now, it's very propable that it would get used again very soon - so what's the advanatge?
    LVL 14

    Expert Comment


    Well, if interested, can read this book.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    After running Ubuntu some time, you will be asked to download updates for fixing bugs and security updates. All the packages you download replace the previous ones, except for the kernel, also called "linux-image". This is due to the fact that w…
    The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. Once you open the link you will see …
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now