- how to avoid accessive caching
- Posted by Syed on August 13th, 2003
Hi
on my Linux machine 2.4.20-19.7smp, 80% of memory is used in caching. I
have a DB on this machine and
after starting DB engine all the memory is consumed and swapping starts.
How can tell linux to only cache
50% and leave remainig for other applications to use.
A detailed reply is highly appreciated.
Regards
Syed
- Posted by Steve Wolfe on August 13th, 2003
I don't think you can. However, in general, you really shouldn't need
to. Swapping, in and of itself, isn't necessarily a bad thing, and you're
probably going to find that the answer to your problem is going to lie in
optimizing your database.
When memory is abundant, Linux will use pretty much all of the
available RAM for caching, if needed. That's a good thing. It will also
swap out processes that have not been used in a very long period of time -
the kind of processes that it's actually a benefit to swapping. If
applications start asking for more memory, Linux will happily free up some
of the cache.
As a matter of fact, I got to see that behavior just yesterday while
doing some work on one of our file servers. It has a gig of RAM, which is
nearly entirely used as cache. The free memory was always pegged at just
over 4 *megs*. However, no matter what I did, the free memory still
stayed at about 4 megs: When I opened up more apps, the cache would drop.
When I closed applications, the cache size would increase as disk access
mandated.
The only time you will be swapping out pages that are actually being
used is when the kernel believes that there is a real need for it, a
shortage of memory, and if that's the case, it will rarely use much memory
at all for caching.
Tell us more about which RDBMS you're using, what memory settings
you're using, how much memory is in the machine, and what the numbers for
free/used/cache/buffer/swap look like.
steve
- Posted by Jean-David Beyer on August 13th, 2003
Syed wrote:
To bad there is no Linux FAQ. ;-)
Because this one comes up so often. Linux uses all the memory it can,
devoting it to whatever it thinks most appropriate. It is rare, even on
my 512Megabyte RAM machine for there to be more than about 8 megabytes
free, although at the moment, 22.8Meg are free. Do not worry about it.
Just means Linux thinks the DB engine can use the memory more
effectively than something else, so it is paging out the least recently
used pages in the cache. Technically speaking, it is paging, not
swapping (swapping means entire processes, and paging means only pages).
You could recompile the db application to lock itself to memory. But you
would probably regret it. Remember one of the laws of computer programming:
The more you try to outsmart an operating system, the more it will
outsmart you.
--
.~. Jean-David Beyer Registered Linux User 85642.
/V\ Registered Machine 73926.
/( )\ Shrewsbury, New Jersey http://counter.li.org
^^-^^ 6:05pm up 22 days, 22:57, 2 users, load average: 2.11, 2.10, 2.02
- Posted by Juha Kustaa Siltala on August 13th, 2003
In article <3F3AB731.3010305@exit109.com>, Jean-David Beyer wrote:
http://www.tldp.org/FAQ/Linux-FAQ/ . Debian package: doc-linux-text or
doc-linux-html.
--
Juha Siltala
- Posted by Dave Carrigan on August 14th, 2003
Syed <szaheer@hotmail.com> writes:
Why would you want to? As soon as there is a "real" use for it, Linux
happily gives up memory used for cache. Any application that needs
memory constitutes a real use. So, your system is using 80% of memory
for cache, it's because your application working set only needs 20%.
--
Dave Carrigan
Seattle, WA, USA
dave@rudedog.org | http://www.rudedog.org/ | ICQ:161669680
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-C++-DNS-PalmOS-PostgreSQL-MySQL
- Posted by Ming He on August 16th, 2003
Jean-David Beyer <jdbeyer@exit109.com> writes:
About linux memory management.
For example. I have two processes running. And I like to have both stay
in memory. So I can switch between them real fast. But linux might decide
one process is inactive and paged it out. So when I switch process, it has
to read from disk.
I would like to have some control over this. Like limiting the cache size.
Even windows 3.1 has this capacity.
/ming
- Posted by Peter T. Breuer on August 16th, 2003
Ming He <ming@satan.minghe.org> wrote:
No it doesn't. You can control aspects of paging out like this. But
anyway, "man mlockall". Also man chmod (for the save text bit).
"even"? Are you implying some sort of linear scale on which running
without an integrated cache in MM is level zero?
If you really want to rewrite the standard caching and management
algorithms, go ahead. Be sure and mention to the kernel maintainer
concerned that "even" win 3.1 can do this :-).
Peter
- Posted by Dave Brown on August 17th, 2003
In article <nobmhb.0mh.ln@news.it.uc3m.es>, Peter T. Breuer wrote:
I don't think the SVTX bit will prevent a process from being paged-out.
Its purpose is to keep the code in memory after a process terminates, so
it can be called again, and be found in memory.
On the other hand, unless real memory is depleted by allocation to other
processes, I don't think it's necessarily paged-out, even though idle for
some period of time. I have the impression that some things may be
written to paging space, while still being held in real memory, such that
if paging-out were required, it would already be there.
I don't think disk cache size will affect paging, as it automatically
minimizes as processes occupy real memory.
I often have processes idle for hours on end (eg., a document opened in
acroread, which I started to read and instead got busy at something else).
Yet, paging space stays at 0 usage, so "prepaging" must only take place
when real memory starts to become scarce.
--
Dave Brown Austin, TX