Thread (9 messages) 9 messages, 3 authors, 2021-09-21
STALE1744d REVIEWED: 4 (0M)
Revisions (2)
  1. v2 current
  2. v3 [diff vs current]

[PATCH v2 1/1] Documentation: update pagemap with shmem exceptions

From: Tiberiu A Georgescu <hidden>
Date: 2021-09-20 16:54:08
Also in: linux-mm, lkml
Subsystem: documentation, memory management - misc, the rest · Maintainers: Jonathan Corbet, Andrew Morton, David Hildenbrand, Linus Torvalds

Mentioning the current missing information in the pagemap and alternatives
on how to retrieve it, in case someone stumbles upon unexpected behaviour.

Signed-off-by: Tiberiu A Georgescu <redacted>
Reviewed-by: Ivan Teterevkov <redacted>
Reviewed-by: Florian Schmidt <redacted>
Reviewed-by: Carl Waldspurger <redacted>
Reviewed-by: Jonathan Davies <redacted>
---
 Documentation/admin-guide/mm/pagemap.rst | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst
index fb578fbbb76c..ea3f88f3c18d 100644
--- a/Documentation/admin-guide/mm/pagemap.rst
+++ b/Documentation/admin-guide/mm/pagemap.rst
@@ -196,6 +196,28 @@ you can go through every map in the process, find the PFNs, look those up
 in kpagecount, and tally up the number of pages that are only referenced
 once.
 
+Exceptions for Shared Memory
+============================
+
+Page table entries for shared pages are cleared when the pages are zapped or
+swapped out. This makes swapped out pages indistinguishable from never-allocated
+ones.
+
+In kernel space, the swap location can still be retrieved from the page cache.
+However, values stored only on the normal PTE get lost irretrievably when the
+page is swapped out (i.e. SOFT_DIRTY).
+
+In user space, whether the page is swapped or none can be deduced with the
+lseek system call. For a single page, the algorithm is:
+
+0. If the pagemap entry of the page has bit 63 (page present) set, the page
+   is present.
+1. Otherwise, get an fd to the file where the page is backed. For anonymous
+   shared pages, the file can be found in ``/proc/pid/map_files/``.
+2. Call lseek with LSEEK_DATA flag and seek to the virtual address of the page
+   you wish to inspect. If it overshoots the PAGE_SIZE, the page is NONE.
+3. Otherwise, the page is in swap.
+
 Other notes
 ===========
 
-- 
2.33.0.363.g4c719308ce
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help