@cdmonkey
2018-12-13T15:21:29.000000Z
字数 2192
阅读 1352
操作系统
http://blog.51cto.com/leejia/1431756
http://www.it165.net/os/html/201404/7813.html
问题现象:系统占用内存高,使用 ps
指令查看,并没有进程占用过多内存。
[root@PBSOSSBACK ~]# free -m
total used free shared buffers cached
Mem: 3817 3345 2735 0 26 142
-/+ buffers/cache: 1012 2805
Swap: 8187 26 8161
# 这时操作系统中已经将主要的工作进程关闭,但内存占用居高不下。
使用 atop
指令进行查看:
[root@PBSOSSBACK ~]# atop
...
MEM | tot 3.7G | free 345.9M | cache 229.4M | dirty 0.0M | buff 26.4M | slab 3.1G |
使用 slabtop
指令查看具体信息:
[root@PBSOSSBACK ~]# slabtop
Active / Total Objects (% used) : 6664857 / 7277229 (91.6%)
Active / Total Slabs (% used) : 850234 / 850235 (100.0%)
Active / Total Caches (% used) : 101 / 188 (53.7%)
Active / Total Size (% used) : 2659946.91K / 2701460.45K (98.5%)
Minimum / Average / Maximum Object : 0.02K / 0.37K / 4096.00K
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
3828156 3275671 85% 0.06K 64884 59 259536K size-64
2163690 2163688 99% 1.02K 721230 3 2884920K nfs_inode_cache
1114180 1114180 100% 0.19K 55709 20 222836K dentry
56721 7647 13% 0.10K 1533 37 6132K buffer_head
...
还可使用 vmstat
指令查看:
[systemusers@PBSOSSBACK ~]$ vmstat -m
Cache Num Total Size Pages
nfs_direct_cache 0 0 200 19
nfs_commit_data 0 0 704 11
nfs_write_data 36 36 960 4
nfs_read_data 0 0 896 4
nfs_inode_cache 2140236 2140236 1048 3
nfs_page 0 0 128 30
...
从 /proc/meminfo
文件中也能够看出问题:
[root@PBSOSSBACK ~]# cat /proc/meminfo
MemTotal: 3909344 kB
MemFree: 125508 kB
Buffers: 26960 kB
Cached: 215080 kB
SwapCached: 1440 kB
Active: 144816 kB
Inactive: 117336 kB
Active(anon): 7204 kB
Inactive(anon): 13528 kB
Active(file): 137612 kB
Inactive(file): 103808 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 8384508 kB
SwapFree: 8357824 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 19524 kB
Mapped: 7612 kB
Shmem: 360 kB
Slab: 3448700 kB # 就是这里
SReclaimable: 3157544 kB
SUnreclaim: 291156 kB
KernelStack: 2816 kB
PageTables: 4032 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 10339180 kB
Committed_AS: 141488 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 168580 kB
VmallocChunk: 34359567224 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 8192 kB
DirectMap2M: 2088960 kB
DirectMap1G: 2097152 kB
解决办法:手动释放
[root@PBSOSSBACK ~]# cat /proc/sys/vm/drop_caches
0 # 这个值的默认值是0
[root@PBSOSSBACK ~]# sync # 将内存中的数据同步至硬盘
# 接下来就是手动释放缓存:
[root@PBSOSSBACK ~]# echo 2 > /proc/sys/vm/drop_caches
[root@PBSOSSBACK ~]# cat /proc/sys/vm/drop_caches
2
可将上述操作配置为定时任务:
# crontab -e
0 */4 * * * sync&&echo 2 >/proc/sys/vm/drop_caches