Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Possible command to boost to laptop performance



Dave M G wrote:
> Recently, I came across this simple command which seems to help.
> Actually, it helps a heck of a lot, though it does raise questions.
> 
> The command is this:
> 
>  sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
> 
> I found it on an Ubuntu forum, so it may be most help to Ubuntu users.
> No promises for other Linux flavours.

In what context did you see it there?
It's usually used to make benchmark runs more reproducible.
E.g. if you are want to measure cold cache program startup time:

Say you want to measure how long firefox takes to start up.
The first time it may take 10 seconds, but if you close it and open
it up again it will be much faster since all the files it needs are
still cached.

If you run above command first it will again take the whole 10
seconds to start up.

What the command does:
It drops pages, directory entries and inodes from the cache.
"echo 1 > /proc/sys/vm/drop_caches" would only drop the page cache
"echo 2 > /proc/sys/vm/drop_caches" would only drop the dentries/inode cache

The sync makes sure dirty pages are committed to disk, so all of the
cache can be dropped (If you leave out the sync, it doesn't throw
away data, it just drops less).

If you think your system is swapping too much, you should try
running without swap (If you never memory-hungry applications that
need swap) or decreasing the 'swappiness' value.
Note that even without swap the kernel still can swap a bit:
It can drop code pages of position-independent libraries and later
reload them from the .so file on disk when it is accessed again.

> I find that on my Ubuntu laptop, running this when the memory and cache
> usage seems high (going by the memory/cache monitor graph Gnome panel
> applet) will cause the memory and cache to drop by half or more. Not
> always, but often enough. As a result, the laptop seems to perform
> better, as I think it's swapping less.

Unless you have measured it to perform better...
High cache usage is a good thing.
Clean cache pages are harmless and can be dropped in a jiffy an app
needs more memory.
Too many dirty cache pages on the other hand can be a problem, but
you will only see that when you system is not idle:
Dirty pages are pages with data updates for the filesystem, that
have not yet been written to disk.
Normally the kernel starts writing those within 30 seconds or so,
but if have a process (say a running dd job) that continues to dirty
memory then your dirty pages can grow up to
/proc/sys/vm/dirty_ratio (20) percent of total system memory.
These can only be dropped after they have been 'cleaned' by writing
them to disk (thus the sync).

And for example 'free' will show you 'cache-corrected' values for
used and free in the second line:
             total       used       free     shared    buffers    cached
Mem:       8050796    7925032     125764          0     408568    5539780
-/+ buffers/cache:    1976684    6074112
Swap:      1959804      16784    1943020


The "-/+ buffers/cache" line here says that while only 125764 KB
are 'free', in reality 6074112 KB are available to applications.

> So what the heck is Ubuntu loading right off the bat that I don't seem
> to need at all? And if it's the case that the things it's loading into
> memory are that useless, might I just go ahead and make that command
> part of the startup applications?

Simple:
All files it read during bootup are in the cache.
Only when memory drops below sys/vm/min_free_kbytes it will start
dropping pages from the cache.
Its not useless, but rather speculative:
"Let's keep it as long as we have free memory left, in case it is
needed again"

You might want to have a look at linux/Documentation/sysctl/vm.txt

-- 
Tobias						PGP: http://8ef7ddba.uguu.de


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links