zoukankan      html  css  js  c++  java
  • linux内存学习

    1.vmstat

    procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
     r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
     1  0 750568 298464 232836 1440800    1    1     4     5    5   18  4  7 87  1

    vmstat -a
    procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
     r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa
     3  0 748720 261968 1347780 1250832    1    1     4     5    6   19  4  7 87  1

    procs:

    r:The number of processes waiting for run time.

    b:The number of processes in uninterruptible sleep.

    Memory:

    swpd:the amount of swapped memory used. =/proc/meminfo中的Swaptotal -Swapfree.

    free:the amount of idle memory.=/proc/meminfo中的Memfree

    buffer:the amount of memory used as buffers.

    cache:the amount of memory used as cache.

    inact:the amount of  inactive memory.

    active:the amount of active memory.

    swap:

    si: Amount of memory swapped in from disk (/s).单位为KB

    so:Amount of memory swapped to disk (/s).

    IO:

    bi:Blocks received from a block device (blocks/s).

    bo:Blocks sent to a block device (blocks/s).

    system:

    in: The number of interrupts per second, including the clock.

    cs: The number of context switches per second.

    CPU:

    us:Time spent running non-kernel code.(user time , including the clock)

    sy:Time spent running kernel code.(system time)

    id:Time spent idle.Prior to Linux 2.5.41, this includes IO-wait time.

    wa:Time spent waiting for IO.Prior to Linux 2.5.41, included in idle.

    st:Time stolen from a virtual machine.Prior to Linux 2.6.11, unkown.

    2.free

     free
                 total       used       free     shared    buffers     cached
    Mem:       4081868    3833076     248792          0     200816    1575716
    -/+ buffers/cache:    2056544    2025324
    Swap:      4094972     740156    3354816

    total:总计物理内存的大小

    used:已使用多大.

    free:可用有多少.

    shared:多个进程共享内存总额.

    Buffers/cached:磁盘缓存的大小.

    这里着重讲一下mem的used/free与-/+ buffers/cache的used/free的区别.它们的区别主要是从观察的角度来看:

    mem是从OS的角度,对于OS,buffers/cached都属于被使用,所以可用内存是248792KB,已用内存是3833076  KB,其中包括内核使用+Application(X,postgres,etc) 使用的+buffers+cached;

    -/+ buffers/cache是从应用程序的角度:可用内存=系统free memory+buffers+cached.上例中free2025324=248792+200816+1575716

    所以机器的物理内存free的值很小,这是因为,在linux中有这么一种思想,内存不用白不用,因此它尽可能的cache和buffer一些数据,以方便下次使用.但实际这些内存也可以直接拿来使用的.

    3./proc/下的东东

    (1)/proc/meminfo

    MemTotal:        4081868 kB ---total usable physical ram
    MemFree:          191436 kB ---sum of LowFree and High Free of physical ram.
    Buffers:          300408 kB---The amount of physical RAM used for file buffers
    Cached:          1522444 kB---The amount of physical RAM used as cache memory
    SwapCached:       170456 kB---The amount of swap used as cache memory.The swap cache is similar in concept to the page cache.
    Active:          1317960 kB---total amount of buffer or page cache memory that is in active use.
    Inactive:        1354336 kB---total amount of buffer or page cache memory that are free and available.
    Active(anon):     409912 kB
    Inactive(anon):   441508 kB
    Active(file):     908048 kB
    Inactive(file):   912828 kB
    Unevictable:          16 kB
    Mlocked:              16 kB
    HighTotal:       3237336 kB---total and free amount of memory that is not directly mapped into kernel space
    HighFree:          94236 kB
    LowTotal:         844532 kB---total and free amount of memory that is directly mapped into kernel space
    LowFree:           97200 kB
    SwapTotal:       4094972 kB---total amount of swap available.
    SwapFree:        3352716 kB---total amount of swap free.
    Dirty:              3856 kB---total amount of memory, waiting to be written back to the disk.
    Writeback:             0 kB---total amount of memory actively being written back to the disk.
    AnonPages:        775216 kB
    Mapped:          1128872 kB---The total amount of memory, which have been used to map devices, files, or libraries using the mmap command.All "Mapped:" memory is "Cached", but not all "Cached:" memory is "Mapped:". The first time the mmap area is acessed, the page will be brought in from the disk and mapped into memory.
    Shmem:              1976 kB
    Slab:             134180 kB---total amount of memory used by the kernel to cache data structures for its own use.
    SReclaimable:     108112 kB---the recliamable memory of slab.
    SUnreclaim:        26068 kB
    KernelStack:        4552 kB
    PageTables:        15876 kB---the total amount of memory dedicated to the lowest page table level.管理内存分页页面的索引表的大小.
    NFS_Unstable:          0 kB---不稳定页表的大小.
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:     6135904 kB---based on the overcommit ratio('vm.overcommit_ratio'),this is the total amount of memory currently available to be allocated on the system.This limit is only adhered to if strict overcommit acounting is enabled(mode 2 in 'vm.overcommit_memory').The Commit limit is calculated with the following formula:CommitLimit=('vm.overcommit_ratio'*Physical RAM)+Swap.
    Committed_AS:    5440204 kB---the total amount of memory estimated to complete the workload.This value represents the worst case scennario value, and also includes swap memory.
    VmallocTotal:     122880 kB---the total amount of memory of total allocated virtual address space.
    VmallocUsed:       86444 kB---the total amount of memory of used virtual address space.
    VmallocChunk:      17432 kB---the largetst contiguous block of memory of avalible virtual address space.
    HardwareCorrupted:     0 kB
    AnonHugePages:         0 kB
    HugePages_Total:       0---the total number of hugepages for the system.
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB---the size for each hugepages .4096KB on uniprocessor kernels for 32 bit architectures.For SMP, hugemem kenels, and AMD64, the default is 2048 KB.
    DirectMap4k:      206840 kB
    DirectMap2M:      706560 kB

    (2)/proc/pid/maps 进程所占用的虚拟地址

    cat  /proc/1164/maps
    08048000-08375000 r-xp 00000000 fd:01 873683     /usr/local/pgsql/bin/postgres
    08375000-0837e000 rw-p 0032c000 fd:01 873683     /usr/local/pgsql/bin/postgres
    0837e000-083e7000 rw-p 0837e000 00:00 0          [heap]
    5dd2a000-7769c000 rw-s 00000000 00:08 16089088   /SYSV0052e2c1 (deleted)
    7769c000-776a4000 r-xp 00000000 fd:00 36924      /lib/libnss_files.so.2
    776a4000-776a6000 rw-p 00007000 fd:00 36924      /lib/libnss_files.so.2
    776a6000-776b7000 r-xp 00000000 fd:00 36916      /lib/libnsl.so.1
    776b7000-776b9000 rw-p 00010000 fd:00 36916      /lib/libnsl.so.1
    776b9000-776bb000 rw-p 776b9000 00:00 0
    776bb000-776c1000 r-xp 00000000 fd:00 36888      /lib/libnss_compat.so.2
    776c1000-776c3000 rw-p 00006000 fd:00 36888      /lib/libnss_compat.so.2
    776c3000-776c4000 rw-p 776c3000 00:00 0
    776c4000-777d2000 r-xp 00000000 fd:00 36920      /lib/libc.so.6
    777d2000-777d3000 r--p 0010e000 fd:00 36920      /lib/libc.so.6
    777d3000-777d6000 rw-p 0010f000 fd:00 36920      /lib/libc.so.6
    777d6000-777d8000 rw-p 777d6000 00:00 0
    777d8000-777f8000 r-xp 00000000 fd:00 36903      /lib/libm.so.6
    777f8000-777fa000 rw-p 00020000 fd:00 36903      /lib/libm.so.6
    777fa000-777fc000 r-xp 00000000 fd:00 36904      /lib/libdl.so.2
    777fc000-777fe000 rw-p 00001000 fd:00 36904      /lib/libdl.so.2
    777fe000-77802000 r-xp 00000000 fd:00 36885      /lib/libcrypt.so.1
    77802000-77804000 rw-p 00004000 fd:00 36885      /lib/libcrypt.so.1
    77804000-7782c000 rw-p 77804000 00:00 0
    7782e000-77843000 r-xp 00000000 fd:00 36894      /lib/ld-linux.so.2
    77843000-77844000 r--p 00014000 fd:00 36894      /lib/ld-linux.so.2
    77844000-77845000 rw-p 00015000 fd:00 36894      /lib/ld-linux.so.2
    7f896000-7f8ab000 rw-p 7ffeb000 00:00 0          [stack]
    ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]

    (3)/proc/pid/statm 进程所占用的虚拟内存

    cat  /proc/1164/statm
    106189 3902 3824 813 0 171 0

    man 5 proc,搜statm,provides infomation about memory usage, measured in pages.

    size       total program size(same as VmSize in /proc/[pid]/status)

    used     resident set size(same as VmRSS in /proc/[pid]/status)常驻内存空间页大小

    shared   shared pages(from shared mappings)

    text      text(code)    (same as exe in /proc/[pid]/status)

    lib     library(unused in Linux 2.6q)(same as vmLib in /proc/[pid]/status)

    data    data+stack(same as vmData+vmStack in /proc/[pid]/status)

    dt     dirty pages(unused in Linux 2.6)

    (4)/proc/pid/status

     cat /proc/1164/status
    Name:    postgres
    State:    S (sleeping)
    Tgid:    1164
    Pid:    1164
    PPid:    1
    TracerPid:    0
    Uid:    70    70    70    70
    Gid:    70    70    70    70
    FDSize:    1024
    Groups:    70
    VmPeak:      424760 kB
    VmSize:      424756 kB
    VmLck:           0 kB
    VmHWM:       17056 kB
    VmRSS:       15608 kB
    VmData:         600 kB
    VmStk:          84 kB
    VmExe:        3252 kB
    VmLib:        1440 kB
    VmPTE:          60 kB
    Threads:    1
    SigQ:    0/69632
    SigPnd:    0000000000000000
    ShdPnd:    0000000000000000
    SigBlk:    0000000000000000
    SigIgn:    0000000001303000
    SigCgt:    0000000000014a07
    CapInh:    00000000fffffeff
    CapPrm:    0000000000000000
    CapEff:    0000000000000000
    CapBnd:    ffffffffffffffff
    voluntary_ctxt_switches:    8726984
    nonvoluntary_ctxt_switches:    1159326

  • 相关阅读:
    mybatis3这个问题我晕为什么对于配置信息的节点放的位置也会报错
    QTP的那些事增删改查中的增加操作的测试用例及其脚本设计思路
    QTP的那些事importsheet注意的一些事情
    mybatis3中的结果集
    QTP的那些事终极项目脚本设计思路及其测试查询功能的一些实际项目体会
    mybatis+spring整合的几个好的例子
    QTP的那些事操作excel数据需要注意的事
    hibernate4的使用第一步环境搭建
    项目中关于IFRAME引发的问题【出现率很高】
    oracle直接sql语句后台递归查询返回一个树
  • 原文地址:https://www.cnblogs.com/wataciii/p/2752830.html
Copyright © 2011-2022 走看看