There is a file that describes the structure of the virtual address space of the process, this file looks like this:
08048000-08053000 r-xp 00000000 08:03 18877 /usr/bin/cat 08053000-08054000 r--p 0000a000 08:03 18877 /usr/bin/cat 08054000-08055000 rw-p 0000b000 08:03 18877 /usr/bin/cat 091e3000-09204000 rw-p 00000000 00:00 0 [heap] 4f2d0000-4f2ef000 r-xp 00000000 08:03 1857 /usr/lib/ld-2.15.so 4f2ef000-4f2f0000 r--p 0001e000 08:03 1857 /usr/lib/ld-2.15.so 4f2f0000-4f2f1000 rw-p 0001f000 08:03 1857 /usr/lib/ld-2.15.so 4f2f7000-4f4a2000 r-xp 00000000 08:03 1858 /usr/lib/libc-2.15.so 4f4a2000-4f4a3000 ---p 001ab000 08:03 1858 /usr/lib/libc-2.15.so 4f4a3000-4f4a5000 r--p 001ab000 08:03 1858 /usr/lib/libc-2.15.so 4f4a5000-4f4a6000 rw-p 001ad000 08:03 1858 /usr/lib/libc-2.15.so 4f4a6000-4f4a9000 rw-p 00000000 00:00 0 b75c0000-b77c0000 r--p 00000000 08:03 57661 /usr/lib/locale/locale-archive b77c0000-b77c1000 rw-p 00000000 00:00 0 b77d9000-b77da000 rw-p 00000000 00:00 0 b77da000-b77db000 r-xp 00000000 00:00 0 [vdso] bf819000-bf83a000 rw-p 00000000 00:00 0 [stack] The first and second columns are the beginning and end of the virtual memory area, respectively. The second is right, the third is the offset in the file if mmap used, the fourth is the device number if read by mmap'ом . The fifth is the file number if read by mmap'ом and the sixth is the path to the file.
The x86 processor family has two-level virtual memory. The size of one page - 4 kb. One root page table (page directory) contains 1024 records each 4 bytes in size, each record can refer to the second level record - the page directory (page table). Each directory contains 1024 entries each 4 bytes in size.
Here, in fact, the task is to calculate the total size of the tables necessary for the operation of virtual memory for a specific file. I do this: the total size of the mapped memory for the file from the example is 4345856 (I haven't completely laid it out), then we find the number of pages, there are 4345856/4096 = 1061, they need 1061/1024 = 2 second-level directories and 1 is one indicates to them, in the end, you need 3 * 1024 * 4 = 12288. And for some reason, the answer is 7 * 1024 * 4. Maybe I do not understand something, can you explain? And tell you how to do it.