[Gllug] Pages marked as present but not mapped

Christian Smith csmith at thewrongchristian.org.uk
Tue Aug 30 10:48:21 UTC 2011


On Mon, Aug 29, 2011 at 12:06:26PM +0100, Adrian McMenamin wrote:
> I wonder if one of the kernel gurus here can help me with this - I have
> rifled through a lot of literature but cannot find a comprehensive
> explanation.
> 
> I have written some code (https://github.com/mcmenaminadrian/valext) that
> uses ptrace to step through the execution of a Linux program and on every
> step query the /proc/PID/pagemap to record how many pages are present.
> 
> The code seems to work fine (but if anyone spots an error in it let me
> know!) but returns a lot of pages which are marked as present but which
> have no page table entries. Typically these are as numerous as pages which
> are present and have a PTE.
> 
> Now, what I read is that these pages do exist - but nowhere have I read a
> decent explanation of what they are. Anyone here able to give me an
> explanation or point me towards one?

What I suspect is happening is that you're reading entries for pages that
are not present (else the present bit would be 1) but are not swapped.

This will be mmap'ed pages that have never been referenced. mmap'ed
pages are never "swapped", they are written to their underlying file
if dirty. Only anonymouse and private pages are swapped to the swap files.
Unreferenced mmap pages simply use the virtual memory map information
to locate their data from the file, so don't need the swap information.

So your comment needs fixing to report these pages differently:

--- valext.c.orig       2011-08-30 11:43:10.000000000 +0100
+++ valext.c    2011-08-30 11:44:12.000000000 +0100
@@ -176,7 +176,8 @@
        } else if (*pgstatus & present) {
            presentcnt++;
        } else {
-           //page is present but not in page table
+           //page is not present but in page table
+           //unmapped mmap'ed data
            notpresentcnt++;
        }
        i++;


Christian
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list