Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 31 Oct 2014, 12:42
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Freeing RAM used by Linux for cache/buffers
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
mcewanw

Joined: 16 Aug 2007
Posts: 2348
Location: New Zealand

PostPosted: Sat 06 Jun 2009, 23:41    Post subject:  Freeing RAM used by Linux for cache/buffers  

I picked up the following useful tip in a post by user curaga on the tiny core forum:

First, at the commandline, try running the utility "free" and note the results. (You might want to use "sync" first as BruceB suggests later, though it works without that as it happens).

Now enter the following command and afterwords run "free" again:

Code:
echo 3 > /proc/sys/vm/drop_caches


Eat your heart out Microsoft...



System seems to be just as responsive so perhaps it would be good to do this automatically at boot time?

It would certainly be excellent propaganda for new users who first run "free" to see how much memory their system is using immediately after booting. The results give me a lot of "comfort" on my old 256 MB RAM machine anyway, and it seems that I don't start filling up swap quite as quickly.

In fact there doesn't seem to be any major problem running the above command every now and then when using, for example, Seamonkey or Firefox web browser (though I imagine it will have some temporary effect on system responsiveness in terms of the benefits of cache - not that I'm qualitatively noticing anything negative).

Last edited by mcewanw on Fri 27 Dec 2013, 20:35; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Sun 07 Jun 2009, 01:07    Post subject:  

It is supposed to sync first, example:

Code:
sync && echo 3 > /proc/sys/vm/drop_caches

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
mcewanw

Joined: 16 Aug 2007
Posts: 2348
Location: New Zealand

PostPosted: Sun 07 Jun 2009, 01:45    Post subject: Freeing RAM used by Linux for cache/buffers - use of sync  

Bruce B wrote:
It is supposed to sync first, example:

Code:
sync && echo 3 > /proc/sys/vm/drop_caches


Yes, though the action is "non-destructive" it only drops clean caches so you should indeed do a sync first (also helps avoid possible problems with locking mechanisms).

From http://linux.die.net/man/5/proc:

Quote:

/proc/sys/vm/drop_caches (since Linux 2.6.16)
Writing to this file causes the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

To free pagecache, use echo 1 > /proc/sys/vm/drop_caches; to free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches; to free pagecache, dentries and inodes, use echo 3 > /proc/sys/vm/drop_caches.

Because this is a non-destructive operation and dirty objects are not freeable, the user should run sync(8) first.


Note that in practice the kernel should free cache anyway when applications require more RAM, however the likelihood of that happening depends on how your system is tuned up in terms of "swappiness" (i.e. a characteristic which effects when the vm manager decides to swap out pages of RAM; the "swappiness factor" can be adjusted, but I prefer to stick with the default system "swappiness" settings since they have presumably been tested as reasonably optimal for a typical system configuration).

From http://kerneltrap.org/node/3000
Quote:

a run-time tunable is available through the proc interface for anyone needing to adapt kernel behavior to their own requirements. To tune, simply echo a value from 0 to 100 onto /proc/sys/vm/swappiness. The higher a number set here, the more the system will swap.


It's a compromise of free RAM versus latency (responsiveness).

In practice, I find that the kernel tends to allow my swap space to fill up (i.e. part of virtual memory) such that my lo-RAM system can slow to a crawl. Freeing RAM manually, as above, alleviates the problem.
Back to top
View user's profile Send private message Visit poster's website 
mikeb


Joined: 23 Nov 2006
Posts: 8394

PostPosted: Sun 07 Jun 2009, 18:47    Post subject:  

Interesting post .. cheers

Quote:
In practice, I find that the kernel tends to allow my swap space to fill up (i.e. part of virtual memory) such that my lo-RAM system can slow to a crawl. Freeing RAM manually, as above, alleviates the problem.

I notice a magic 73MB of swap used .. certain apps seem to trigger it as sometimes it remains empty..never spent time tracing the pattern.

mike

edit...actually running this does dramatically drop free readings but in htop and xfce memory monitor very minor and I find the latter 2 more representitive.
Also puppy's free is the busybox one I believe whereas the full version gives a more complete picture....anyway memory management comes under the heading of devine mysteries where buffer, cache and used are all one Very Happy
Back to top
View user's profile Send private message 
mcewanw

Joined: 16 Aug 2007
Posts: 2348
Location: New Zealand

PostPosted: Sun 07 Jun 2009, 21:39    Post subject: sys info "reports" versus actual RAM used  

mikeb wrote:

edit...actually running this does dramatically drop free readings but in htop and xfce memory monitor very minor and I find the latter 2 more representitive.
Also puppy's free is the busybox one I believe whereas the full version gives a more complete picture....anyway memory management comes under the heading of devine mysteries where buffer, cache and used are all one :D


It is important not to confuse the reports output by the various measuring tools with the actual RAM used. htop and xfce mem manager makes a stab at reporting what "would be" the used/free RAM "if" buffers/cache was not being allocated (i.e. what they report is not the free RAM but an arithmetic calculation: RAM usage - buffer/cache usage). The utility "free" on the other hand (either version) makes an attempt to tell you the actual usage (including buffer/cache use). Gnu free has more options than free, but both are limited. All these tools you mention obtain their values from the /proc filesystem; an alternative is just to enter:

Code:

cat /proc/meminfo


The command I gave in the top post (+ sync as described by BruceB) actually DOES clear the RAM as described. htop will not notice the difference because its "calculated" report will be much as before but the RAM itself actually has been flushed as "free" suggests.

If you are interested in more accurately measure RAM usage you would be better to use a tool such as "exmap" http://www.berthels.co.uk/exmap/doc.html which is described along with further information about "free" and so on in the following two article links:

http://ktown.kde.org/~seli/memory/analysis.html
http://www.ibm.com/developerworks/linux/library/l-linux-memory.html

As the ktown article says:

Quote:

Various files in the /proc filesystem can provide information about memory. However they're are poorly documented (linux/Documentation/filesystems/proc.txt) and many of them are broken (and since top and free get their values the same way, they are equally broken). In /proc/PID/ there are several files:

* status - human-readable data about the process, includes some data shown by top
* stat/statm - similar, not in human-readable format
* maps - lists memory mappings of the process . . .
* smaps - lists memory mappings of the process with more details . . .


Note that there is also a utility called vmstat (+ more options than busybox versions of ps, top, w, kill, free, slabtop, and skill) which is available if you have procps installed on your system http://procps.sourceforge.net/
http://www.murga-linux.com/puppy/viewtopic.php?p=275329
http://www.murga-linux.com/puppy/viewtopic.php?p=306327
http://www.murga-linux.com/puppy/viewtopic.php?p=84431

You will notice from the ibm 'developerworks' article that exmap is able to accurately report the memory usage of individual processes and applications, which "free", for example, cannot.

However, as far as I remember exmap needs to be specially compiled for the kernel you are using since it involves a loadable kernel module. It has been compiled and tested on Ubuntu systems, though, so there may be a binary download available which will work with Upup at least.
Back to top
View user's profile Send private message Visit poster's website 
mikeb


Joined: 23 Nov 2006
Posts: 8394

PostPosted: Sun 07 Jun 2009, 22:30    Post subject:  

Thanks for the explanation and further info...plenty to chew on, and certainly buffer/cache clearance is dramatic.
Just one related question...puppy tends towards the use of a swap file intead of the more usual partition...are there any significant differences in performance/usage?
regards

mike
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0711s ][ Queries: 11 (0.0054s) ][ GZIP on ]