0

Possible Duplicate:
Memory Usage in LINUX

I have a debian server for 6 days now. It's consuming huge amount of memory - 2GB of 4GB available at the moment. It keeps reserving next 100 MB each day.

Here is what top command says (sorted by res column):

top - 00:50:27 up 6 days,  8:27,  1 user,  load average: 0.03, 0.04, 0.06
Tasks: 116 total,   1 running, 115 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.8%us,  0.1%sy,  0.0%ni, 98.0%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   3972480k total,  1984072k used,  1988408k free,   356180k buffers
Swap:  7815612k total,        0k used,  7815612k free,  1404292k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 6790 mysql     20   0  147m  23m 5796 S    0  0.6  20:59.79 mysqld                                                                                                                                                                            6320 root      20   0 13496 9476 1700 S    0  0.2   0:12.96 miniserv.pl
26855 root      20   0 22636 7768 4684 S    0  0.2   0:14.16 apache2                                                                                                                                                                          28866 www-data  20   0 23424 7428 3380 S    0  0.2   0:00.80 apache2                                                                                                                                                                          28953 www-data  20   0 23424 7404 3360 S    0  0.2   0:00.68 apache2
29010 www-data  20   0 23440 7400 3328 S    0  0.2   0:00.40 apache2                                                                                                                                                                          29047 www-data  20   0 23424 7372 3308 S    2  0.2   0:00.30 apache2                                                                                                                                                                          28903 www-data  20   0 23176 7144 3360 S    0  0.2   0:00.76 apache2
28950 www-data  20   0 23168 7136 3356 S    0  0.2   0:00.50 apache2                                                                                                                                                                          29071 www-data  20   0 23176 7136 3356 S    0  0.2   0:00.12 apache2                                                                                                                                                                          29001 www-data  20   0 23076 7132 3392 S    0  0.2   0:00.52 apache2
29002 www-data  20   0 23168 7132 3356 S    0  0.2   0:00.42 apache2                                                                                                                                                                          29041 www-data  20   0 23072 7116 3396 S    0  0.2   0:00.34 apache2                                                                                                                                                                          29049 www-data  20   0 23304 7116 3308 S    1  0.2   0:00.32 apache2
29064 www-data  20   0 23308 7112 3312 S    0  0.2   0:00.18 apache2                                                                                                                                                                          29061 www-data  20   0 23168 7108 3348 S    0  0.2   0:00.08 apache2                                                                                                                                                                          29063 www-data  20   0 23184 7100 3340 S    0  0.2   0:00.08 apache2
28637 www-data  20   0 23180 7092 3384 S    1  0.2   0:01.62 apache2
28989 www-data  20   0 23076 7092 3356 S    0  0.2   0:00.48 apache2
28980 www-data  20   0 23168 7084 3364 S    1  0.2   0:00.48 apache2
28985 www-data  20   0 23076 7084 3360 S    0  0.2   0:00.66 apache2
28967 www-data  20   0 23076 7080 3360 S    0  0.2   0:00.60 apache2
29004 www-data  20   0 23076 7072 3360 S    0  0.2   0:00.28 apache2
29011 www-data  20   0 23076 7072 3356 S    0  0.2   0:00.26 apache2
29080 www-data  20   0 23168 7072 3296 S    0  0.2   0:00.10 apache2
28968 www-data  20   0 23064 7068 3372 S    0  0.2   0:00.56 apache2
28984 www-data  20   0 23180 7068 3356 S    1  0.2   0:00.52 apache2
28983 www-data  20   0 23064 7060 3356 S    0  0.2   0:00.44 apache2
29046 www-data  20   0 23064 7056 3340 S    0  0.2   0:00.28 apache2
29069 www-data  20   0 23184 7056 3356 S    0  0.2   0:00.18 apache2
29044 www-data  20   0 23172 7052 3352 S    0  0.2   0:00.16 apache2
29042 www-data  20   0 23180 7040 3344 S    0  0.2   0:00.30 apache2
29073 www-data  20   0 23312 7040 3296 S    0  0.2   0:00.10 apache2
29050 www-data  20   0 23064 7036 3340 S    0  0.2   0:00.24 apache2
29008 www-data  20   0 23072 7028 3352 S    0  0.2   0:00.32 apache2
29057 www-data  20   0 23056 7028 3340 S    1  0.2   0:00.24 apache2
29087 www-data  20   0 23168 7020 3296 S    0  0.2   0:00.00 apache2
29070 www-data  20   0 23168 7012 3356 S    0  0.2   0:00.06 apache2
29074 www-data  20   0 23168 7004 3312 S    0  0.2   0:00.08 apache2
29054 www-data  20   0 23168 6996 3312 S    0  0.2   0:00.04 apache2
29078 www-data  20   0 23168 6992 3308 S    0  0.2   0:00.08 apache2
29084 www-data  20   0 23168 6920 3280 S    0  0.2   0:00.00 apache2
29076 www-data  20   0 23168 6860 3276 S    0  0.2   0:00.00 apache2
29085 www-data  20   0 23168 6856 3276 S    0  0.2   0:00.00 apache2
29083 www-data  20   0 23168 6820 3276 S    0  0.2   0:00.00 apache2
29081 www-data  20   0 22636 4240 1124 S    0  0.1   0:00.00 apache2
29082 www-data  20   0 22636 4240 1124 S    0  0.1   0:00.00 apache2
29086 www-data  20   0 22636 4240 1124 S    0  0.1   0:00.00 apache2
29088 www-data  20   0 22636 3676  584 S    0  0.1   0:00.00 apache2
20360 root      20   0  8160 2608 2144 S    0  0.1   0:00.06 sshd
 8166 root      20   0 28164 1348  956 S    0  0.0   0:00.77 rsyslogd
 6753 root      20   0  2848 1328 1084 S    0  0.0   0:00.00 mysqld_safe
 6617 root      20   0  5416 1016  660 S    0  0.0   0:00.12 sshd
 2157 root      20   0  2560  992  804 S    0  0.0   0:00.02 cron
 4285 Debian-e  20   0  6256  900  600 S    0  0.0   0:00.00 exim4
 1104 root      16  -4  2288  800  488 S    0  0.0   0:00.06 udevd
    1 root      20   0  2104  688  588 S    0  0.0   0:03.80 init
 6791 root      20   0  1752  528  456 S    0  0.0   0:00.00 logger
 2188 root      20   0  1768  508  436 S    0  0.0   0:00.00 getty
 2190 root      20   0  1768  508  436 S    0  0.0   0:00.00 getty
radek-k
  • 111
  • 3
  • 1
    http://www.linuxatemyram.com/ - To summarize, you are defining free as available for use, top defines free as not being used. You should add the Free + Cached + Buffers values to see what is available for use. You have about 3.6GB available. – Zoredache Feb 17 '11 at 00:02
  • Can I check which files are currently available in memory cache? – radek-k Feb 17 '11 at 10:15

1 Answers1

2

That is normal. As your machine works, if no process needs memory then that memory is used for 'disk cache'.

What that actually means is memory not needed by anything else is used to cache files you have been fetching from disk to reduce need for disk IO.

Also parameters in apache config you might want to check out are MaxClients MaxRequestsPerChild

These two will help you tune how much apache will consume.

With first one you will set how many connections at same time can apache serve. And second one defines after how many requests each of those threads will be recycled. Meaning when you have apache config set to "MaxRequestsPerChild 100" and one thread serves 100 requests, then it will be destroyed, and new apache thread will replace it. How this affects memory usage, well each time it serves request memory print grows, as some parts of request are kept in memory to get better performance.

So if you have high MaxRequestsPerChild you may get to very high memory usage of apache threads over time and that could lead to OOM killer activating and killing random pids and crippling your box, so you need to be careful with pushing the value.

Back on general memory usage, over time all memory will be 'used' but that is desired behavior as it's faster to fetch things from RAM than from disk, so when you see all memory is used, and bunch of it is "cached" no worries, if there is need for memory by some process and no free memory is found , cached will get smaller and some things that were in cached will be flushed to allow process to allocate needed memory.

Hrvoje Špoljar
  • 5,162
  • 25
  • 42
  • Thanks for your reply. Does "1404292k cached" mean that 1,4GB of 2GB reserved memory is for cached files? How can I set a limit for that (in percentage or number of megabytes)? Other question: how can I check which mpm modules are installed in apache server? – radek-k Feb 17 '11 at 10:06
  • I dont think you can limit how much memory can be used for disk cache, as it will use up all free memory available over time, and when that memory needs to be freed up for some process to allocate it will be done, and if processes need a lot of memory eventually your disk cache will be driven down to 0 as memory was needed for other purposes rather than store cached files in it. For apache, you can check list of modules used with something like `apache2ctl -M` – Hrvoje Špoljar Feb 17 '11 at 10:14