LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Increased cached and swap used (https://www.linuxquestions.org/questions/linux-general-1/increased-cached-and-swap-used-243057/)

pbrugnone 10-15-2004 01:03 PM

Increased cached and swap used
 
Hi,

I read many threads related to "how linux handle system memory" but I cannot really understand how Linux use memory. I'm working with RH 7.3 with 500Mb of RAM and 2 CPUs PIII. I know that memory cache isn't really used by O.S. but why Linux still use memory during system swap?
Here an example of what happen to my system:

top results:

4:16pm up 34 days, 19:54, 1 user, load average: 0.08, 0.04, 0.00
280 processes: 279 sleeping, 1 running, 0 zombie, 0 stopped
CPU0 states: 0.3% user, 3.5% system, 0.0% nice, 95.4% idle
CPU1 states: 0.1% user, 0.0% system, 0.0% nice, 99.5% idle
Mem: 512388K av, 510572K used, 1816K free, 0K shrd, 2392K buff
Swap: 2048888K av, 217056K used, 1831832K free 326244K cached

PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
9128 root 14 0 1280 1280 860 R 4.1 0.2 0:01 top
12995 root 9 0 16868 11M 4368 S 0.1 2.3 12:31 java
13020 root 9 0 16868 11M 4368 S 0.1 2.3 8:42 java
1 root 8 0 124 72 68 S 0.0 0.0 0:25 init
2 root 9 0 0 0 0 SW 0.0 0.0 0:00 keventd
3 root 9 0 0 0 0 SW 0.0 0.0 1:17 kswapd
4 root 9 0 0 0 0 SW 0.0 0.0 0:00 kreclaimd
5 root 9 0 0 0 0 SW 0.0 0.0 0:19 bdflush
6 root 9 0 0 0 0 SW 0.0 0.0 0:20 kupdated
11 root 9 0 0 0 0 SW 0.0 0.0 0:00 khubd
12 root -1 -20 0 0 0 SW< 0.0 0.0 0:00 mdrecoveryd
13 root -1 -20 0 0 0 SW< 0.0 0.0 0:01 raid1d
14 root 19 19 0 0 0 SWN 0.0 0.0 0:01 raid1syncd
15 root -1 -20 0 0 0 SW< 0.0 0.0 0:06 raid1d
16 root 19 19 0 0 0 SWN 0.0 0.0 0:05 raid1syncd
17 root -1 -20 0 0 0 SW< 0.0 0.0 0:00 raid1d
18 root 18 19 0 0 0 SWN 0.0 0.0 0:00 raid1syncd
140 root 9 0 0 0 0 SW 0.0 0.0 0:00 scsi_eh_2
141 root 9 0 0 0 0 SW 0.0 0.0 0:00 scsi_eh_3
584 root 9 0 340 316 252 S 0.0 0.0 0:01 syslogd
589 root 9 0 760 4 4 S 0.0 0.0 0:00 klogd
603 rpc 9 0 92 4 4 S 0.0 0.0 0:00 portmap
618 rpcuser 9 0 104 4 4 S 0.0 0.0 0:00 rpc.statd
704 root 9 0 1968 1968 1712 S 0.0 0.3 0:00 ntpd
750 root 9 0 132 44 44 S 0.0 0.0 0:00 automount
762 daemon 9 0 108 44 36 S 0.0 0.0 0:00 atd
777 root 9 0 532 448 388 S 0.0 0.0 0:01 sshd
797 root 9 0 492 352 272 S 0.0 0.0 0:01 xinetd
809 root 9 0 176 116 76 S 0.0 0.0 0:00 crond
843 root 9 0 64 4 4 S 0.0 0.0 0:00 mingetty
844 root 9 0 64 4 4 S 0.0 0.0 0:00 mingetty
845 root 9 0 64 4 4 S 0.0 0.0 0:00 mingetty
846 root 9 0 64 4 4 S 0.0 0.0 0:00 mingetty
847 root 9 0 64 4 4 S 0.0 0.0 0:00 mingetty
848 root 9 0 64 4 4 S 0.0 0.0 0:00 mingetty
852 root 9 0 164 4 4 S 0.0 0.0 0:00 cmclconfd
853 root 9 0 7544 7544 2460 S 0.0 1.4 0:00 cmcld
855 root 9 0 176 4 4 S 0.0 0.0 0:00 cmclconfd
856 root 9 0 7544 7544 2460 S 0.0 1.4 0:00 cmcld
857 root 9 0 7544 7544 2460 S 0.0 1.4 0:00 cmcld
858 root 9 0 7544 7544 2460 S 0.0 1.4 0:00 cmcld

free -m results:
total used free shared buffers cached
Mem: 500 498 2 0 2 318
-/+ buffers/cache: 177 323
Swap: 2000 211 1788


From the above command it's possible to see that memory really used is 177M and free 323M but swap used is 211 why? Why Linux use 318M to cache and start to swap?

Thanking in advance.

Pierluigi

tredegar 10-15-2004 04:56 PM

Pierluigi,

Relax.

When I first started using linux, I also used to worry about how memory was managed, and how much the hard disk was fragmented. These had been problems with windows (and previously DOS). I soon learnt not to worry: linux handles these things completely differently, and a whole lot better.

The main problems with memory and disk management were sorted out long ago. If you ask linux how much memory is free (mem), it will probably report "very little", and you might start to worry, but any "free" memory is usually allocated to buffers to speed the whole system up. But if the system really needs memory, it will flush the buffers and make it available without any interaction with you. It generally does this in a surprisingly efficient way (unlike that other operating system). Those kernel developers are a clever bunch!

I have two computers, both running mandrake 9.1 One has 64MB memory, the other 1GB. Linux runs fine on both, although I can hear it swapping memory on the smaller computer (the swap partition is on a different and very noisy drive), and of course it it slower, but it does run just fine without falling over.

So: stop worrying, let the kernel do its thing, I'm beginnning to believe it really does know what it is doing.

pbrugnone 10-15-2004 05:33 PM

Hi tredegar,

thanks to your reply.
Unfortunately the problem is that when the system start to use swap memory became very slow as you can know. So I'm looking for to know if the amount of memory it's enough to run a DB server, a web server, several web application, a cluster manager and other processes. I'm sure that my application haven't memory leak problem.
For my purpose it isn't enough to know that everything run properly; my web application should answer in "real time".

tredegar 10-16-2004 05:14 AM

Ok,
So you are running
- A DB server
- A web server
- "several" web applications
- a cluster manager
AND "other processes".

This is quite a lot for 500M, especially if you are also running X, KDE and the rest.

You could either just add more memory, and see if that improves performance, or try starting your applications one-by-one, and working out which one is the real memory hog. Then concentrate on optimising that one.

Hope this helps.


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