简体   繁体   English

Linux:内存使用情况和释放交换内存

[英]Linux: memory usage and releasing swap memory

I have observed the below stats on one of my servers. 我在其中一台服务器上观察到以下统计信息。

  1. From the top command, only one process is using 15% of RAM and there are no others 从最高命令开始,只有一个进程正在使用15%的RAM,没有其他进程
  2. There are all 0's under swap-in & swap-out columns of vmstat output vmstat输出的换入和换出列下均为0

But still I am seeing that Swap and RAM both are fully occupied in "free -m" output 但是我仍然看到Swap和RAM都被“ free -m”输出完全占用了

top output 最高输出

Mem:  16413804k total, 16390264k used,    23540k free,    59604k buffers
Swap:  2040244k total,  2040244k used,        0k free,   584688k cached

PID USER        PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+     COMMAND                                                                                                                                                                         
10984 mysql     15   0 3100m 2.4g 5472 S    0 15.5   1129:44    mysqld                                                                                                                                                                          
12773 root      16   0 18440 7916 1064 S    0  0.0   65:46.67   IPremoted                                                                                                                                                                       
3108 ntp        16   0 18984 5720 4652 S    0  0.0   54:35.78   ntpd                                                                                                                                                                            
19694 root      16   0 48996 5708 3656 S    0  0.0   0:00.03    sshd                                                                                                                                                                            
11084 hpsmh     17   0  371m 3892 2532 S    0  0.0   0:00.00    hpsmhd                                                                                                                                                                          

free -m output 自由-m输出

    total  used    free   shared   buffers   cached
Mem:16029  15983   46     0        52        546
-/+ buffers/cache:      
               15384   644
Swap:1992  1992    0

vmstat output vmstat输出

 swap usage
 si   so    
 0    0
 0    0
 0    0
 0    0
 0    0
 0    0
 0    0

Can some one explain this case ? 有人可以解释这种情况吗?

Thanks in advace. 非常感谢。

First you find which process is utilizing the swap space while using below script. 首先,您会发现使用以下脚本时哪个进程正在使用交换空间。

#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
let OVERALL=$OVERALL+$SUM
SUM=0

done
echo "Overall swap used: $OVERALL"

then do the below swapoff -a once swap cleared then swapon -a 然后执行以下swapoff -a,一旦清除掉交换,然后swapon -a

Thanks -Arun 谢谢-阿伦

Swap is not a problem here. 交换在这里不是问题。 But something using more than half of RAM is. 但是使用一半以上RAM的东西却是。

Swap is full with totally useless data, so you have 2 GB more of RAM to do the important stuff. 交换中充满了完全无用的数据,因此您还有2 GB的RAM可以用来做重要的事情。 Good for you! 对你有好处! How I know swap contents are useless? 我怎么知道交换内容没用? Well, zero in si . 好吧, si为零。 No process ever wants to read this back into memory. 任何进程都不想将其读回内存。

Now the problem is: 现在的问题是:

  • 16 GB total RAM 16 GB总RAM
  • minus 3 GB or so used by all processes (I'm guessing you sorted top output properly) 所有进程使用的负3 GB左右(我猜您对顶部输出进行了正确排序)
  • minus 644 MB for cache/buffers/free 负644 MB用于高速缓存/缓冲区/空闲
  • leaves over 12 gigabytes used by what? 剩下超过12 GB的空间被什么使用? Either kernel or some slab or shared memory or some other anonymous pages. 内核,某些平板或共享内存或其他一些匿名页面。 Weird. 奇怪的。 I would examine /proc/meminfo carefully to find out the cause. 我会仔细检查/proc/meminfo以找出原因。

Also don't look at inactive memory statistic as suggested in comments. 也不要看注释中建议的不活动内存统计信息。 It's useless . 这没用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM