I'm trying to get my head around the two files mentioned in the title. I've looked up what the bits are; however, I'm failing to understand how to extract useful info from them (or I'm simply approaching it the wrong way).
Let me explain: The pagemaps is a rather newer "feature" pseudo file that contains the physical frame information of virtual pages assigned to a current [pid]. That is, given a virtual page that starts at address x, say 'vas' for virtual address start, i can index the pagemap file using vas to get the 64bits of the mapped physical page frame. These bits contain info about that virtual page. However, when I extract the bits and do a bit of shifting I'm getting lost with what I'm seeing.
The bits are represented as follows: 0-54 is the page frame number, 55-60 is the page shift, 63rd bit is the present bit, there are other bits of little interest to me. After I do a bit of mapping using vas addresses from /proc/[pid]/maps, it seems that just about every process' page is swapped, i.e. the 63rd bit is always a zero. :(
I guess the question would be, how should I go about effectively using pagemaps to get the equivalent physical address of the address given by /proc/[pid]/maps
To be fair, I've posted a similar question but the approach was a bit different a few days earlier.
If anyone can shed some light on this matter I would be greatly appreciative.
===EDIT===
To address the comment below: I'm reading a line from /proc/[pid]/maps and the lines look like:
00400000-00401000 r-xp 00000000 08:01 8915461 /home/janjust/my_programs/shared_mem 7ffffef1b000-7ffffef3c000 rw-p 00000000 00:00 0 [stack]
Then I'm extracting the number of virtual pages it touches and indexing a binary file /proc/[pid]/pagemaps , and for each virtual page I can extract the physical page it is assigned to.
The output looks like:
00400000-00401000 r-xp 00000000 08:01 8915461 /home/janjust/my_programs/shared_mem num_pages: 1 : 86000000001464C6
One physical address for each virtual page in the virtual range.
The code for reading the line and extracting the physical address is:
74     /* process /proc/pid/maps, by line*/
75     while(fgets(line, 256, in_map) != NULL){
76         unsigned long vas;
77         unsigned long vae;
78         int num_pages;
79 
80         //print line
81         printf("%s", line);
82 
83         /*scan for the virtual addresses*/
84         n = sscanf(line, "%lX-%lX", &vas, &vae);
85         if(n != 2){
86             printf("Involid line read from %s\n",maps);
87             continue;
88         }
89 
90         num_pages = (vae - vas) / PAGE_SIZE;
91         printf("num_pages: %d\n", num_pages);
92 
93         if(num_pages > 0){
94             long index  = (vas / PAGE_SIZE) * sizeof(unsigned long long);
95             off64_t o;
96             ssize_t t;
97 
98             /* seek to index in pagemaps */
99             o = lseek64(pm, index, SEEK_SET);
100             if (o != index){
101                 printf("Error seeking to o:%ld, index:%ld.\n", o, index);
102             }
103 
104             /* map the virtual to physical page */
105             while(num_pages > 0){
106                 unsigned long long pa;
107 
108                 /* Read a 64-bit word from each pagemap file... */
109                 t = read(pm, &pa, sizeof(unsigned long long));
110                 if(t < 0){
111                     printf("Error reading file \"%s\" \n", page_map);
112                     goto next_line;
113                 }
114                 printf(": %016llX\n", pa);
However, although I think I'm getting the right output, the index seems to be either a type mismatch or something else is going on: The output say for instance for the [shared mem] line in maps gives a wrong index; yet I'm still able to scan through the binary file and get the physical page address.
The example of that output is below:
969 7f7f08d58000-7f7f08d59000 rw-s 00000000 00:04 0    /SYSV00003039 (deleted)
970 num_pages: 1
971 Error seeking to o:-1081840960, index:273796065984.
972 : 8600000000148267
Ok, now, lastly I should say that this is under a 64bit OS, and this problem doesn't persist in a 32bit OS.
 
     
    