Debian巨大的内存消耗

可能重复:
内存使用在LINUX中

我有一个6天的debian服务器。 它消耗了大量的内存 – 现在有2GB的4GB空间。 它每天保留下100 MB。

这是什么顶部命令说(按res列sorting):

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 

这是正常的。 在你的机器工作的时候,如果没有进程需要内存,那么这个内存就被用于“磁盘caching”。

这实际上意味着什么都不需要的内存用于caching从磁盘中获取的文件,以减less对磁盘IO的需求。

另外你可能想要检查的apacheconfiguration参数是MaxClients MaxRequestsPerChild

这两个将帮助你调整多less阿帕奇将消耗。

与第一个你会设置多less连接在同一时间可以apache服务。 第二个定义了每个线程将被回收的请求数量。 意思是当你的apacheconfiguration设置为“MaxRequestsPerChild 100”,一个线程服务100个请求时,它将被销毁,新的apache线程将取代它。 这是如何影响内存使用情况的,以及每次服务请求内存打印增长时,请求的一些部分保存在内存中以获得更好的性能。

所以,如果MaxRequestsPerChild高,你可能会随着时间的推移使用apache线程的内存使用率很高,这可能会导致OOM杀手激活和杀死随机pid,从而使你的盒子变得瘫痪,所以你需要小心推动价值。

回到一般的内存使用情况,随着时间的推移,所有的内存将被“使用”,但是这是所期望的行为,因为从RAM获取内容比从磁盘获取要快,所以当你看到所有的内存被使用,并且一堆被“caching”担心,如果某个进程需要内存,并且没有find空闲内存,则caching将变小,并且caching中的某些内容将被刷新以允许进程分配所需的内存。