zoukankan      html  css  js  c++  java
  • [Linux] Linux smaps接口文件结构

    在Linux内核 2.6.16中引入了一个系统内存接口特性,这个接口位于/proc/$pid/目录下的smaps文件中 ,一看内容发现是进程内存映像信息,比同一目录下的maps文件更详细些。

    400df000-4048c000 r--s 00000000 1f:05 286        /data/dalvik-cache/system@framework@core.jar@classes.dex
    Size:               3764 kB
    Rss:                1804 kB
    Pss:                1804 kB
    Shared_Clean:          0 kB
    Shared_Dirty:          0 kB
    Private_Clean:      1804 kB
    Private_Dirty:         0 kB
    Referenced:         1804 kB
    Anonymous:             0 kB
    Swap:                  0 kB
    KernelPageSize:        4 kB
    MMUPageSize:           4 kB

    以上述输出结果为例:400df000-4048c000 r--s 00000000 1f:05 286 /data/dalvik-cache/system@framework@core.jar@classes.dex

    • 400df000-4048c000 是该虚拟内存段的开始和结束位置
    • r--s内存段的权限,最后一位p代表私有,s代表共享
    • 00000000 该虚拟内存段在对应的映射文件中的偏移量
    • 1f:05 文件的主设备和次设备号
    • 286 被映射到虚拟内存的文件的索引节点号
    • /data/dalvik-cache/system@framework@core.jar@classes.dex 被映射到虚拟内存的文件名称。后面带(deleted)的是内存数据,可以被销毁。
    • size 是进程使用内存空间,并不一定实际分配了内存(VSS)
    • Rss是实际分配的内存(不需要缺页中断就可以使用的)
    • Pss是平摊计算后的使用内存(有些内存会和其他进程共享,例如mmap进来的)
    • Shared_Clean 和其他进程共享的未改写页面
    • Shared_Dirty 和其他进程共享的已改写页面
    • Private_Clean 未改写的私有页面页面
    • Private_Dirty 已改写的私有页面页面
    • Referenced 标记为访问和使用的内存大小
    • Anonymous 不来自于文件的内存大小
    • Swap 存在于交换分区的数据大小(如果物理内存有限,可能存在一部分在主存一部分在交换分区)
    • KernelPageSize 内核页大小 
    • MMUPageSize    MMU页大小,基本和Kernel页大小相同


    其中Dirty页面如果没有交换机制的情况下,应该是不能回收的。
    精确分析内存占用可以用Private内存信息来衡量。 

    详细解释见 http://www.kernel.org/doc/Documentation/filesystems/proc.txt

    The first of these lines shows the same information as is displayed for the
    mapping in /proc/PID/maps.  The remaining lines show the size of the mapping
    (size), the amount of the mapping that is currently resident in RAM (RSS), the
    process' proportional share of this mapping (PSS), the number of clean and
    dirty private pages in the mapping.  Note that even a page which is part of a
    MAP_SHARED mapping, but has only a single pte mapped, i.e.  is currently used
    by only one process, is accounted as private and not as shared.  "Referenced"
    indicates the amount of memory currently marked as referenced or accessed.
    "Anonymous" shows the amount of memory that does not belong to any file.  Even
    a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE
    and a page is modified, the file page is replaced by a private anonymous copy.
    "Swap" shows how much would-be-anonymous memory is also used, but out on
    swap.
  • 相关阅读:
    Centos7安装Python3
    mysql+centos7+主从复制
    Python开发之virtualenv和virtualenvwrapper详解
    Linux基础系统优化(二)
    Linux基础系统优化(一)
    Windows 10版本区别
    HTML5常用的语义化标签
    关于efk多服务器多日志合并收集
    离线状态安装docker容器
    Docker部署jenkins+sonar+gitlab代码检测系统
  • 原文地址:https://www.cnblogs.com/0616--ataozhijia/p/3999661.html
Copyright © 2011-2022 走看看