pagemap.txt 5.6 KB

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