A minor page fault occurs when a process attempts to access memory that has not been initialized, requiring the system to perform operations to fill memory maps or management structures. The impact is usually minor. A major page fault occurs when the system must synchronize memory buffers with disk or swap memory pages, requiring input/output that increases latency significantly. It happens when a virtual address without a physical page allocated is referenced.
1. A potential source of memory latency is called a minor page fault. They are created when a
process attempts to access a portion of memory before it has been initialized. In this case, the
system will need to perform some operations to fill the memory maps or other management
structures. The severity of a minor page fault can depend on system load and other factors, but
they are usually short and have a negligable impact.
A more severe memory latency is a major page fault. These can occur when the system has to
synchronize memory buffers with the disk, swap memory pages belonging to other processes, or
undertake any other Input/Output activity to free memory. This occurs when the processor
references a virtual memory address that has not had a physical page allocated to it. The
reference to an empty page causes the processor to execute a fault, and instructs the kernel
code to allocate a page and return, all of which increases latency dramatically
缺页有 3 种:major page fault,minor page fault,protection fault
major page faults 发生在试图访问一个虚拟内存单元,该单元虽已被 map
到 Solaris 的某个段映像,不过并不存在于物理内存中,这时,MMU 会触发一个
缺页中断(x86)或 trap(sparc),导致内核处理程式比较该内存错误地址发生在
哪个段。如果不属于所有一个段则给进程发送一个段错误 SIGSEGV。否则,将
调用该段驱动程式的 page-fault 例程。调用该例程的结果可能是两种:
1. 该内存存在于 swap 区,段驱动通过 vnode 的 getpage 函数,从 swap 读入
到物理内存
2. 该内存从未被使用,需要新生成该页
minor page faults 发生在试图访问一个虚拟内存单元,该单元已被 map 到
Solaris 的某个段映像,并且已存在于物理内存,但还未建立物理内存和虚拟地址
空间 转换关系。例如系统种的共享库,就属于这种情形,实际上多个进程只是共享
同一共享 库的物理内存页,第一个引用共享库的进程导致一个 major page faults,
而之后的其 他进程引用则只是 minor page faults,attach 在该库的物理内存上。
protection faults 发生在试图访问一个虚拟内存单元,该单元访问方式和所在段的
访问 方式相悖。例如写程式的代码段将会导致该错误。
It's normal and unremarkable for your application to generate page
faults. In linux (and most other modern OSes), the operating system
doesn't load all of your code and data into memory immediately when your
program starts, it simply sets up internal data structures so that the
code and data can be found if/when they're later needed. So the pages
corresponding to your program code and data are "faulted in" --
essentially one at a time -- as you access them.
Once they've been allocated and/or read into memory, they are likely to
remain there as long as they're being used regularly (also assuming you
have an adequate amount of physical memory).
2. Likewise, if you allocate some large buffers, for example, you'll find
that in actuality the operating system merely did some bookkeeping at
the time you did the allocation. The memory won't actually be made
available to your process until your program attempts to access it.
This will cause a page fault; physical memory is then made available to
your process, "swapping" some other page to the paging device if
necessary (hopefully a page that hasn't been used recently by your
pjrogram or any another).