Hey,

Have you guys got any tips on reducing the number of page faults caused in our programs? Looking at programs like Windows Media Player 8, it causes around 140,000 page faults after playing for 15 mins!! Im assuming (and after reading) that page faults are costly, any tips?

Thanks :grin:

oDD
Posted on 2001-10-31 09:02:16 by oDD
Page faults occur when you touch executable pages for the first
time. Aint much to do about this. But with the small sizes of our
programs, and the fact that we wont get page faults again unless
we get paged out, this is not too much of a problem.

HOWEVER, large data structures in .data? might be a problem...
Using VirtualAlloc, you can make it COMMIT the memory right away,
which (afaik) means you will NOT get page faults when accessing
the memory... keep this in mind (and do tests). HeapAlloc, GlobalAlloc,
and the likes, probably use a guard page scheme, which means you'll
get page faults.

Just guesses, do some tests.
Posted on 2001-10-31 10:29:26 by f0dder
careful about doing page commits w/o testing. you don't get something for free here. if there's a memalloc issue then you'll wind up just getting the page faults in another process... robbing peter to pay paul... if you're not careful you can actually make things worse. what you need is proper balance.

page thrashing & cache thrashing are two of the monsters that keep me up at nights but so far i haven't been smart enuf to figure out a silver bullet for these problems.

in some older o/s's there were system settings to help with this kind of thing but i don't know enuf windows to be specific.
Posted on 2001-10-31 11:01:18 by rafe
rafe, it depends on what the problems are caused by. If it's insufficient
memory, committing lots in one app is surely bad for the rest.
If the problems are caused by guard pages and "just-in-time" commitment
(as is usually done), committing will be no problem. Committing a
meg if you NEED a meg is most likely a good idea. Quake pretouched
all it's allocated pages to help speed (in a way to avoid a pretouch-detecting
algorithm in windows, hehe).
Posted on 2001-10-31 11:21:33 by f0dder
thanks. yea, you're right about taking a meg if you need it & you've got plenty.

correct me if i'm wrong... pre-touching sounds useful but only really as a way to determine when & where pages are loaded, which can be useful. But i can't see it improving overall speed because as you mentioned you're going to have to load the pages sometime.

Like I said this is something that concerns me so i'm all eyes. I'm using valloc with no guard pages... i handle that logic myself because the data stucts grow from both the top & bottom of the allocated area & any potential guard page will float

edit: I hope that luck has no play in your up comming surgery & that if it does it's only good :-|
Posted on 2001-10-31 12:14:31 by rafe
Thanks guys, Ill do what u said f0dder and do some tests. Currently I get ~800 page faults, just executing my program. quote from MSDN says "A page fault results in about 1 million lost instructions." WOW thats a lot of waste :) (800 million lost instructions!)

Anywayz thnx again
Posted on 2001-10-31 20:53:32 by oDD
rafe, pretouching means you get your pagefaults at one time, instead
of "as they happen". Thus you have a little longer initial loadtime,
but faster execution time. Also, in the case of (big) local stack data
that is accessed non-linearily, you will have to pretouch or get pagefaults.

Again, I'm not sure whether VirtualAlloc with reserve+commit will
generate a pagefault on first access, but I hope+think not.
Posted on 2001-11-01 00:04:30 by f0dder