LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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.

Notices

Reply
 
LinkBack Search this Thread
Old 06-02-2006, 03:29 PM   #16
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860

First of all: don't hijack other threads

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.


Cheers,
Tink
 
Old 06-03-2006, 12:53 PM   #17
tkedwards
Senior Member
 
Registered: Aug 2004
Location: Munich, Germany
Distribution: Opensuse 11.2
Posts: 1,549

Rep: Reputation: 49
Quote:
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)
Even on Windows these 'RAM Recovery' programs are of very, very questionable benefit, see http://mywebpages.comcast.net/SupportCD/XPMyths.html http://www.windowsitpro.com/Article/...1095.html?Ad=1
All you're essentially doing is forcing a large amount of the data in RAM for running programs into swap space which is literally about 1000 times slower to read from because its on disk.

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.
 
Old 04-05-2007, 12:41 PM   #18
mbradlcu
LQ Newbie
 
Registered: Mar 2006
Location: so ca
Posts: 2

Rep: Reputation: 0
swapoff/on worked for me sshfs issue

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!

Quote:
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.. (;
 
Old 08-22-2007, 08:25 PM   #19
winfinit
Member
 
Registered: Jul 2006
Location: FL, Delray Beach
Distribution: Slackware11, LFS
Posts: 67

Rep: Reputation: 15
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
rm 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.

-------------------------------------
####@############:/etc# uname -r
2.6.21
 
Old 08-22-2007, 09:09 PM   #20
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,827

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
Have a look at modifying the swappiness sysctl. It's probably biased toward page-cache by default (say 60) - try 20 for a while and see what happens.

If you want the old (2.4) behaviour set it to zero.
 
Old 08-23-2007, 03:36 AM   #21
Pearlseattle
Member
 
Registered: Aug 2007
Location: Switzerland
Distribution: Gentoo
Posts: 661

Rep: Reputation: 71
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.
 
Old 08-23-2007, 06:39 AM   #22
winfinit
Member
 
Registered: Jul 2006
Location: FL, Delray Beach
Distribution: Slackware11, LFS
Posts: 67

Rep: Reputation: 15
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...

Last edited by winfinit; 08-23-2007 at 06:42 AM.
 
Old 08-23-2007, 05:44 PM   #23
winfinit
Member
 
Registered: Jul 2006
Location: FL, Delray Beach
Distribution: Slackware11, LFS
Posts: 67

Rep: Reputation: 15
here are better ways to flush cache

To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches

(taken from proc.txt kernel docs)
 
Old 08-23-2007, 07:35 PM   #24
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,827

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
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.
 
Old 08-26-2007, 11:35 PM   #25
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,827

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
Quote:
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.
 
Old 08-01-2008, 06:47 AM   #26
careless-one
LQ Newbie
 
Registered: Aug 2008
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by Artanicus View Post
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.

My swap space was cleared by the way.
 
Old 08-03-2008, 05:33 AM   #27
checkmate3001
Member
 
Registered: Sep 2007
Location: Folsom, California
Distribution: Debian 4.0 (Etch), Debian 5.0 (Lenny), Ubuntu 8.04
Posts: 297

Rep: Reputation: 32
I can't figure out what you people are doing. I got 2 gigs of ram and 1 gig swap. I've never touched the swap. never. ram has never filled up either.

I can only assume you have some processes that are eating a lot of cpu ticks.

I would love to see the results to:
Code:
top -n 1
and
Code:
free -m
This should be interesting.
 
Old 08-30-2008, 05:02 PM   #28
gtphonehome
LQ Newbie
 
Registered: Aug 2008
Posts: 2

Rep: Reputation: 0
Smile 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
 
Old 09-14-2008, 12:52 AM   #29
ikyuao
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Rep: Reputation: 0
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.
 
Old 09-15-2008, 09:20 PM   #30
nowshining
Member
 
Registered: Dec 2007
Distribution: Ibex
Posts: 93

Rep: Reputation: 15
http://ramdefrag.sourceforge.net/

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

url:http://ramdefrag.sourceforge.net/

a script u can use

Code:
#!/bin/bash

ramdefrag -c -s

exit 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sendmail, command to flush queue? glock19 Linux - Software 10 11-18-2010 11:23 PM
how to reload sbp2 module /Flush terminal command cache Lakota Mandriva 1 12-07-2004 02:08 PM
Use RAM as swap??? oneandoneis2 Linux - General 3 08-19-2004 04:48 AM
RAM and Swap shiny_spoon Linux - General 5 01-13-2004 02:27 PM
Swap and RAM ? mikeshn Linux - General 1 09-18-2002 09:33 PM


All times are GMT -5. The time now is 12:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration