什么原因导致页面错误? [英] What causes page faults?

查看:283
本文介绍了什么原因导致页面错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Wikipedia :

页面错误是程序访问映射在虚拟地址空间中但未加载到物理内存中的页面的硬件陷阱,即硬件提出的软件陷阱. (强调我的)

A page fault is a trap to the software raised by the hardware when a program accesses a page that is mapped in the virtual address space, but not loaded in physical memory. (emphasis mine)

好的,那很有意义.

但是如果是这样,为什么每当刷新Process Hacker中的过程信息时,我都会看到大约15个页面错误?

But if that's the case, why is it that whenever the process information in Process Hacker is refreshed, I see about 15 page faults?

或者换句话说,为什么任何内存都被调出? (我不知道是用户内存还是内核内存.)我没有页面文件,并且在完全重启后,RAM使用量约为4 GB中的1.2 GB.不缺任何资源;为什么什么东西会被调出?

Or in other words, why is any memory getting paged out? (I have no idea if it's user or kernel memory.) I have no page file, and the RAM usage is about 1.2 GB out of 4 GB, which is after a clean reboot. There's no shortage of any resource; why would anything get paged out?

推荐答案

(我是Process Hacker的作者.)

(I'm the author of Process Hacker.)

首先:

页面错误是软件的陷阱 当程序产生时由硬件引发 访问在中映射的页面 虚拟地址空间,但未加载 在物理内存中.

A page fault is a trap to the software raised by the hardware when a program accesses a page that is mapped in the virtual address space, but not loaded in physical memory.

这并不完全正确,如同一篇文章的稍后部分所述(小页面错误).存在软页面错误,所有内核所需要做的就是将页面添加到进程的工作集中.这是Windows Internals一书中的一张表(我已经排除了那些导致访问冲突的表):

That's not entirely correct, as explained later in the same article (Minor page fault). There are soft page faults, where all the kernel needs to do is add a page to the working set of the process. Here's a table from the Windows Internals book (I've excluded the ones that result in an access violation):

  • 故障原因-结果
  • 访问不在内存中但在磁盘上的页面文件或映射文件中的页面-分配物理页面,并从磁盘读取所需的页面并进入相关工作集
  • 访问备用列表或已修改列表上的页面-将页面转换为相关的进程,会话或系统工作集
  • 访问零需求页面-将零填充页面添加到相关工作集中
  • 写至写时复制页面-制作页面的进程私有(或会话私有)副本,并替换进程或系统工作集中的原始文件
  • Reason for Fault - Result
  • Accessing a page that isn’t resident in memory but is on disk in a page file or a mapped file - Allocate a physical page, and read the desired page from disk and into the relevant working set
  • Accessing a page that is on the standby or modified list - Transition the page to the relevant process, session, or system working set
  • Accessing a demand-zero page - Add a zero-filled page to the relevant working set
  • Writing to a copy-on-write page - Make process-private (or session-private) copy of page, and replace original in process or system working set

页面错误可能由于多种原因而发生,如您在上面看到的.其中只有一个与从磁盘读取有关.如果您尝试从堆中分配一个块,并且堆管理器分配了新页面,然后访问这些页面,则会出现零需求页面错误.如果您尝试通过写入kernel32的页面来在kernel32中挂接一个函数,则会出现写时复制错误,因为这些页面被以静默方式复制,因此您的更改不会影响其他进程.

Page faults can occur for a variety of reasons, as you can see above. Only one of them has to do with reading from the disk. If you try to allocate a block from the heap and the heap manager allocates new pages, then accesses those pages, you'll get a demand-zero page fault. If you try to hook a function in kernel32 by writing to kernel32's pages, you'll get a copy-on-write fault because those pages are silently being copied so your changes don't affect other processes.

现在更具体地回答您的问题:Process Hacker似乎仅在更新其服务信息时出现页面错误-也就是说,当它调用

Now to answer your question more specifically: Process Hacker only seems to have page faults when updating its service information - that is, when it calls EnumServicesStatusEx, which RPCs to the SCM (services.exe). My guess is that in the process, a lot of memory is being allocated, leading to demand-zero page faults (the service information requires several pages to store, IIRC).

这篇关于什么原因导致页面错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆