简体   繁体   English

如何在虚拟内存 - Linux 中查看每个进程维护的页表?

[英]How can I see a page-table maintained by each process in Virtual Memory - Linux?

In the virtual memory concept- each process maintains their own page table.在虚拟内存概念中 - 每个进程维护自己的页表。 This page table maps the virtual address to the kernel virtual address.该页表将虚拟地址映射到内核虚拟地址。 This kernel virtual address translates the address to Physical RAM.该内核虚拟地址将地址转换为物理 RAM。 I understand that there is a Kernel Virtual adddres - vm area struct.我知道有一个内核虚拟地址 - vm area 结构。 This vm area struct finally maps this address to the Physical address.这个 vm area 结构体最终将这个地址映射到物理地址。 When I do cat /proc//maps - I see the direct mapping of virtual address to physical address.当我执行 cat /proc//maps 时 - 我看到了虚拟地址到物理地址的直接映射。 Because it maps the address to the file - with inode.因为它将地址映射到文件 - 使用 inode。 So, it looks that it is the address on the hard-disk, file descriptor, major-minor number.因此,它看起来是硬盘上的地址、文件描述符、主要次要编号。 There are a few address that are on the RAM. RAM上有几个地址。 So, I can say that I can't see the table where the Virtual address is mapped to Kernel virtual address.所以,我可以说我看不到虚拟地址映射到内核虚拟地址的表。 I want to see that table.我想看看那张桌子。 How can I see that?我怎么能看到呢? It should not be in the kernel space.它不应该在内核空间中。 Because when process is accessing let's say memory - 0x1681010 then this should be translated to kernel virtual memory address.因为当进程访问时让我们说内存 - 0x1681010 那么这应该被转换为内核虚拟内存地址。 Finally, this address should be translated to physical memory address.最后,这个地址应该被转换成物理内存地址。

No, the Linux kernel maintains the processes page tables (but not the processes themselves).不, Linux 内核维护进程页表(但不维护进程本身)。 Processes are only seeing virtual memory thorough their address space .进程只能通过它们的地址空间看到虚拟内存 Processes use some syscalls , like eg mmap(2) or execve(2) , to change their address space.进程使用一些系统调用,例如mmap(2)execve(2) ,来改变它们的地址空间。

Physical addresses and page tables and dealing with and managing the MMU is the business of the kernel, which actually provides some " abstract machine " (with the virtual address spaces, the syscalls as atomic elementary operations, etc...) to user applications.物理地址和页表以及处理和管理MMU是内核的业务,它实际上为用户应用程序提供了一些“抽象机器”(具有虚拟地址空间、系统调用作为原子基本操作等)。 The applications don't see the raw (x86) hardware, but only the user mode as given by the kernel.应用程序看不到原始 (x86) 硬件,而只能看到内核给出的用户模式 Some hardware resources and instructions are not available to them (they only run in user space ).一些硬件资源和指令对他们来说是不可用的(他们只能在用户空间运行)。

The page tables are managed by the kernel, and indeed various processes may use different -or sometimes same- page tables.页表由内核管理,实际上不同的进程可能使用不同的——有时是相同的——页表。 (So context switches managed by the kernl may need to reconfigure the MMU). (因此由内核管理的上下文切换可能需要重新配置 MMU)。 You don't care, (and the user processes don't see page tables) the kernel will manage them.你不在乎,(用户进程看不到页表)内核会管理它们。

And no, /proc/self/maps does not show anything about physical addresses, only about virtual one.不, /proc/self/maps不显示任何有关物理地址的信息,只显示虚拟地址。 The kernel is permitted to move processes from one core to another, to move pages from one physical (not virtual) address to another, etc...., at any time;内核可以随时将进程从一个内核移动到另一个内核,将页面从一个物理(非虚拟)地址移动到另一个,等等……; and applications usually don't see this (they might query this with mincore(2) , getcpu(2) and thru proc(5) ...)应用程序通常看不到这一点(他们可能会使用mincore(2)getcpu(2)proc(5) ...

Applications should not care about physical memory or interrupts , like page faults (only the kernel care about these; sometimes by sending signals).应用程序不应该关心物理内存或中断,如页面错误(只有内核关心这些;有时通过发送信号)。

The virtual to physical address translation happens in the MMU.虚拟地址到物理地址的转换发生在 MMU 中。 Usually, it is successful (perhaps transparently accessing page tables), and the processor sends on the bus to the RAM the translated physical address (corresponding to some virtual address handled by the user-mode machine instruction).通常,它是成功的(可能是透明地访问页表),处理器在总线上将转换后的物理地址(对应于用户模式机器指令处理的某个虚拟地址)发送到 RAM 中。 When the MMU cannot handle it, a page fault occurs, which is processed by the kernel (which could swap-in some page, send a SIGSEGV , do a context switch, etc...)当 MMU 无法处理它时,会发生页面错误,由内核处理(可以交换某些页面、发送SIGSEGV 、执行上下文切换等...)

See also the processor architecture , instruction set , page table , paging , translation lookaside buffer , cache , x86 and x86-64 wikipages (and follow all the links I gave you).另请参阅处理器体系结构指令集页表分页翻译后备缓冲区缓存x86x86-64维基页面(并遵循我给您的所有链接)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Linux的VirtualQueryEx替代品-如何获取另一个进程的虚拟内存范围 - VirtualQueryEx alternative for Linux - how to get virtual memory range of another process Linux中单个进程的总/可用虚拟内存 - Total/Free virtual memory for a single process in Linux 有没有办法查看每个线程的进程的虚拟内存usgae? - Is there any way to see virtual memory usgae of a process per thread? 如何查看我的程序正在消耗多少内存? - how can I see how much memory my program is eating? 如何在linux上看到(C和C ++)二进制符号? - How can I see symbols of (C and C++) binary on linux? 如何处理此Linux C ++警告? “找不到`sockaddr_in'的虚拟表的链接器符号” - How do I approach this Linux C++ warning? “can't find linker symbol for virtual table for `sockaddr_in'” 如何查看指针 memory 中的实际值 C++? - How can I see the actual value in memory of a pointer, C++? 进程如何访问不属于其虚拟地址空间的内存映射IO地址? - How can a process access memory mapped IO address not belonging to it's virtual address space? 一个进程可以从它的虚拟内存中的任何地址读/写吗? - Can a process read/write at any address from it's virtual memory? 用户进程看不到服务创建的全局共享内存 - User process can't see global shared memory created by service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM