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