的/ proc / [PID] / pagemaps和的/ proc / [PID] /地图| Linux的 [英] /proc/[pid]/pagemaps and /proc/[pid]/maps | linux
问题描述
我试图让我的头在标题中提到的两个文件左右。
我抬起头位是什么;不过,我没有理解如何从中提取有用的信息(或者我只是接近了错误的方式)。
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).
让我来解释一下:本pagemaps是一个相当新的功能伪包含分配给电流[PID]虚拟页的物理帧信息文件。也就是说,给定一个虚拟页面起始地址为X,说'增值'的虚拟地址开始,我可以利用指数输精管得到映射的物理页面框架的64位的页映射文件。这些位包含有关虚拟页的信息。
然而,当我解压位和做一些转变,我迷路与我所看到的。的
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.
该位被重新psented为$ P $如下:0-54是页面帧号,55-60是页面的转变,第63位为present位,有对我的兴趣不大的其他位。
之后,我用输精管地址做一点映射从/ proc / [PID] /地图,似乎只是每进程的页面交换,即第63位始终为零。 (
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. :(
我想问题是,我应该如何去有效利用pagemaps得到给出的地址相当于物理地址的/ proc / [PID] /图
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.
如果任何人都可以在这个问题上提供一些线索,我会大大AP preciative。
If anyone can shed some light on this matter I would be greatly appreciative.
的 ===编辑=== 的
要解决下面的评论:
我读线从/ proc / [PID] /地图和线路如下:
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 /家庭/ janjust / my_programs / shared_mem
7ffffef1b000-7ffffef3c000 RW-P 00000000 00:00 0 [堆栈]
00400000-00401000 r-xp 00000000 08:01 8915461 /home/janjust/my_programs/shared_mem 7ffffef1b000-7ffffef3c000 rw-p 00000000 00:00 0 [stack]
然后我提取倒是虚拟页面数和索引的二进制文件/ proc / [PID] / pagemaps,并为每个虚拟页我可以提取物理页就被分配到。
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.
输出如下:
00400000-00401000 R-XP 00000000 08:01 8915461 /家庭/ janjust / my_programs / shared_mem
NUM_PAGES:1
:86000000001464C6
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.
的code代表读线路和提取的物理地址是:
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.
这输出的例子是如下:
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
好了,现在,最后我应该说,这是一个64位操作系统下,这个问题不会在32位操作系统坚持。
Ok, now, lastly I should say that this is under a 64bit OS, and this problem doesn't persist in a 32bit OS.
推荐答案
哦K,该指数是正确的,但off64_t O(8个字节),长指数比较是间pretingØ错因此为什么我得到这个错误。
哈!这是一个愚蠢的错误。
所以加入适当的头花的照顾。
Oooh K, the index was correct but comparing off64_t o (8bytes) with long index was interpreting o wrong hence why I was getting that error. Ha! this was a stupid mistake. So adding the appropriate header took care of that.
缺少标题: - 。/的叹息的修复与off64_t进行比较的问题上无符号长
Missing header :-/ sigh fixes the issue of comparing off64_t with a unsigned long.
这篇关于的/ proc / [PID] / pagemaps和的/ proc / [PID] /地图| Linux的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!