zoukankan      html  css  js  c++  java
  • Page in/Page out/Page fault

    Paging refers to writing portions, termed pages, of a process' memory to disk.

    Swapping, strictly speaking, refers to writing the entire process, not just part, to disk. In Linux, true swapping is exceedingly rare, but the terms paging and swapping often are used interchangeably.

    When pages are written to disk, the event is called a page-out, and when pages are returned to physical memory, the event is called a page-in.

    A page fault occurs when the kernel needs a page, finds it doesn't exist in physical memory because it has been paged-out, and re-reads it in from disk.

    Page-ins are common, normal and are not a cause for concern. For example, when an application first starts up, its executable image and data are paged-in. This is normal behavior.

    Page-outs, however, can be a sign of trouble. When the kernel detects that memory is running low, it attempts to free up memory by paging out.

    Though this may happen briefly from time to time, if page-outs are plentiful and constant, the kernel can reach a point where it's actually spending more time managing paging activity than running the applications,

    and system performance suffers. This woeful state is referred to as thrashing.

     

    The reaction to a "page fault" is a "page in".

    Page faults occur when any application (and not just the kernel) needs a page that is not currently in memory. A page fault is also not a "kernel" thing, it's a hardware thing. The reaction to the fault, often a "page in" is handled by the kernel. Also, the setup required to support virtual memory is handled by the kernel, but the fault itself is all hardware.

    There is also a slight inaccuracy in stating that the fault occurs because the page was previously paged out. The page that causes the fault does not have to have been previously paged out. If the page referred to program code it doesn't get paged out, it just gets paged in when the fault occurs since the code exists in the executable file and doesn't need to be paged out. A page fault can also occur when trying to access memory beyond the end of the stack, thus signalling the O/S that more stack space needs to be allocated, but this again is memory that was never paged out. Here the page is just used as a guard or sentry to tell the O/S when the application needs more stack space.

    So I would reword that sentence thusly:

    A page fault occurs when the CPU needs a page which does not exist in physical memory. In response to the fault the kernel allocates a free page for the missing memory and if the page was previously paged out, the kernel pages in the previously paged out data. If the kernel is unable to find an unused page to allocate for the missing memory then an existing page will be freed and if need be paged out.

  • 相关阅读:
    linux-gcc 编译时头文件和库文件搜索路径
    程序自启动位置(8种方法,注册表有6处)
    谷歌、flick网站图片 一次性下载 javaWeb项目 多线程下载,
    部署vc2008开发的程序(vcredist_x86是其中一个办法)
    vs2012-vs2013编译出来的程序不能在xp上运行解决方法
    openssl编译
    libcurl编译
    qt 国际化(翻译时会触发changeEvent)
    uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列
    qtcreator增加doxygen注释
  • 原文地址:https://www.cnblogs.com/princessd8251/p/5075776.html
Copyright © 2011-2022 走看看