linux内存相关proc文件解析

来源:互联网 发布:winrar数据解压缩软件 编辑:程序博客网 时间:2024/06/06 05:58
linux中内存管理相关的proc文件有meminfo,buddyinfo,pagetypeinfo,slabinfo,vmallocinfo;
下面分别介绍下buddyinfo,pagetypeinfo,slabinfo;


/proc/buddyinfo


linux kernel伙伴系统是以order为单位管理内存分组;Kernel会以Order 0,1,2,3,4,5,6,7,8,9,10,也就是从Order 0 一个Page 4096kbytes大小,到Order10提供约4MB大小的Memory配置,根据每种不同大小的连续内存的使用状况,可把被释放的内存组合为更高一阶的Memory Page Oder,或是把连续的内存根据需求拆解为所需的Page Order大小的内存区块,而这些当下Buddy System对内存的使用情况,就是BuddyInfo所可以提供的内存使用信息,当所要配置的记忆体Page Order正好落在目前Buddy System所无法供应的连续内存区块时,就可能会导致内存申请失败. (内存申请失败会通过Low Memory Killer 或OOM 来强制应用程序的删除执行,配置出足够大小的连续物理内存空间).


/proc/buddyinfo这个文件就是显示当前系统不同zone区按order 0~10 依次剩余的空闲内存大小


root:/ # cat /proc/buddyinfo
Node 0, zone      DMA   1792    474    341    141     28     18      2      3     20     36    275
Node 0, zone   Normal   1203    456    251    183     19     10      1      5     13     29    283


DMA zone 区有1792个2^0 个page,474个2^1个page....


在系统运行过程中,按照伙伴算法原理,不同order 空闲内存会进行变化,
下面是系统运行一段时间前后的两次buddyinfo信息:


root:/ # cat /proc/buddyinfo
Node 0, zone      DMA    158     46      8      4      2      0      1     14     35     30    333
Node 0, zone   Normal    170     86     30     17      2      1      1      9     37     31    319


root:/ # cat /proc/buddyinfo
Node 0, zone      DMA      1      2     46     64     13      7      3      5     36     29    333
Node 0, zone   Normal      1      1     77     72     13      2      1      0     36     31    319


具体涉及到的代码:


struct zone {


/* free areas of different sizes */
struct free_area free_area[MAX_ORDER];
}


struct free_area {
struct list_head free_list[MIGRATE_TYPES];
unsigned long nr_free;
};
/* Free memory management - zoned buddy allocator.  */
#ifndef CONFIG_FORCE_MAX_ZONEORDER
#define MAX_ORDER 11
#else
#define MAX_ORDER CONFIG_FORCE_MAX_ZONEORDER
#endif


enum {
MIGRATE_UNMOVABLE,
MIGRATE_RECLAIMABLE,
MIGRATE_MOVABLE,
#ifdef CONFIG_CMA
MIGRATE_CMA,
#endif
MIGRATE_PCPTYPES, /* the number of types on the pcp lists */
MIGRATE_RESERVE = MIGRATE_PCPTYPES,
#ifdef CONFIG_MEMORY_ISOLATION
MIGRATE_ISOLATE,/* can't allocate from here */
#endif
MIGRATE_TYPES
};


注意在每个order空闲内存list中,又按照不同的MIGRATE_TYPES进行进一步细分,这样主要便于系统

内存回收,合并为大的order;




/proc/pagetypeinfo
这个文件是将buddyinfo的内容进一步细分:
Free pages count per migrate type at order -- 不同order 按照migrate type的空闲page数量
Number of blocks -- 连续内存块数量


|root:/ # cat /proc/pagetypeinfo
Page block order: 10
Pages per block:  1024


Free pages count per migrate type at order       0      1      2      3      4      5      6      7      8      9     10
Node    0, zone      DMA, type    Unmovable    248     78    126     95      5      4      1      1     18     32     59
Node    0, zone      DMA, type  Reclaimable      0      1      3      3      1      1      0      0      1      1      0
Node    0, zone      DMA, type      Movable    696    385    201     44     22     13      1      2      1      3    214
Node    0, zone      DMA, type          CMA      0      0      0      0      0      0      0      0      0      0      0
Node    0, zone      DMA, type      Reserve      0      0      0      0      0      0      0      0      0      0      2
Node    0, zone      DMA, type      Isolate      0      0      0      0      0      0      0      0      0      0      0
Node    0, zone   Normal, type    Unmovable      1     71    125    131      7      5      0      1     10     28     60
Node    0, zone   Normal, type  Reclaimable      0      0      0      0      1      1      0      1      1      0      0
Node    0, zone   Normal, type      Movable    128    383    121     52     11      5      0      3      2      1    221
Node    0, zone   Normal, type          CMA      0      0      0      0      0      0      0      0      0      0      0
Node    0, zone   Normal, type      Reserve      0      0      0      0      0      0      0      0      0      0      2
Node    0, zone   Normal, type      Isolate      0      0      0      0      0      0      0      0      0      0      0


Number of blocks type     Unmovable  Reclaimable      Movable          CMA      Reserve      Isolate
Node 0, zone      DMA          142            8          531           36            2            0
Node 0, zone   Normal          139           10          608            0            2            0


Number of mixed blocks    Unmovable  Reclaimable      Movable          CMA      Reserve      Isolate
Node 0, zone      DMA            0            0            0           36            0            0
Node 0, zone   Normal            0            0            0            0            0            0



/proc/slabinfo
对应kernel中频繁使用的数据结构,为了减少内存碎片,同时提升效率,使用slab/slub进行内存管理;


slabinfo - version: 2.1
# name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
kmem_cache_node      113    192    128   32    1 : tunables    0    0    0 : slabdata      6      6      0
kmem_cache            97    128    256   16    1 : tunables    0    0    0 : slabdata      8      8      0
task_struct         1759   1980   3328    9    8 : tunables    0    0    0 : slabdata    220    220      0
ext4_groupinfo_4k   1091   1152    168   24    1 : tunables    0    0    0 : slabdata     48     48      0
ip6-frags              0      0    240   17    1 : tunables    0    0    0 : slabdata      0      0      0
RAWv6                100    100   1280   25    8 : tunables    0    0    0 : slabdata      4      4      0
UDPLITEv6              0      0   1280   25    8 : tunables    0    0    0 : slabdata      0      0      0
UDPv6                100    100   1280   25    8 : tunables    0    0    0 : slabdata      4      4      0
tw_sock_TCPv6          0      0    384   21    2 : tunables    0    0    0 : slabdata      0      0      0
TCPv6                 56     56   2304   14    8 : tunables    0    0    0 : slabdata      4      4      0
nf_conntrack_ffffffc001689980     76     76    416   19    2 : tunables    0    0    0 : slabdata      4      4      0
ashmem_area_cache    100    100    320   25    2 : tunables    0    0    0 : slabdata      4      4      0
kcopyd_job             0      0   3600    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_io_cq            504    504    112   36    1 : tunables    0    0    0 : slabdata     14     14      0
cfq_queue            442    442    232   17    1 : tunables    0    0    0 : slabdata     26     26      0
bsg_cmd                0      0    312   26    2 : tunables    0    0    0 : slabdata      0      0      0
fuse_request          72     72    440   18    2 : tunables    0    0    0 : slabdata      4      4      0
fuse_inode          2322   2322    896   18    4 : tunables    0    0    0 : slabdata    129    129      0
ecryptfs_inode_cache      0      0   1408   23    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
exfat_inode_cache      0      0    920   17    4 : tunables    0    0    0 : slabdata      0      0      0
fat_inode_cache       29     54    864   18    4 : tunables    0    0    0 : slabdata      3      3      0
fat_cache             18    204     40  102    1 : tunables    0    0    0 : slabdata      2      2      0
jbd2_transaction_s     64     80    256   16    1 : tunables    0    0    0 : slabdata      5      5      0
jbd2_journal_handle    340    340     48   85    1 : tunables    0    0    0 : slabdata      4      4      0
journal_handle         0      0     24  170    1 : tunables    0    0    0 : slabdata      0      0      0
journal_head         148    216    112   36    1 : tunables    0    0    0 : slabdata      6      6      0
revoke_table         266   1024     16  256    1 : tunables    0    0    0 : slabdata      4      4      0
revoke_record        384    512     32  128    1 : tunables    0    0    0 : slabdata      4      4      0
ext4_inode_cache   11881  11908   1240   26    8 : tunables    0    0    0 : slabdata    458    458      0
ext4_free_data       256    320     64   64    1 : tunables    0    0    0 : slabdata      5      5      0
ext4_allocation_context    128    128    128   32    1 : tunables    0    0    0 : slabdata      4      4      0
ext4_prealloc_space    136    136    120   34    1 : tunables    0    0    0 : slabdata      4      4      0
ext4_io_end          560    560     72   56    1 : tunables    0    0    0 : slabdata     10     10      0
ext4_extent_status   8976   8976     40  102    1 : tunables    0    0    0 : slabdata     88     88      0
ext2_inode_cache       0      0    968   16    4 : tunables    0    0    0 : slabdata      0      0      0
ext3_inode_cache       0      0    976   16    4 : tunables    0    0    0 : slabdata      0      0      0
dnotify_mark         100    120    136   30    1 : tunables    0    0    0 : slabdata      4      4      0
dio                    0      0    640   25    4 : tunables    0    0    0 : slabdata      0      0      0
posix_timers_cache    124    124    264   31    2 : tunables    0    0    0 : slabdata      4      4      0
ip4-frags              0      0    216   18    1 : tunables    0    0    0 : slabdata      0      0      0
UDP-Lite               0      0   1152   28    8 : tunables    0    0    0 : slabdata      0      0      0
flow_cache             0      0    104   39    1 : tunables    0    0    0 : slabdata      0      0      0
UDP                  112    112   1152   28    8 : tunables    0    0    0 : slabdata      4      4      0
tw_sock_TCP            0      0    384   21    2 : tunables    0    0    0 : slabdata      0      0      0
TCP                   32     32   2048   16    8 : tunables    0    0    0 : slabdata      2      2      0
IPA RX PKT WRAPPER   4030   4080     80   51    1 : tunables    0    0    0 : slabdata     80     80      0
IPA HDR               32     72    168   24    1 : tunables    0    0    0 : slabdata      3      3      0
IPA FLT                2     20    392   20    2 : tunables    0    0    0 : slabdata      1      1      0
blkdev_queue          34     45   2160   15    8 : tunables    0    0    0 : slabdata      3      3      0
blkdev_requests      506    506    344   23    2 : tunables    0    0    0 : slabdata     22     22      0
sock_inode_cache     903    903    768   21    4 : tunables    0    0    0 : slabdata     43     43      0
file_lock_cache      171    171    208   19    1 : tunables    0    0    0 : slabdata      9      9      0
net_namespace          0      0   5248    6    8 : tunables    0    0    0 : slabdata      0      0      0
ftrace_event_file    967   1012     88   46    1 : tunables    0    0    0 : slabdata     22     22      0
proc_inode_cache    8341   8967    752   21    4 : tunables    0    0    0 : slabdata    427    427      0
sigqueue             100    100    160   25    1 : tunables    0    0    0 : slabdata      4      4      0
bdev_cache            37     64   1024   16    4 : tunables    0    0    0 : slabdata      4      4      0
shmem_inode_cache   2463   2880    800   20    4 : tunables    0    0    0 : slabdata    144    144      0
filp                9328  10941    384   21    2 : tunables    0    0    0 : slabdata    521    521      0
inode_cache        24950  25070    688   23    4 : tunables    0    0    0 : slabdata   1090   1090      0
dentry             55228  56754    216   18    1 : tunables    0    0    0 : slabdata   3153   3153      0
avc_operation_perm    512    512     32  128    1 : tunables    0    0    0 : slabdata      4      4      0
avc_operation_node    292    292     56   73    1 : tunables    0    0    0 : slabdata      4      4      0
avc_node            1914   2072     72   56    1 : tunables    0    0    0 : slabdata     37     37      0
selinux_inode_security 104534 106114    120   34    1 : tunables    0    0    0 : slabdata   3121   3121      0
buffer_head        16029  16029    104   39    1 : tunables    0    0    0 : slabdata    411    411      0
nsproxy             4080   4080     48   85    1 : tunables    0    0    0 : slabdata     48     48      0
vm_area_struct     61882  65274    176   23    1 : tunables    0    0    0 : slabdata   2838   2838      0
mm_struct            378    378    896   18    4 : tunables    0    0    0 : slabdata     21     21      0
files_cache          165    168    768   21    4 : tunables    0    0    0 : slabdata      8      8      0
signal_cache        1070   1176   1152   28    8 : tunables    0    0    0 : slabdata     42     42      0
sighand_cache        523    555   2176   15    8 : tunables    0    0    0 : slabdata     37     37      0
task_struct         1759   1980   3328    9    8 : tunables    0    0    0 : slabdata    220    220      0
anon_vma_chain     53046  58368     64   64    1 : tunables    0    0    0 : slabdata    912    912      0
anon_vma           28440  30966    104   39    1 : tunables    0    0    0 : slabdata    794    794      0
debug_objects_cache  31176  33150     40  102    1 : tunables    0    0    0 : slabdata    325    325      0
radix_tree_node    11974  11984    584   28    4 : tunables    0    0    0 : slabdata    428    428      0
idr_layer_cache      435    435   2096   15    8 : tunables    0    0    0 : slabdata     29     29      0
page->ptl          22350  22780     24  170    1 : tunables    0    0    0 : slabdata    134    134      0
dma-kmalloc-8192    2016   2016   8192    4    8 : tunables    0    0    0 : slabdata    504    504      0
dma-kmalloc-4096      40     40   4096    8    8 : tunables    0    0    0 : slabdata      5      5      0
dma-kmalloc-2048     275    304   2048   16    8 : tunables    0    0    0 : slabdata     19     19      0
dma-kmalloc-1024     176    176   1024   16    4 : tunables    0    0    0 : slabdata     11     11      0
dma-kmalloc-512      320    320    512   16    2 : tunables    0    0    0 : slabdata     20     20      0
dma-kmalloc-256        0      0    256   16    1 : 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         149    160   8192    4    8 : tunables    0    0    0 : slabdata     40     40      0
kmalloc-4096        1350   1352   4096    8    8 : tunables    0    0    0 : slabdata    169    169      0
kmalloc-2048        1026   1088   2048   16    8 : tunables    0    0    0 : slabdata     68     68      0
kmalloc-1024        2416   2464   1024   16    4 : tunables    0    0    0 : slabdata    154    154      0
kmalloc-512         4256   4736    512   16    2 : tunables    0    0    0 : slabdata    296    296      0
kmalloc-256        17810  18208    256   16    1 : tunables    0    0    0 : slabdata   1138   1138      0
kmalloc-128        82674  88160    128   32    1 : tunables    0    0    0 : slabdata   2755   2755      0
kmem_cache_node      113    192    128   32    1 : tunables    0    0    0 : slabdata      6      6      0
kmem_cache            97    128    256   16    1 : tunables    0    0    0 : slabdata      8      8      0


/proc/sys/vm目录下还有部分内存管理相关的文件节点,后面的文章再介绍;


0 0
原创粉丝点击