zoukankan      html  css  js  c++  java
  • free命令查看内存信息

    free介绍

    FREE(1)                       Linux User’s Manual                      FREE(1)
    
    NAME
           free - Display amount of free and used memory in the system
    
    SYNOPSIS
           free [-b | -k | -m] [-o] [-s delay ] [-t] [-l] [-V]
    
    DESCRIPTION
           free  displays  the total amount of free and used physical and swap memory in the system, 
           as well as the buffers used by the kernel.  
           The shared memory column should be ignored; it is obsolete.
    
       Options
           The -b switch displays the amount of memory in bytes; the -k switch (set by default) displays  it
           in kilobytes; the -m switch displays it in megabytes.
    
           The -t switch displays a line containing the totals.
    
           The  -o  switch disables the display of a "buffer adjusted" line.  If the -o option is not speci-
           fied, free subtracts buffer memory from the used memory and adds it to the free memory  reported.
    
           The  -s  switch  activates  continuous  polling delay seconds apart. You may actually specify any
           floating point number for delay, usleep(3) is used for microsecond resolution delay times.
    
           The -l switch shows detailed low and high memory statistics.
    
           The -V switch displays version information.
    
    FILES
           /proc/meminfo-- memory information
    
    SEE ALSO
           ps(1), slabtop(1), vmstat(8), top(1)
    
    AUTHORS
           Written by Brian Edmonds.
    
           Send bug reports to <albert@users.sf.net>
    
    Cohesive Systems                 20 Mar 1993                           FREE(1)

    free示例

    root@71standby[12:20:25]$ free && echo '' && cat /proc/meminfo
                 total       used       free     shared    buffers     cached
    Mem:      32880252    7804824   25075428       2836     397504    5559752
    -/+ buffers/cache:    1847568   31032684
    Swap:      2064380          0    2064380
    
    MemTotal:       32880252 kB
    MemFree:        25075428 kB
    Buffers:          397504 kB
    Cached:          5559752 kB
    SwapCached:            0 kB
    Active:          2778440 kB
    Inactive:        4535288 kB
    Active(anon):    1356660 kB
    Inactive(anon):     2640 kB
    Active(file):    1421780 kB
    Inactive(file):  4532648 kB
    Unevictable:           0 kB
    Mlocked:               0 kB
    SwapTotal:       2064380 kB
    SwapFree:        2064380 kB
    Dirty:               160 kB
    Writeback:             0 kB
    AnonPages:       1356472 kB
    Mapped:            32648 kB
    Shmem:              2836 kB
    Slab:             259528 kB
    SReclaimable:     221788 kB
    SUnreclaim:        37740 kB
    KernelStack:        5776 kB
    PageTables:        18332 kB
    NFS_Unstable:          0 kB
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:    18504504 kB
    Committed_AS:    3346884 kB
    VmallocTotal:   34359738367 kB
    VmallocUsed:       66544 kB
    VmallocChunk:   34359658428 kB
    HardwareCorrupted:     0 kB
    AnonHugePages:    806912 kB
    HugePages_Total:       0
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB
    DirectMap4k:        6012 kB
    DirectMap2M:     2091008 kB
    DirectMap1G:    31457280 kB
    root@71standby[12:20:30]$ 

    字段解释

    >>> # free 默认单位是KB
    >>> 
    >>> 32880252-7804824             # 总内存 - 已使用内存 == 剩余可用内存
    25075428
    >>> 
    >>> 7804824-397504-5559752       # 已使用内存分为三部分:应用程序占用的内存 + buffers + cached
    1847568                          # 所以当前服务器上应用程序一共占用了 1847568KB内存
    >>> 
    >>> 25075428+397504+5559752      # 全部可用内存 = 剩余可用内存 + buffers + cached
    31032684                         # 所以当前服务器上可以实际使用的内存为 31032684KB
    >>>

    buffers和cached是干啥用的?

    cached是cpu与内存间的,buffer是内存与磁盘间的,都是为了解决速度不对等的问题。

    buffer是即将要被写入磁盘的,而cache是被从磁盘中读出来的。

        - 缓存(cached)是把读取过的数据保存起来,重新读取时若命中(找到需要的数据)就不要去读硬盘了,若没有命中就读硬盘。

          其中的数据会根据读取频率进行组织,把最频繁读取的内容放在最容易找到的位置,把不再读的内容不断往后排,直至从中删除。

        - 缓冲(buffers)是根据磁盘的读写设计的,把分散的写操作集中进行,减少磁盘碎片和硬盘的反复寻道,从而提高系统性能。

          linux有一个守护进程定期 清空缓冲内容(即写入磁盘),也可以通过sync命令手动清空缓冲。

         举个例子吧:我这里有一个ext2的U盘,我往里面cp一个3M的MP3,但U盘的灯 没有跳动,过了一会儿(或者手动输入sync)U盘的灯就跳动起来了。

                              卸载设备时会清空缓冲,所以有些时候卸载一个设备时要等上几秒钟

        - swappiness  修改/etc/sysctl.conf中的vm.swappiness右边的数字可以在下次开机时调节swap使用策略。

          该数字范围是0~100,数字越大越倾向于使用swap。默认为60,可以改一下试试。–两者都是RAM中的数据。

     

    转自https://www.cnblogs.com/chenpingzhao/p/5161844.html

  • 相关阅读:
    mac xcode c++ cin cout注意细节一
    linux c++编译问题和虚拟机网络通信
    cocos2d之列表容器节点再排序
    cocos2d之z轴位置示例
    cocos2d之json使用实例
    绑定方法与非绑定方法
    Python 多态与抽象类
    面向对象
    面向对象之继承与派生
    面向对象之类与对象
  • 原文地址:https://www.cnblogs.com/standby/p/9349662.html
Copyright © 2011-2022 走看看