2003-11-06 08:06:02

by Wee Teck Neo

[permalink] [raw]
Subject: Over used cache memory?

My system having 1GB ram and this is the output of vmstat

procs memory swap io system
cpu
r b w swpd free buff cache si so bi bo in cs us sy
id
0 0 0 5640 21224 121512 797832 0 0 6 9 3 17 0 0
6


It seems that 797MB is used for caching... thats a high number. Anyway to
set a lower cache size?

I've read about the /proc/sys/vm/buffermem but my /proc doesn't have it.

Kernel: 2.4.22

_________________________________________________________________
Get 10mb of inbox space with MSN Hotmail Extra Storage
http://join.msn.com/?pgmarket=en-sg


2003-11-06 08:25:53

by Nick Piggin

[permalink] [raw]
Subject: Re: Over used cache memory?



Wee Teck Neo wrote:

> My system having 1GB ram and this is the output of vmstat
>
> procs memory swap io
> system cpu
> r b w swpd free buff cache si so bi bo in cs
> us sy id
> 0 0 0 5640 21224 121512 797832 0 0 6 9 3 17
> 0 0 6
>
>
> It seems that 797MB is used for caching... thats a high number. Anyway
> to set a lower cache size?
>
> I've read about the /proc/sys/vm/buffermem but my /proc doesn't have it.
>
> Kernel: 2.4.22


Short answer, no.

If it is actually causing you a problem, test the latest 2.4 prerelease.
If that doesn't help, report the details of the problem.


2003-11-06 09:00:01

by Jerry Lundström

[permalink] [raw]
Subject: Re: Over used cache memory?

Wee Teck Neo wrote:
> My system having 1GB ram and this is the output of vmstat
>
> procs memory swap io
> system cpu
> r b w swpd free buff cache si so bi bo in cs us
> sy id
> 0 0 0 5640 21224 121512 797832 0 0 6 9 3 17 0
> 0 6
>
>
> It seems that 797MB is used for caching... thats a high number. Anyway
> to set a lower cache size?
>
> I've read about the /proc/sys/vm/buffermem but my /proc doesn't have it.
>
> Kernel: 2.4.22
>

I don't see the problem? Linux uses unused memory as cache and unless
you have processes using more memory then thats free you dont have a
problem, this is all dynamic and nothing to worry about.

2003-11-06 09:01:52

by Helge Hafting

[permalink] [raw]
Subject: Re: Over used cache memory?

Wee Teck Neo wrote:
> My system having 1GB ram and this is the output of vmstat
>
> procs memory swap io
> system cpu
> r b w swpd free buff cache si so bi bo in cs us
> sy id
> 0 0 0 5640 21224 121512 797832 0 0 6 9 3 17 0
> 0 6
>
>
> It seems that 797MB is used for caching... thats a high number. Anyway
> to set a lower cache size?

Yes - _use_ the memory for something else.
1. All unused memory will be put to good use as cache.
2. Memory is taken from the cache whenever you need it for
something else, so (1) is not a problem at all.

Helge Hafting

2003-11-06 09:16:28

by Jerry Lundström

[permalink] [raw]
Subject: Re: Over used cache memory?

Wee Teck Neo wrote:
> But seems like the swap space is begin used because of "insufficent"
> free memory. I'm not sure if there is a performance slow down.
>

no no no, this is the way linux works. Memory from programs that are not
accessed alot are put into the swap so that the not-so-offen-used memory
can be used by other programs or the cache to speed up everything. When
that program later access the swaped memory it will load it up and
remove some of the cache and after a while it will put it back into the
swap (dont have any numbers on how long till it will but trust linux, it
does it very good).

I wouldnt worry at all about those numbers, they are very common in 1gig
server systems and ive worked with alot of them, even 4gig mem systems
use the swap, thats what its for...

If you are worried about preformance with memory and such after all
configure you systems like this:

If you use IDE have the system disk on one IDE channel and a standalone
swap disk on another IDE channel (not master or slave way but ide0 or
ide1). For SCSI you can just put the swap on a seperate disk.
Doing this will speed up alot of stuff since linux have 100% access to
the swap when it needs too, it doesnt have to share the IO to the disk
with another partition.

Otherwise Id just say, dont worry about it... Linux knows what its doing...

hope it helps...

2003-11-06 09:15:39

by Wee Teck Neo

[permalink] [raw]
Subject: Re: Over used cache memory?

procs memory swap io system
cpu
r b w swpd free buff cache si so bi bo in cs us sy
id
1 0 0 92744 9640 20240 801644 0 0 3 10 17 0 25 2
10


This one will be wierd.

I'm having 4 program running at background using 50MB each (got it from
"top")
Total up to about 200MB.

The system is having 1GB ram and currently using 92MB as swap. Why does the
system use the slower swap when there are still memory available (as cache).
Anyway to "force" the system to use more ram instead of putting into swap
memory?



----Original Message Follows----
From: Helge Hafting <[email protected]>
To: Wee Teck Neo <[email protected]>
CC: [email protected]
Subject: Re: Over used cache memory?
Date: Thu, 06 Nov 2003 10:11:50 +0100

Wee Teck Neo wrote:
>My system having 1GB ram and this is the output of vmstat
>
> procs memory swap io system
>cpu
>r b w swpd free buff cache si so bi bo in cs us sy
>id
>0 0 0 5640 21224 121512 797832 0 0 6 9 3 17 0 0
>6
>
>
>It seems that 797MB is used for caching... thats a high number. Anyway to
>set a lower cache size?

Yes - _use_ the memory for something else. 1. All unused memory will be put
to good use as cache.
2. Memory is taken from the cache whenever you need it for
something else, so (1) is not a problem at all.

Helge Hafting

_________________________________________________________________
Take a break! Find destinations on MSN Travel. http://www.msn.com.sg/travel/

2003-11-06 09:33:24

by Wee Teck Neo

[permalink] [raw]
Subject: Re: Over used cache memory?

Ok...... Thanks got an idea how linux uses memory.

Thanks


----Original Message Follows----
From: Jerry Lundstr?m <[email protected]>
To: Wee Teck Neo <[email protected]>
CC: [email protected]
Subject: Re: Over used cache memory?
Date: Thu, 06 Nov 2003 10:16:19 +0100

Wee Teck Neo wrote:
>But seems like the swap space is begin used because of "insufficent" free
>memory. I'm not sure if there is a performance slow down.
>

no no no, this is the way linux works. Memory from programs that are not
accessed alot are put into the swap so that the not-so-offen-used memory can
be used by other programs or the cache to speed up everything. When that
program later access the swaped memory it will load it up and remove some of
the cache and after a while it will put it back into the swap (dont have any
numbers on how long till it will but trust linux, it does it very good).

I wouldnt worry at all about those numbers, they are very common in 1gig
server systems and ive worked with alot of them, even 4gig mem systems use
the swap, thats what its for...

If you are worried about preformance with memory and such after all
configure you systems like this:

If you use IDE have the system disk on one IDE channel and a standalone swap
disk on another IDE channel (not master or slave way but ide0 or ide1). For
SCSI you can just put the swap on a seperate disk.
Doing this will speed up alot of stuff since linux have 100% access to the
swap when it needs too, it doesnt have to share the IO to the disk with
another partition.

Otherwise Id just say, dont worry about it... Linux knows what its doing...

hope it helps...

_________________________________________________________________
Keep track of Singapore & Malaysia stock prices.
http://www.msn.com.sg/money/

2003-11-06 13:40:37

by jlnance

[permalink] [raw]
Subject: Re: Over used cache memory?

On Thu, Nov 06, 2003 at 10:11:50AM +0100, Helge Hafting wrote:
>
> Yes - _use_ the memory for something else.
> 1. All unused memory will be put to good use as cache.
> 2. Memory is taken from the cache whenever you need it for
> something else, so (1) is not a problem at all.

This is the way it is susposed to work, but I am working on a problem
where this does not seem to be happening. We have a machine with 6G
of ram. It reads some huge files (~5G) and cache fills up. Then
it starts to process the data and goes into a swap storm because it
can not get any memory for the process because it all is in the cache.
If you run top, you see kswapd stuck at the top.

If anyone has any ideas about this, I would love to hear them.

Thanks,

Jim

2003-11-06 14:15:13

by Gianni Tedesco

[permalink] [raw]
Subject: Re: Over used cache memory?

On Thu, 2003-11-06 at 14:40, [email protected] wrote:
> If anyone has any ideas about this, I would love to hear them.

cat /proc/pid/maps of app in question....

most likely it's copying a fsck load of that file in to anonymous
mappings, causing swapping.

If it has a 2GB anonymous mapping and 1GB physical memory, swap will
happen on 1 in 2 pages that that program tries to access, on average.

--
// Gianni Tedesco (gianni at scaramanga dot co dot uk)
lynx --source http://www.scaramanga.co.uk/gianni-at-ecsc.asc | gpg --import
8646BE7D: 6D9F 2287 870E A2C9 8F60 3A3C 91B5 7669 8646 BE7D


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2003-11-06 19:07:10

by Jose Luis Domingo Lopez

[permalink] [raw]
Subject: Re: Over used cache memory?

On Thursday, 06 November 2003, at 17:15:33 +0800,
Wee Teck Neo wrote:

> procs memory swap io system
> cpu
> r b w swpd free buff cache si so bi bo in cs us sy id
> 1 0 0 92744 9640 20240 801644 0 0 3 10 17 0 25 2 10
>
> The system is having 1GB ram and currently using 92MB as swap. Why does the
> system use the slower swap when there are still memory available (as
> cache). Anyway to "force" the system to use more ram instead of putting
> into swap memory?
>
The obvious solution is to disable swap memory completely if those
90 MiB worth of idle and unused memory pages on disk bother you.

If this "vmstat" output shows your box usual load, with 80% of RAM used
in caches, I think you will never really need swap at all.

--
Jose Luis Domingo Lopez
Linux Registered User #189436 Debian Linux Sid (Linux 2.6.0-test9-mm1)

2003-11-06 19:57:41

by Maciej Żenczykowski

[permalink] [raw]
Subject: Re: Over used cache memory?

> On Thursday, 06 November 2003, at 17:15:33 +0800,
> Wee Teck Neo wrote:
>
> > procs memory swap io system
> > cpu
> > r b w swpd free buff cache si so bi bo in cs us sy id
> > 1 0 0 92744 9640 20240 801644 0 0 3 10 17 0 25 2 10
> >
> > The system is having 1GB ram and currently using 92MB as swap. Why does the
> > system use the slower swap when there are still memory available (as
> > cache). Anyway to "force" the system to use more ram instead of putting
> > into swap memory?

Why would you want to? The kernel has determined that 92MB of the stuff
in memory is less important than the disk cache. For example a program
requires 100 MB data for boot and then spends the next week using the last
5 MB. Do you expect all 100 MB to stay resident in memory for ever
(while the program is running)? Of course not, it'll get swapped out once
it is determined to be less used than the disk cache and only that last 5
MB which is actually doing something will remain in RAM, with the rest
quietly sitting in swap. Swap is slower than RAM, sure, but using RAM for
storing your dirty laundry from two weeks ago is pointless - and that's
why it's swapped out - the disk cache will likely accelerate stuff more
than keeping the odds and ends in memory.

Now, if you have lots of cache and the system is swapping like crazy -
then something is wrong, but only then.

> The obvious solution is to disable swap memory completely if those
> 90 MiB worth of idle and unused memory pages on disk bother you.
>
> If this "vmstat" output shows your box usual load, with 80% of RAM used
> in caches, I think you will never really need swap at all.

I wouldn't agree with that - It'll still swap via R/O text executable
pages, so you'll still have swap, just invisible.

Cheers,
MaZe.


2003-11-06 20:50:39

by Daniel Gryniewicz

[permalink] [raw]
Subject: Re: Over used cache memory?

On Thu, 2003-11-06 at 14:57, Maciej Zenczykowski wrote:
> > On Thursday, 06 November 2003, at 17:15:33 +0800,
> > Wee Teck Neo wrote:
> >
> > > procs memory swap io system
> > > cpu
> > > r b w swpd free buff cache si so bi bo in cs us sy id
> > > 1 0 0 92744 9640 20240 801644 0 0 3 10 17 0 25 2 10
> > >
> > > The system is having 1GB ram and currently using 92MB as swap. Why does the
> > > system use the slower swap when there are still memory available (as
> > > cache). Anyway to "force" the system to use more ram instead of putting
> > > into swap memory?
>
> Why would you want to? The kernel has determined that 92MB of the stuff
> in memory is less important than the disk cache. For example a program
> requires 100 MB data for boot and then spends the next week using the last
> 5 MB. Do you expect all 100 MB to stay resident in memory for ever
> (while the program is running)? Of course not, it'll get swapped out once
> it is determined to be less used than the disk cache and only that last 5
> MB which is actually doing something will remain in RAM, with the rest
> quietly sitting in swap. Swap is slower than RAM, sure, but using RAM for
> storing your dirty laundry from two weeks ago is pointless - and that's
> why it's swapped out - the disk cache will likely accelerate stuff more
> than keeping the odds and ends in memory.

Because your mozilla and evolution got swapped out overnight in favor of
cache touched by updatedb? Then, when you get in in the morning, your
mozilla and evolution take forever to swap in, which is very annoying.
Frankly, I don't care at all if the updatedb takes slightly longer due
to less cache space, as long as my evolution and mozilla are not swapped
out. This is why I don't have any swap on my desktop. Responsiveness
of the desktop is much more important to me than any speed-up of
cron-based cache-limited processes.

A possibly better solution to this, in my opinion, would be a way to
mark a working set, which get's swapped in as soon as there's space (ie
as soon as cache get's older than some amount of time). This would
allow mozilla to be swapped out in favor of cache during the night, and
then swapped back in automatically when that cache ages out. Obviously
this would need to be disabled on multiuser systems, but would help, I
believe, on desktops. Then again, I have no time or skill to code it,
so feel free to ignore me completely. :) The "no swap" solution works
great for me.
--
Daniel Gryniewicz <[email protected]>


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2003-11-06 21:47:49

by jlnance

[permalink] [raw]
Subject: Re: Over used cache memory?

On Thu, Nov 06, 2003 at 03:14:32PM +0100, Gianni Tedesco wrote:
> On Thu, 2003-11-06 at 14:40, [email protected] wrote:
> > If anyone has any ideas about this, I would love to hear them.
>

> most likely it's copying a fsck load of that file in to anonymous
> mappings, causing swapping.

Thanks for the reply. Unfortunatly thats not it. I can reproduce this
problem with a little program that appends data to a file and every so
often seeks back to the beginning of the file and scribbles a little there.

Thanks,

Jim