zoukankan      html  css  js  c++  java
  • 内核内存泄露

    问题如下:使用仪器测试盒子设备 ipv6 完毕后,发现内存降不下去

    1、简单分析 slabinfo 以及buffinfo

     Develop>cat /proc/slabinfo 
    slabinfo - version: 2.1
    # name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
    ext4_groupinfo_4k  30296  30296    144   28    1 : tunables    0    0    0 : slabdata   1082   1082      0
    bio-1               1325   1325   1280   25    8 : tunables    0    0    0 : slabdata     53     53      0
    ext4_groupinfo_1k    120    120    136   30    1 : tunables    0    0    0 : slabdata      4      4      0
    RAWv6                 26     26   1216   26    8 : tunables    0    0    0 : slabdata      1      1      0
    UDPLITEv6              0      0   1216   26    8 : tunables    0    0    0 : slabdata      0      0      0
    UDPv6                416    416   1216   26    8 : tunables    0    0    0 : slabdata     16     16      0
    tw_sock_TCPv6          0      0    280   29    2 : tunables    0    0    0 : slabdata      0      0      0
    request_sock_TCPv6 7105488 7105488    416   39    4 : tunables    0    0    0 : slabdata 182192 182192      0
    TCPv6             7105434 7107315   2176   15    8 : tunables    0    0    0 : slabdata 473821 473821      0
    nf_conntrack_1         0      0    320   25    2 : tunables    0    0    0 : slabdata      0      0      0
    dm_bio_prison_cell      0      0     96   42    1 : tunables    0    0    0 : slabdata      0      0      0
    kcopyd_job             0      0   3312    9    8 : tunables    0    0    0 : slabdata      0      0      0
    dm_uevent              0      0   2632   12    8 : tunables    0    0    0 : slabdata      0      0      0
    cfq_queue            560    560    232   35    2 : tunables    0    0    0 : slabdata     16     16      0
    bsg_cmd                0      0    312   26    2 : tunables    0    0    0 : slabdata      0      0      0
    mqueue_inode_cache     36     36    896   36    8 : tunables    0    0    0 : slabdata      1      1      0
    au_finfo            4223   4448    256   32    2 : tunables    0    0    0 : slabdata    139    139      0
    au_icntnr           3060   3060    896   36    8 : tunables    0    0    0 : slabdata     85     85      0
    au_dinfo           20544  20544    256   32    2 : tunables    0    0    0 : slabdata    642    642      0
    fuse_request           0      0    400   40    4 : tunables    0    0    0 : slabdata      0      0      0
    fuse_inode             0      0    768   42    8 : tunables    0    0    0 : slabdata      0      0      0
    ecryptfs_key_record_cache      0      0    576   28    4 : tunables    0    0    0 : slabdata      0      0      0
    ecryptfs_inode_cache      0      0   1024   32    8 : tunables    0    0    0 : slabdata      0      0      0
    ecryptfs_file_cache      0      0     16  256    1 : tunables    0    0    0 : slabdata      0      0      0
    isofs_inode_cache      0      0    616   26    4 : tunables    0    0    0 : slabdata      0      0      0
    exfat_inode_cache      0      0    752   43    8 : tunables    0    0    0 : slabdata      0      0      0
    fat_inode_cache        0      0    704   46    8 : tunables    0    0    0 : slabdata      0      0      0
    fat_cache              0      0     40  102    1 : tunables    0    0    0 : slabdata      0      0      0
    hugetlbfs_inode_cache     84     84    584   28    4 : tunables    0    0    0 : slabdata      3      3      0
    jbd2_journal_handle   1360   1360     48   85    1 : tunables    0    0    0 : slabdata     16     16      0
    jbd2_journal_head    544    544    120   34    1 : tunables    0    0    0 : slabdata     16     16      0
    jbd2_revoke_table_s   1536   1536     16  256    1 : tunables    0    0    0 : slabdata      6      6      0
    jbd2_revoke_record_s    640    640     32  128    1 : tunables    0    0    0 : slabdata      5      5      0
    ext2_inode_cache      82     82    792   41    8 : tunables    0    0    0 : slabdata      2      2      0
    ext4_inode_cache   41550  41550   1072   30    8 : tunables    0    0    0 : slabdata   1385   1385      0
    ext4_free_data      1024   1024     64   64    1 : tunables    0    0    0 : slabdata     16     16      0
    ext4_allocation_context   4640   4640    128   32    1 : tunables    0    0    0 : slabdata    145    145      0
    ext4_io_end          952    952     72   56    1 : tunables    0    0    0 : slabdata     17     17      0
    ext4_extent_status   4080   4080     40  102    1 : tunables    0    0    0 : slabdata     40     40      0
    reiser_inode_cache   2653   2924    752   43    8 : tunables    0    0    0 : slabdata     68     68      0
    dquot                512    512    256   32    2 : tunables    0    0    0 : slabdata     16     16      0
    kioctx                 0      0    896   36    8 : tunables    0    0    0 : slabdata      0      0      0
    userfaultfd_ctx_cache      0      0    128   32    1 : tunables    0    0    0 : slabdata      0      0      0
    fsnotify_mark          0      0     80   51    1 : tunables    0    0    0 : slabdata      0      0      0
    dnotify_struct       128    128     32  128    1 : tunables    0    0    0 : slabdata      1      1      0
    pid_namespace          0      0   2224   14    8 : tunables    0    0    0 : slabdata      0      0      0
    posix_timers_cache    102    102    240   34    2 : tunables    0    0    0 : slabdata      3      3      0
    UNIX                 448    448   1152   28    8 : tunables    0    0    0 : slabdata     16     16      0
    ip4-frags              0      0    216   37    2 : tunables    0    0    0 : slabdata      0      0      0
    UDP-Lite               0      0   1024   32    8 : tunables    0    0    0 : slabdata      0      0      0
    flow_cache             0      0    112   36    1 : tunables    0    0    0 : slabdata      0      0      0
    UDP                  512    512   1024   32    8 : tunables    0    0    0 : slabdata     16     16      0
    tw_sock_TCP            0      0    280   29    2 : tunables    0    0    0 : slabdata      0      0      0
    request_sock_TCP     624    624    416   39    4 : tunables    0    0    0 : slabdata     16     16      0
    TCP                  672    672   2048   16    8 : tunables    0    0    0 : slabdata     42     42      0
    eventpoll_pwq       5824   5824     72   56    1 : tunables    0    0    0 : slabdata    104    104      0
    blkdev_queue         216    216   1336   24    8 : tunables    0    0    0 : slabdata      9      9      0
    blkdev_requests      924    924    368   44    4 : tunables    0    0    0 : slabdata     21     21      0
    blkdev_ioc           624    624    104   39    1 : tunables    0    0    0 : slabdata     16     16      0
    khugepaged_mm_slot   3570   3570     40  102    1 : tunables    0    0    0 : slabdata     35     35      0
    sock_inode_cache    3583   3750    640   25    4 : tunables    0    0    0 : slabdata    150    150      0
    skbuff_fclone_cache   3250   3275    640   25    4 : tunables    0    0    0 : slabdata    131    131      0
    skbuff_head_cache   1385   1700    320   25    2 : tunables    0    0    0 : slabdata     68     68      0
    file_lock_cache      624    624    208   39    2 : tunables    0    0    0 : slabdata     16     16      0
    net_namespace          0      0   7424    4    8 : tunables    0    0    0 : slabdata      0      0      0
    shmem_inode_cache   3816   3816    656   24    4 : tunables    0    0    0 : slabdata    159    159      0
    taskstats            384    384    328   24    2 : tunables    0    0    0 : slabdata     16     16      0
    proc_inode_cache    8362   8788    624   26    4 : tunables    0    0    0 : slabdata    338    338      0
    sigqueue             425    425    160   25    1 : tunables    0    0    0 : slabdata     17     17      0
    bdev_cache           585    585    832   39    8 : tunables    0    0    0 : slabdata     15     15      0
    kernfs_node_cache  26619  26860    120   34    1 : tunables    0    0    0 : slabdata    790    790      0
    mnt_cache           1554   1554    384   42    4 : tunables    0    0    0 : slabdata     37     37      0
    inode_cache         7771   8008    568   28    4 : tunables    0    0    0 : slabdata    286    286      0
    dentry            130056 135786    192   42    2 : tunables    0    0    0 : slabdata   3233   3233      0
    iint_cache             0      0     72   56    1 : tunables    0    0    0 : slabdata      0      0      0
    buffer_head        21624  24297    104   39    1 : tunables    0    0    0 : slabdata    623    623      0
    nsproxy             4526   4526     56   73    1 : tunables    0    0    0 : slabdata     62     62      0
    vm_area_struct     20199  21320    200   40    2 : tunables    0    0    0 : slabdata    533    533      0
    mm_struct            624    624    832   39    8 : tunables    0    0    0 : slabdata     16     16      0
    files_cache          672    672    768   42    8 : tunables    0    0    0 : slabdata     16     16      0
    signal_cache        1170   1170   1088   30    8 : tunables    0    0    0 : slabdata     39     39      0
    sighand_cache        720    720   2112   15    8 : tunables    0    0    0 : slabdata     48     48      0
    task_struct         1135   1161   3328    9    8 : tunables    0    0    0 : slabdata    129    129      0
    cred_jar            3234   3234    192   42    2 : tunables    0    0    0 : slabdata     77     77      0
    anon_vma_chain     20532  24320     64   64    1 : tunables    0    0    0 : slabdata    380    380      0
    anon_vma           12999  14178     80   51    1 : tunables    0    0    0 : slabdata    278    278      0
    numa_policy          170    170     24  170    1 : tunables    0    0    0 : slabdata      1      1      0
    radix_tree_node     4872   4872    584   28    4 : tunables    0    0    0 : slabdata    174    174      0
    trace_event_file    1702   1702     88   46    1 : tunables    0    0    0 : slabdata     37     37      0
    ftrace_event_field   3910   3910     48   85    1 : tunables    0    0    0 : slabdata     46     46      0
    idr_layer_cache      705    705   2096   15    8 : tunables    0    0    0 : slabdata     47     47      0
    dma-kmalloc-8192       0      0   8192    4    8 : tunables    0    0    0 : slabdata      0      0      0
    dma-kmalloc-4096       0      0   4096    8    8 : tunables    0    0    0 : slabdata      0      0      0
    dma-kmalloc-2048       0      0   2048   16    8 : tunables    0    0    0 : slabdata      0      0      0
    dma-kmalloc-1024       0      0   1024   32    8 : tunables    0    0    0 : slabdata      0      0      0
    dma-kmalloc-512        0      0    512   32    4 : tunables    0    0    0 : slabdata      0      0      0
    dma-kmalloc-256        0      0    256   32    2 : tunables    0    0    0 : slabdata      0      0      0
    dma-kmalloc-128        0      0    128   32    1 : tunables    0    0    0 : slabdata      0      0      0
    kmalloc-8192         156    156   8192    4    8 : tunables    0    0    0 : slabdata     39     39      0
    kmalloc-4096         543    568   4096    8    8 : tunables    0    0    0 : slabdata     71     71      0
    kmalloc-2048        1168   1200   2048   16    8 : tunables    0    0    0 : slabdata     75     75      0
    kmalloc-1024        3744   3840   1024   32    8 : tunables    0    0    0 : slabdata    120    120      0
    kmalloc-512         2656   2656    512   32    4 : tunables    0    0    0 : slabdata     83     83      0
    kmalloc-256        13554  23488    256   32    2 : tunables    0    0    0 : slabdata    734    734      0
    kmalloc-128       7216432 7265664    128   32    1 : tunables    0    0    0 : slabdata 227052 227052      0
    kmem_cache_node      256    256    128   32    1 : tunables    0    0    0 : slabdata      8      8      0
    kmem_cache           256    256    256   32    2 : tunables    0    0    0 : slabdata      8      8      0
     Develop>cat /proc/buddyinfo 
    Node 0, zone      DMA    812    745    599    616    399    261    202    185    123      0      0 
    Node 0, zone   Normal   9347  10672   4696   6395   4327   2799   2243   2107   2166     63   1316 
     Develop>

    发现kmalloc-128 异常!

    2、使用kmemleak 看到如下可能的leak 点

    unreferenced object 0xffffffc883a81000 (size 128):
      comm "softirq", pid 0, jiffies 4295163332 (age 144041.356s)
      hex dump (first 32 bytes):
        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      backtrace:
        [<ffffffc0001f968c>] __save_stack_trace+0x38/0x48
        [<ffffffc0001f9d40>] create_object+0x13c/0x268
        [<ffffffc000868d54>] kmemleak_alloc+0x88/0xbc
        [<ffffffc0001e4cf0>] kmem_cache_alloc_trace+0x148/0x224
        [<ffffffc0003810ac>] lsm_sock_alloc+0x34/0x60
        [<ffffffc000384b18>] security_sk_alloc+0x34/0x88
        [<ffffffc00071155c>] sk_prot_alloc+0xbc/0x11c
        [<ffffffc00071452c>] sk_clone_lock+0x38/0x2dc
        [<ffffffc000793614>] inet_csk_clone_lock+0x30/0xdc
        [<ffffffc0007abef4>] tcp_create_openreq_child+0x38/0x370
        [<ffffffc0008256c4>] tcp_v6_syn_recv_sock+0x1c0/0x57c
        [<ffffffc0007ac9d8>] tcp_check_req+0x2d8/0x3c4
        [<ffffffc000826410>] tcp_v6_rcv+0x390/0xb3c
        [<ffffffc0007fefac>] ip6_input_finish+0x2c0/0x438
        [<ffffffc0007ff5fc>] ip6_input+0x44/0xa0
        [<ffffffc0007fecd4>] ip6_rcv_finish+0x94/0xac
    unreferenced object 0xffffffc878e1b0c0 (size 408):
      comm "softirq", pid 0, jiffies 4295163332 (age 144041.380s)
      hex dump (first 32 bytes):
        40 8b c3 7a c8 ff ff ff f3 14 c9 66 60 4d 50 00  @..z.......f`MP.
        0a 00 0c fe 00 00 00 00 60 68 62 7a c0 ff ff ff  ........`hbz....
      backtrace:
        [<ffffffc0001f968c>] __save_stack_trace+0x38/0x48
        [<ffffffc0001f9d40>] create_object+0x13c/0x268
        [<ffffffc000868d54>] kmemleak_alloc+0x88/0xbc
        [<ffffffc0001e4ac4>] kmem_cache_alloc+0x144/0x228
        [<ffffffc00079a2b8>] inet_reqsk_alloc+0x34/0xb0
        [<ffffffc00079afac>] tcp_conn_request+0x17c/0x8b4
        [<ffffffc0008250f4>] tcp_v6_conn_request+0x68/0x98
        [<ffffffc0007a0ca4>] tcp_rcv_state_process+0x88/0xac0
        [<ffffffc000825e64>] tcp_v6_do_rcv+0x204/0x420
        [<ffffffc000826684>] tcp_v6_rcv+0x604/0xb3c
        [<ffffffc0007fefac>] ip6_input_finish+0x2c0/0x438
        [<ffffffc0007ff5fc>] ip6_input+0x44/0xa0
        [<ffffffc0007fecd4>] ip6_rcv_finish+0x94/0xac
        [<ffffffc0007ff51c>] ipv6_rcv+0x3f8/0x494
        [<ffffffc000728e18>] __netif_receive_skb_core+0x6dc/0x95c
        [<ffffffc00072982c>] __netif_receive_skb+0x34/0x90

     使用 kprobe 统计  sk的refcnt 引用计数,最后发现是 在查找sk的时候  会inc refcnt 但是由没有设置 skb->sk=sk ;报文走正常协议栈时 会再次查找sk 导致 refcnt 引用计数增加了一次

    http代理服务器(3-4-7层代理)-网络事件库公共组件、内核kernel驱动 摄像头驱动 tcpip网络协议栈、netfilter、bridge 好像看过!!!! 但行好事 莫问前程 --身高体重180的胖子
  • 相关阅读:
    c#中的委托和事件
    C++STL中的vector
    java中的static
    java中public private protected区别
    java中抽象类与接口
    c++中的namespace
    北京“新城卓越”黑中介租房感受
    如何删除当前正在使用的SQLLite文件?
    SVN将一台服务器上的代码迁移到另一台服务器上
    使用PowerDesigner对NAME和COMMENT互相转换
  • 原文地址:https://www.cnblogs.com/codestack/p/14714114.html
Copyright © 2011-2022 走看看