Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Second: don't bump your own posts until 24 hours have passed
Third: What better use do you think the RAM is going to be put
to if it's not used for caching? It's not like Linux kernel will
try to hang onto cache and buffers like ol' Scrouge. If RAM is
needed for apps or data cache/buffers will be flushed.
anyone know of a terminal/run command to clear out my RAM and my swap space? the other OS had a prog called freemem which would clean it out, and older machines would run a bit faster after it. I'd love to flush it out on this work machine I use (pent 2, mepis 3.3)
Linux will automatically use almost all your available RAM for a disk cache (which is why many people think Linux is a memory hog because it always appears to be using all the RAM) and will then feed RAM to programs as they request it. This RAM used for the disk cache is not considered 'in use' because it can instantly be made available for overwriting by any program requesting more RAM, because its just a copy of what's on disk.
Trying to use some kind of 'RAM Optimiser' which requests a huge amount of RAM then frees it again to give the illusion of 'free RAM' would probably dramatically decrease the performance of your computer. It would force the system to dump pretty much all the disk cache and force most running process' data into swap space. In other words you've basically moved everything out of your nice, fast RAM and onto slow disk. And its all unnecessary, there is no need to do this before starting a game or something because Linux will allocate it the RAM it needs.
thanks for the posts all,,
here's my experience:
overnight my sshfs mounts were somehow disconnected, this was indicated by 'df'. Me memory usage was around 400k on a 1m system, and the swap was around 300k,, My system was running super slow with high load avarage >3.5 ..I umount the sshfs mounted dirs, closed most programs. note top indicated no proggys with high %cpu or mem usage. I noticed every program I opened, even a terminal would spike the swap (as seen using gkrellm) I ran 'swapoff' (yes performance was disastrous for a minute) but then my system performance returned to normal.. I then ran 'swapon'.. This is just a guess but it seemed like all programs were not accessing ram but swap,, or at least swap then ram. Regardless I'd like your take on why swapoff fixed my condition.
thanks in advance!
Originally Posted by Artanicus
ive allways just opened ~2000 photos at the same time.. That about fills my gig of RAM and 2 gigs of swap.. (; Tho the even when I need this is very rare. Linux has superior memory management whem compared to other OS:s, so there realy isnt any need to flush the whole ram&swap. If you see 'free' reporting low values, dont forget that many apps like to cache memory, so most of the memory thats missing from free, isnt in use. Freeing cached memory for use by another app isnt strategically slower than using free mem.
Thats just my thoughts on the matter, I know it doesnt answer your question too well.. (;
No linux not clearing cache that is a problem, well it should but it doesnt, you can open 2 shells run top on one and do dd of /dev/zero in size of lets say 2gb, now watch your caching increasing to 2gb and not getting release, now run tar and see what is going to happen... system is going to be veeery slow...
because cache not being flushed as it should, and in fact you will be swapping, which is sucks.
cool way that can help you to clear your memory cache is this
1. Create one large file first for me i am doing 2gb
dd if=/dev/zero of=file bs=1024 count=2000
2. delete that file
what that is going to do is to create a file, put it in the buffer, and by removing it you are making data in a buffer not valid, which will free up your cache...
a little off topic
this problem was noticed by me while uploading file form my system to another one on a network, file was quite large and after uploading was finished i have noticed that system is very slow, i looked at my ram, and i had 30MB free, reason for it is that it is reserved for a system, because all my non system processes will go to swap if ram gets so low. I looked at the 'top' and there are no processes that are taking too much space, i ran free and saw that all ram is cached...
if someone knows fix for this issue please let me know, because at this moment flushing mem manually is not efficient.
I agree with syg00, Tinkster and tkedwards. Use the "sync" command if you want to clear the cache and write dirty buffers to disk, but otherwise the behaviour of using all available RAM to hold cached data is normal and that's how it is supposed to work. If that doesn't make you happy you should have a look at the swappiness level, so that you fix your problem at the source and not run crazy things to fill up RAM, temporarily deactivate swap or similar stuff.
Btw, this article might be interesting.
Last edited by Pearlseattle; 08-23-2007 at 04:00 AM.
my swappiness is set to 30, and sync will not cleat rams cache it clears your disk buffers cache...
also i said, YES it should clear it, and it wasnt a problem until recently, and in fact it does clear the cache automatically if i am running regular applications, it doesnt clear it when you are transferring huge files, and after they being cached to the ram, those files are staying there... even after xfer is complete they will cause rest of the apps to page... the only way i found to clear rams cache is above...
That's the theory. I found it didn't give me the return I expected when I tested this a while back. updatedb is particularly bad at hammering the (memory) allocation system.
Freeing the cache(s) doesn't necessarily provide any benefit if the slabs involved don't become totally free. There is some slab defragmentation updates coming through the mainline that may help. @winfinit may be seeing something similar with the large file transfers.
Freeing the cache(s) doesn't necessarily provide any benefit if the slabs involved don't become totally free. There is some slab defragmentation updates coming through the mainline that may help.
Help may have arrived.
On one of my 2.6.22 kernel machines, using the drop_cache sysctl (3) certainly caused the slab allocation to return to "normal" after an updatedb run.
Won't save you having to be swapped back in if you are out, but should help after that.
I tried that out and the results very pretty disastrous if I had even one byte of swap in use when deactivating it. I managed to save my testmachine by doing a swapon eventhough the swapoff wasnt fully finihed yet.. Was running out ram quick.. d:
I dont recomend taking swap off to clear anything.. There realy is no use in clearing memory unless some areas are better than others, and if thats the case, its time to swap the ram.. d:
Usually the rule for swap or virtual memory in windows size is memory+12. this was referenced in a Windows NT book years ago and I dont agree with it.
Run 'top' as suggested and see how much memory is being consumed and how much swap is being used.
If you are experience a lot of swap usage, you'll need to upgrade ram and theres no real cheating. If you want to free physical ram memory, kill programs you dont need. run ps -ef | less and you can sif through 1000s of processes if its that important or run 'top' and sort by memory usage by pressing 'SHIFT+P' and kill the pid if its safe.
I checked my memory and swap usage. I have 1.5GB of RAM and 2GB swap. 43MB of swap was consumed and 1.3GB RAM in use. running 'swapoff -a' turned swap off and then ran 'swapon -a' and it didnt fase my server as expected, but that is because the ram was not peaked out.
flushing swap due to memory leaks and other things the kernel doesnt handle.
sudo sync && sudo echo done | sudo tee /proc/sys/vm/drop_caches will free up all the ram not in use. useful for machines running unstable software with memory leaks or game emulators that want the ram. no insult to the kernel. in my opinion the computer is a tinker toy anyways
be sure be in root or administrator to run in a console and Try echo 1 > /proc/sys/vm/drop_caches to flush pagecache only or try echo 3 > /proc/sys/vm/drop_caches to flush everything includes pagecache, dentries and inodes if you have 2.6.16 or later kernel versions.
i set a cron job to run a script i made every 5m to auto do this, so far my system has been running more stable.. alas if anyone is going to say anything - with windows ramdefraggers did slow down the system but on linux at least Gutsy it works fine..