[haiku-development] Re: Page faults.

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 18 Sep 2008 00:23:09 +0200

On 2008-09-17 at 18:53:20 [+0200], Bruno Albuquerque <bga@xxxxxxxxxxxxx> 
wrote:
> I used Axel's latest changes to monitor the page fault pattern in Haiku
>    and I noticed something I am not 100% sure was expected.
> 
> If you start running ls - l in the terminal repeatedly, you will get
> lots of page faults (around 700/s). Is this really expected considering
> I am simply listing the same directory over and over without doing
> anything else (so the directory contents and file inodes will already be
> in the cache)? Or is this just the fact that it is a different team and
> them the cache must be remapped to it (and this is the reason of the
> page faults)?

Sort of. When an area is created -- via create_area() or mmap() -- normally 
none of its addresses has been mapped yet. Exceptions are B_FULL_LOCK 
areas, which are almost never used in userland, and an optimization I 
introduced recently. If there are already pages of a file cached, mmap() 
will immediately map all those pages into the respective area(*). That is 
the read-only segments of executables, shared libraries, and add-ons will 
cause way less page faults when used the second time (in your example 
likely none). Pages for stacks and heaps are lazily allocated and mapped, 
though, i.e. every single used page causes a page fault. So, depending on 
how many instances of ls are executed, 700 page faults per second doesn't 
sound that much.

BTW, I've already experimented a bit with pre-faulting (i.e. mapping more 
than the one required page on a page fault) and it does reduce the number 
of page faults significantly -- at least up to the point where our memory 
allocator starts increasing the heap size page-wise.

CU, Ingo

(*) To clarify the semantics: Mapping a file (via mmap()) does only create 
a logical connection between the created area and a range in the file. It 
doesn't mean that any page of the file is mapped ("wired") into the 
respective team's address space.

Other related posts: