Thread: page fault

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    page fault

    Hello everyone,


    I can understand hard page fault is we need to load from page file into working set (RAM). But what is a soft page fault? I am confused.


    thanks in advance,
    George

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    How about using Google ? The first link for "soft page fault" will answer the question.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks nvoigt,


    I found,

    http://blogs.msdn.com/greggm/archive.../21/61237.aspx

    But do not quite understand what the 2 situations below mean when there is soft page fault. Could you give more information please?

    1. wants to be zero (called ‘demand zero’ pages)
    2. when a page is written to for the first time (‘copy on write’ pages)

    If you have any good comments, it is appreciated if you could share and if you have other good resources links for this topic, could you share please?

    Quote Originally Posted by nvoigt View Post
    How about using Google ? The first link for "soft page fault" will answer the question.

    regards,
    George

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Did you google "demand zero" and "copy on write" ? They do exactly as their name says:

    demand zero -> demands a page that is filled with zeroes. Therefore, it has to be a new page, but the new page doesn't need to be read from disk, it can be filled without disk access.

    copy on write -> Means that the page is already in use. The processes will share the page until one writes to it. Only then will a copy be made. As the page is already active, it has not to be loaded from disk.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There are several cases for "soft page faults":
    1. Administrative "not present" for statistics - if the OS wants to know if a page is being accessed, the OS can set the page not present, and then see if it gets a page-fault within a given time. If there's no page-fault, then it's probably a good candidate for "removing from memory".

    2. Demand paging. This, as has been explained, falls into two categories:
    - Copy on write. For example data sections in DLL's can be shared between multiple processes until such a time that the data has been modified. If there is large amounts of rarely modified data, the saving can be quite large. The original data is marked read-only, and when a write happens, a page-fault handler allocates a new page and copies the original data - this page is then set writable.

    Copy on write also happens in Linux when a process is Forked, where the new process gets the same pages as the old process, but the new process pages are marked read-only. Again, the page-fault handler copies the data into a newly allocated page, which is writable.

    3. Zero-pages, where a large block of memory is supposed to be zero, but until an access actually happens, there is no backing memory [e.g. a process allocates 2MB for a document, then loads it with 38KB of data - so the remaining 1.9+MB is never touched - no reason to actually take up REAL memory for alll those pages of zeros, right?] When the document then expands beyond 40KB [next 4KB limit], the OS will need to fill in another zero-filled page. It just allocates a new page and fills it with zero.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats and nvoigt,


    First of all, my apologies to always forget to merge posting in the past. :-)

    Two more comments,

    1. About copy on write as you mentioned below, for the new page -- which needs to grant write privilege, yes, there is no need to do I/O, and only need to copy the read-only page to a new writatble page. It is fine to the new page. But, it will cause (if memory is low) other pages to swap out to swap page file. And if such swap-out pages will be demanded later, there will be hard page fault for the pages. Actually, increasing the size of physical RAM (working set) will usually cause the issue I mentioned above. Any comments?

    Quote Originally Posted by matsp View Post

    2. Demand paging. This, as has been explained, falls into two categories:
    - Copy on write. For example data sections in DLL's can be shared between multiple processes until such a time that the data has been modified. If there is large amounts of rarely modified data, the saving can be quite large. The original data is marked read-only, and when a write happens, a page-fault handler allocates a new page and copies the original data - this page is then set writable.

    Copy on write also happens in Linux when a process is Forked, where the new process gets the same pages as the old process, but the new process pages are marked read-only. Again, the page-fault handler copies the data into a newly allocated page, which is writable.
    Quote Originally Posted by nvoigt View Post
    copy on write -> Means that the page is already in use. The processes will share the page until one writes to it. Only then will a copy be made. As the page is already active, it has not to be loaded from disk.

    2. About demand for zero as you mentioned below, for the new page whose value is all 0 in initial state -- it is more accurate to say that the page is not allocated in physical RAM (working set) until the current process demands it. So, it is a page allocation operation (and initialize it with all 0 after initialization). Right?

    And the same, it will cause (if memory is low) other pages to swap out to swap page file. And if such swap-out pages will be demanded later, there will be hard page fault for the pages. Actually, increasing the size of physical RAM (working set) will usually cause the issue I mentioned above. Any comments?

    Quote Originally Posted by matsp View Post
    3. Zero-pages, where a large block of memory is supposed to be zero, but until an access actually happens, there is no backing memory [e.g. a process allocates 2MB for a document, then loads it with 38KB of data - so the remaining 1.9+MB is never touched - no reason to actually take up REAL memory for alll those pages of zeros, right?] When the document then expands beyond 40KB [next 4KB limit], the OS will need to fill in another zero-filled page. It just allocates a new page and fills it with zero.

    --
    Mats
    Quote Originally Posted by nvoigt View Post
    demand zero -> demands a page that is filled with zeroes. Therefore, it has to be a new page, but the new page doesn't need to be read from disk, it can be filled without disk access.

    regards,
    George
    Last edited by George2; 01-10-2008 at 05:47 AM.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Of course, if you allocate a new page, if there isn't sufficient free pages, there will have to be a "swap-out" of a page.

    This is the same as if an application requests more memory for any other reason, including the swap-in of another page for an application.

    I'm not sure what your point is....

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    My point is...

    Let us put the swap-out issue for other pages aside, do you agree all other points in my last post. :-)

    Quote Originally Posted by matsp View Post
    Of course, if you allocate a new page, if there isn't sufficient free pages, there will have to be a "swap-out" of a page.

    This is the same as if an application requests more memory for any other reason, including the swap-in of another page for an application.

    I'm not sure what your point is....

    --
    Mats

    regards,
    George

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Let me summarize what I think you are saying:
    All soft-page-faults except number 1 [statistical/administrative] are allocating pages.

    Yes, I agree with that.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    Your summary is always brief and clear compared with mine. :-)

    My question is answered.

    Quote Originally Posted by matsp View Post
    Let me summarize what I think you are saying:
    All soft-page-faults except number 1 [statistical/administrative] are allocating pages.

    Yes, I agree with that.

    --
    Mats

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. monitor page fault
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-15-2008, 04:17 AM
  2. why page based I/O can improve performance?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-12-2006, 07:42 AM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. virtual memory
    By sweets in forum C Programming
    Replies: 6
    Last Post: 11-06-2004, 06:55 AM
  5. Page Fault in Visual C++
    By readerwhiz in forum C Programming
    Replies: 6
    Last Post: 05-03-2002, 12:30 AM