V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
通过以下 Referral 链接购买 DigitalOcean 主机,你将可以帮助 V2EX 持续发展
DigitalOcean - SSD Cloud Servers
gamexg
V2EX  ›  VPS

内存被什么占用了?同一个程序,阿里云 2G 内存程序因内存不足被 kill, do 512M VPS 整个系统只占用 240M。

  •  
  •   gamexg · 2016-09-15 20:55:08 +08:00 · 416 次点击
    这是一个创建于 2992 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一个 go 程序,在阿里云 ubuntu14.04 运行的。 free 显示占用了 1.7G 内存,但是我实在找不到这 1.7G 内存被什么占用了...

    root@iZ62hgc3hpoZ:~# free -h
                 total       used       free     shared    buffers     cached
    Mem:          2.0G       1.7G       215M       412K       3.1M        15M
    -/+ buffers/cache:       1.7G       234M
    Swap:           0B         0B         0B
    
    root@iZ62hgc3hpoZ:~# ps auxw|head -1;ps auxw|sort -rn -k4|head -10 
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root      2096  0.7  3.7 798244 76988 pts/0    Sl+  20:33   0:01 ./forward
    root      2066  0.0  0.1  22284  2944 pts/0    Ss   20:31   0:00 -bash
    root      1950  0.0  0.1  22292  2404 pts/3    Ss   19:07   0:00 -bash
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    syslog     368  0.0  0.0 255840   688 ?        Ssl  17:57   0:00 rsyslogd
    root       924  0.0  0.0  15816   160 tty1     Ss+  17:58   0:00 /sbin/getty -8 38400 tty1
    root         9  0.0  0.0      0     0 ?        S    17:57   0:00 [rcu_bh]
    root         8  0.0  0.0      0     0 ?        S    17:57   0:00 [rcuos/0]
    root       777  0.0  0.0  23652   448 ?        Ss   17:57   0:00 cron
    root       774  0.0  0.0  61376   684 ?        Ss   17:57   0:00 /usr/sbin/sshd -D
    
    
    mmon 命令输出:
    lnmonq14gqqqqqq[H for help]qqqHostname=iZ62hgc3hpoZqRefresh= 2secs qqq20:36.11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
    x Memory Stats qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqx
    x                RAM     High      Low     Swap    Page Size=4 KB                                                                            x
    x Total MB      2001.9     -0.0     -0.0      0.0                                                                                            x
    x Free  MB       119.2     -0.0     -0.0      0.0                                                                                            x
    x Free Percent     6.0%   100.0%   100.0%     0.0%                                                                                           x
    x             MB                  MB                  MB                                                                                     x
    x                      Cached=   102.6     Active=   108.2                                                                                   x
    x Buffers=     5.0 Swapcached=     0.0  Inactive =    91.3                                                                                   x
    x Dirty  =     0.0 Writeback =     0.0  Mapped   =     4.8                                                                                   x
    x Slab   =   101.5 Commit_AS =   153.1 PageTables=     2.6                                                                                   x
    xqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqx
    
    
    root@iZ62hgc3hpoZ:~# cat /proc/meminfo 
    MemTotal:        2049904 kB
    MemFree:          124512 kB
    Buffers:            5412 kB
    Cached:           105412 kB
    SwapCached:            0 kB
    Active:           107488 kB
    Inactive:          94048 kB
    Active(anon):      90768 kB
    Inactive(anon):      396 kB
    Active(file):      16720 kB
    Inactive(file):    93652 kB
    Unevictable:           0 kB
    Mlocked:               0 kB
    SwapTotal:             0 kB
    SwapFree:              0 kB
    Dirty:                 0 kB
    Writeback:             0 kB
    AnonPages:         90796 kB
    Mapped:             4696 kB
    Shmem:               412 kB
    Slab:             103948 kB
    SReclaimable:      30260 kB
    SUnreclaim:        73688 kB
    KernelStack:         688 kB
    PageTables:         2616 kB
    NFS_Unstable:          0 kB
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:     1024952 kB
    Committed_AS:     156768 kB
    VmallocTotal:   34359738367 kB
    VmallocUsed:     1697480 kB
    VmallocChunk:   34358029192 kB
    HardwareCorrupted:     0 kB
    AnonHugePages:     36864 kB
    HugePages_Total:       0
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB
    DirectMap4k:       32640 kB
    DirectMap2M:     2064384 kB
    DirectMap1G:           0 kB
    
    slabtop 命令输出:
     Active / Total Objects (% used)    : 379789 / 382445 (99.3%)
     Active / Total Slabs (% used)      : 14435 / 14435 (100.0%)
     Active / Total Caches (% used)     : 64 / 96 (66.7%)
     Active / Total Size (% used)       : 100656.00K / 101729.76K (98.9%)
     Minimum / Average / Maximum Object : 0.01K / 0.27K / 8.00K
    
      OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME                   
     73728  73480  99%    0.06K   1152       64      4608K kmalloc-64
     47712  47712 100%    0.12K   1491       32      5964K kmalloc-128
     32403  32086  99%    0.19K   1543       21      6172K dentry
     26859  26346  98%    0.19K   1279       21      5116K kmalloc-192
     25856  25856 100%    0.02K    101      256       404K kmalloc-16
     25216  25216 100%    0.03K    197      128       788K kmalloc-32
     24976  24976 100%    0.07K    446       56      1784K Acpi-ParseExt
     24432  24147  98%    0.25K   1527       16      6108K kmalloc-256
     23496  23496 100%    0.62K   1958       12     15664K sock_inode_cache
     23436  23436 100%    1.75K   2604        9     41664K TCP
     15408  15408 100%    0.11K    428       36      1712K sysfs_dir_cache
     12792  12426  97%    0.10K    328       39      1312K buffer_head
      6426   5980  93%    0.57K    459       14      3672K inode_cache
      3584   3584 100%    0.01K      7      512        28K kmalloc-8
      2380   2380 100%    0.05K     28       85       112K shared_policy_node
      2288   2207  96%    0.96K    286        8      2288K ext4_inode_cache
      1512   1512 100%    0.07K     27       56       108K anon_vma
      1428   1428 100%    0.04K     14      102        56K ext4_extent_status
      1008   1008 100%    0.09K     24       42        96K kmalloc-96
      1036    873  84%    0.55K     74       14       592K radix_tree_node
       792    792 100%    0.66K     66       12       528K shmem_inode_cache
       544    501  92%    1.00K     68        8       544K kmalloc-1024
       560    496  88%    0.50K     70        8       280K kmalloc-512
       492    431  87%    0.63K     41       12       328K proc_inode_cache
     24976  24976 100%    0.07K    446       56      1784K Acpi-ParseExt
        56     56 100%    0.07K      1       56         4K ext4_io_end
       153    153 100%    0.08K      3       51        12K Acpi-State
         0      0   0%    0.09K      0       46         0K ext4_xattr
    
    root@iZ62hgc3hpoZ:~#  echo `cat /proc/slabinfo |awk 'BEGIN{sum=0;}{sum=sum+$3*$4;}END{print sum/1024/1024}'` MB
    99.3455 MB
    root@iZ62hgc3hpoZ:~# echo `grep PageTables /proc/meminfo | awk '{print $2}'` KB
    2224 KB
    
    
    4 条回复    2016-09-15 21:50:24 +08:00
    selinaspy
        1
    selinaspy  
       2016-09-15 20:57:10 +08:00
    有种东西叫动态内存
    gamexg
        2
    gamexg  
    OP
       2016-09-15 21:06:00 +08:00
    @selinaspy 不明白什么意思,指的应用程序突发内存占用?
    gamexg
        3
    gamexg  
    OP
       2016-09-15 21:17:55 +08:00
    都怀疑是不是 OpenVZ 的那个内存统计问题,但是阿里云使用的是 xen 啊
    gamexg
        4
    gamexg  
    OP
       2016-09-15 21:50:24 +08:00
    确认了问题,是 tcp 协议栈占用的内存,一个最大队列大小设置的太大了。
    但是奇葩的是在其他平台做过相同的配置,却没有出现这个问题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3002 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 12:58 · PVG 20:58 · LAX 04:58 · JFK 07:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.