1. pagemap, from the userspace perspective
  2. ---------------------------------------
  3.  
  4. pagemap is a new (as of 2.6.25) set of interfaces in the kernel that allow
  5. userspace programs to examine the page tables and related information by
  6. reading files in /proc.
  7.  
  8. There are three components to pagemap:
  9.  
  10. * /proc/pid/pagemap. This file lets a userspace process find out which
  11. physical frame each virtual page is mapped to. It contains one 64-bit
  12. value for each virtual page, containing the following data (from
  13. fs/proc/task_mmu.c, above pagemap_read):
  14.  
  15. * Bits 0-54 page frame number (PFN) if present
  16. * Bits 0-4 swap type if swapped
  17. * Bits 5-54 swap offset if swapped
  18. * Bit 55 pte is soft-dirty (see Documentation/vm/soft-dirty.txt)
  19. * Bits 56-60 zero
  20. * Bit 61 page is file-page or shared-anon
  21. * Bit 62 page swapped
  22. * Bit 63 page present
  23.  
  24. If the page is not present but in swap, then the PFN contains an
  25. encoding of the swap file number and the page's offset into the
  26. swap. Unmapped pages return a null PFN. This allows determining
  27. precisely which pages are mapped (or in swap) and comparing mapped
  28. pages between processes.
  29.  
  30. Efficient users of this interface will use /proc/pid/maps to
  31. determine which areas of memory are actually mapped and llseek to
  32. skip over unmapped regions.
  33.  
  34. * /proc/kpagecount. This file contains a 64-bit count of the number of
  35. times each page is mapped, indexed by PFN.
  36.  
  37. * /proc/kpageflags. This file contains a 64-bit set of flags for each
  38. page, indexed by PFN.
  39.  
  40. The flags are (from fs/proc/page.c, above kpageflags_read):
  41.  
  42. 0. LOCKED
  43. 1. ERROR
  44. 2. REFERENCED
  45. 3. UPTODATE
  46. 4. DIRTY
  47. 5. LRU
  48. 6. ACTIVE
  49. 7. SLAB
  50. 8. WRITEBACK
  51. 9. RECLAIM
  52. 10. BUDDY
  53. 11. MMAP
  54. 12. ANON
  55. 13. SWAPCACHE
  56. 14. SWAPBACKED
  57. 15. COMPOUND_HEAD
  58. 16. COMPOUND_TAIL
  59. 16. HUGE
  60. 18. UNEVICTABLE
  61. 19. HWPOISON
  62. 20. NOPAGE
  63. 21. KSM
  64. 22. THP
  65.  
  66. Short descriptions to the page flags:
  67.  
  68. 0. LOCKED
  69. page is being locked for exclusive access, eg. by undergoing read/write IO
  70.  
  71. 7. SLAB
  72. page is managed by the SLAB/SLOB/SLUB/SLQB kernel memory allocator
  73. When compound page is used, SLUB/SLQB will only set this flag on the head
  74. page; SLOB will not flag it at all.
  75.  
  76. 10. BUDDY
  77. a free memory block managed by the buddy system allocator
  78. The buddy system organizes free memory in blocks of various orders.
  79. An order N block has 2^N physically contiguous pages, with the BUDDY flag
  80. set for and _only_ for the first page.
  81.  
  82. 15. COMPOUND_HEAD
  83. 16. COMPOUND_TAIL
  84. A compound page with order N consists of 2^N physically contiguous pages.
  85. A compound page with order 2 takes the form of "HTTT", where H donates its
  86. head page and T donates its tail page(s). The major consumers of compound
  87. pages are hugeTLB pages (Documentation/vm/hugetlbpage.txt), the SLUB etc.
  88. memory allocators and various device drivers. However in this interface,
  89. only huge/giga pages are made visible to end users.
  90. 17. HUGE
  91. this is an integral part of a HugeTLB page
  92.  
  93. 19. HWPOISON
  94. hardware detected memory corruption on this page: don't touch the data!
  95.  
  96. 20. NOPAGE
  97. no page frame exists at the requested address
  98.  
  99. 21. KSM
  100. identical memory pages dynamically shared between one or more processes
  101.  
  102. 22. THP
  103. contiguous pages which construct transparent hugepages
  104.  
  105. [IO related page flags]
  106. 1. ERROR IO error occurred
  107. 3. UPTODATE page has up-to-date data
  108. ie. for file backed page: (in-memory data revision >= on-disk one)
  109. 4. DIRTY page has been written to, hence contains new data
  110. ie. for file backed page: (in-memory data revision > on-disk one)
  111. 8. WRITEBACK page is being synced to disk
  112.  
  113. [LRU related page flags]
  114. 5. LRU page is in one of the LRU lists
  115. 6. ACTIVE page is in the active LRU list
  116. 18. UNEVICTABLE page is in the unevictable (non-)LRU list
  117. It is somehow pinned and not a candidate for LRU page reclaims,
  118. eg. ramfs pages, shmctl(SHM_LOCK) and mlock() memory segments
  119. 2. REFERENCED page has been referenced since last LRU list enqueue/requeue
  120. 9. RECLAIM page will be reclaimed soon after its pageout IO completed
  121. 11. MMAP a memory mapped page
  122. 12. ANON a memory mapped page that is not part of a file
  123. 13. SWAPCACHE page is mapped to swap space, ie. has an associated swap entry
  124. 14. SWAPBACKED page is backed by swap/RAM
  125.  
  126. The page-types tool in this directory can be used to query the above flags.
  127.  
  128. Using pagemap to do something useful:
  129.  
  130. The general procedure for using pagemap to find out about a process' memory
  131. usage goes like this:
  132.  
  133. 1. Read /proc/pid/maps to determine which parts of the memory space are
  134. mapped to what.
  135. 2. Select the maps you are interested in -- all of them, or a particular
  136. library, or the stack or the heap, etc.
  137. 3. Open /proc/pid/pagemap and seek to the pages you would like to examine.
  138. 4. Read a u64 for each page from pagemap.
  139. 5. Open /proc/kpagecount and/or /proc/kpageflags. For each PFN you just
  140. read, seek to that entry in the file, and read the data you want.
  141.  
  142. For example, to find the "unique set size" (USS), which is the amount of
  143. memory that a process is using that is not shared with any other process,
  144. you can go through every map in the process, find the PFNs, look those up
  145. in kpagecount, and tally up the number of pages that are only referenced
  146. once.
  147.  
  148. Other notes:
  149.  
  150. Reading from any of the files will return -EINVAL if you are not starting
  151. the read on an 8-byte boundary (e.g., if you sought an odd number of bytes
  152. into the file), or if the size of the read is not a multiple of 8 bytes.
  153.  
  154.       https://www.kernel.org/doc/Documentation/vm/pagemap.txt

pagemap, from the userspace perspective的更多相关文章

  1. linux 下 I/O 多路复用初探

    本文内容整理自B站up主 free-coder 发布的视频:[并发]IO多路复用select/poll/epoll介绍 引入 一般来讲,服务器在处理IO请求(一般指的是socket编程)时,需要对so ...

  2. 利用/proc/pid/pagemap将虚拟地址转换为物理地址

    内核文档: Documentation/vm/pagemap.txt pagemap is a new (as of 2.6.25) set of interfaces in the kernel t ...

  3. css3中perspective

    perspective 属性定义 3D 元素距视图的距离,以像素计.该属性允许改变 3D 元素查看 3D 元素的视图.当为元素定义 perspective 属性时,其子元素会获得透视效果,而不是元素本 ...

  4. css3 perspective perspective-origin属性的理解

    perspective字面意思是:透视. 在w3school中它的解释为:设置元素被查看位置的视图:通俗讲,就是我们看看一个物体的所处的视角,近大远小.就比如我们正对着电脑:当我无限贴近电脑屏幕的时候 ...

  5. Zero Copy I: User-Mode Perspective

    By now almost everyone has heard of so-called zero-copy functionality under Linux, but I often run i ...

  6. Opengl中矩阵和perspective/ortho的相互转换

    Opengl中矩阵和perspective/ortho的相互转换 定义矩阵 Opengl变换需要用四维矩阵.我们来定义这样的矩阵. +BIT祝威+悄悄在此留下版了个权的信息说: 四维向量 首先,我们定 ...

  7. CSS3打造3D效果——perspective transform的深度剖析

    声明:此篇博文虽是自己手写,但大量资源取自 张鑫旭 的博文.想看更详细 更专业的剖析请看张鑫旭的博文. 昨天对css3的transform做了初步的分析和认识,突然看到perspective属性,调了 ...

  8. css3 视距-perspective

           视距-用来设置用户与元素3d空间Z平面之间的距离. 实例1:       HTML: <div class="perspective"> <h3&g ...

  9. This kind of launch is configured to open the Debug perspective when it suspends.

    This kind of launch is configured to open the Debug perspective when it suspends. 因为设置了断点才会弹出这个,不需要调 ...

随机推荐

  1. Java接口与实例化

    看代码看到 public Runnable r = new Runnable() { @Override public void run() { ... } } 接口不能new ,不过可以生成一个匿名 ...

  2. C# ASP.NET MVC HtmlHelper用法大全

    UrlHrlper 下面的两个地址一样的功能 下边这个防止路由规则改变 比如UserInfo/Index改为UserInfo-Index,使用下面的不受影响 另一种形式的超链接: <%: Htm ...

  3. PL/SQL不支持64位Oracle Client 解决办法

    解决X64操作系统PL/SQL连接报错问题 make sure you have the 32 bits oracle client installed 说明PLSQL Developer并不支持Or ...

  4. this 的工作原理

    JavaScript 有一套完全不同于其它语言的对 this 的处理机制. 在五种不同的情况下 ,this 指向的各不相同. 全局范围内 this; 当在全部范围内使用 this,它将会指向全局对象. ...

  5. 我们应该如何去了解JavaScript引擎的工作原理

    “读了你的几篇关于JS(变量对象.作用域.上下文.执行代码)的文章,我个人觉得有点抽象,难以深刻理解.我想请教下通过什么途径能够深入点的了解javascript解析引擎在执行代码前后是怎么工作的,ec ...

  6. ThinkPHP讲解(十一)——验证码和文件上传

    一.验证码 1.页面前端显示 (验证码是图片标签,来源是控制器里的yzm()操作方法) <h1>登录</h1> <form action="__ACTION__ ...

  7. 161215、MySQL 查看表结构简单命令

    一.简单描述表结构,字段类型desc tabl_name;显示表结构,字段类型,主键,是否为空等属性,但不显示外键.二.查询表中列的注释信息select * from information_sche ...

  8. mac上安装Navicat Premium 破解版+汉化包

    Navicat是一款非常强大的sql分析管理工具.以前一直在windows上面使用. 由于工作的需要,我也是折腾出了这不易的mac破解版.下了好多网上的版本,亲测这个可用. 俗话说:工欲善其事,必先利 ...

  9. html里面的相对路径和绝对路径

    HTML有两种路径的写法:相对路径和绝对路径. 相对路径是在同一个目录的文件引用,如果源文件和引用文件在同一个目录里,直接写引用文件名即可. 如: a.html:     c:\test\menu\a ...

  10. LINK : fatal error LNK1104: 无法打开文件“LIBCD.lib”

    出现这类问题一般是由于所运行的项目是VC6(或者vs2003)创建的,而后又用VS2005或者更高版本工具打开项目导致的,原因都是因为LIBCD.lib文件被更改了.要解决问题的话,只要在链接设置那里 ...