|
|
Posted Oct 23, 2008 at 8:09:26 AM
Subject: Freeing up memory - is there a command? Got workaround.
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&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 "free" or "free -m") 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 "gain" 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 & non-intrusive) way to reclaim this "free but not free" memory?[/b]
Thanks in advance for all explanations and suggestions,
Kon.
|
Khabi
Joined Apr 21, 2008 Posts: 121
Other Topics
|
Posted:
Oct 23, 2008 8:49:02 PM
Subject: Freeing up memory - is there a command? Got workaround.
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 > /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.
|
Konerak
Joined Oct 23, 2008 Posts: 2
Other Topics
|
Posted:
Oct 24, 2008 8:30:37 AM
Subject: Freeing up memory - is there a command? Got workaround.
This was exactly the issue! I was looking for the memory using "top" and sorting on VIRT, and wondered where it went to. Thanks a lot, Khabi, kudos!
|