?
Solved

How to free memory without rebooting?

Posted on 2006-05-02
7
Medium Priority
?
435 Views
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.
0
Comment
Question by:firepol
7 Comments
 
LVL 15

Accepted Solution

by:
m1tk4 earned 520 total points
ID: 16586346
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

top

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.
0
 

Assisted Solution

by:ahnberg
ahnberg earned 280 total points
ID: 16586880
Perhaps this URL can be of some use to explain matters too?

http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html
0
 
LVL 2

Author Comment

by:firepol
ID: 16588336
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 43

Assisted Solution

by:ravenpl
ravenpl earned 400 total points
ID: 16588371
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).
0
 
LVL 14

Expert Comment

by:ppfoong
ID: 16593584

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.


0
 
LVL 43

Expert Comment

by:ravenpl
ID: 16593781
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?
0
 
LVL 14

Expert Comment

by:ppfoong
ID: 16594224

Well, if interested, can read this book.

http://www.phptr.com/bookstore/product.asp?isbn=0131453483&rl=1#

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

621 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