Article View: borland.public.cppbuilder.nativeapi
Article #14833Re: PageFaults... are they a problem??
From: MWP
Date: Thu, 31 Jul 2003 16:04
Date: Thu, 31 Jul 2003 16:04
66 lines
4080 bytes
4080 bytes
Thanks for the reply. I now understand. Alan Bellingham <alanb@episys.com> wrote: >"MWP" <mwp@overclockers.com.au> wrote: > >>But i am accessing shared memory from external apps using OpenFileMapping and MapViewOfFile a lot (up to every 5ms). >>Would this cause these page faults? > >Oh, almost definitely yes. > >When you use these functions, the OS reserves a memory range, and maps >that range onto the file. As far as your used code is concerned, that >file appears to be in RAM, but it actually isn't. Every 'page' of >memory (about 4K in size last time I looked) is noted as being 'not >there'. > >(The processor uses a lookup table for this - for this purpose, it needs >1 bit per 4K of addressable memory, or 128K for 4GB.) > >When you access a page for the first time, effectively the processor >checks the bit. If it says the memory isn't currently mapped, the >processor generates a page fault. > >At this point, Windows catches the exception, and tries to do something >about it. In this case, it grabs a page of actual RAM, maps it to the >address required, loads the relevant data from the file into that page, >flips the bit to now say it's there, and tells the processor to restart >the instruction that caused the problem. > >Oh, yes, "maps it to the address required". The address that the program >sees and that the processor actually uses for a page of memory is >different. This means another lookup table that the processor uses. > >Of course, actual RAM isn't infinite, and sooner or later Windows will >need the actual RAM for something else. It'll unload the RAM, note the >address as being 'not there' again, and use the actual RAM for the >something else. > >(The above ignores the fun and games of what happens when you or >something else modifies the mapped file data. If more than one process >is mapping the same file, the two different process may look at the same >page of actual RAM, but think they're at different addresses.) > >And now to the conclusion: > >What can cause a huge number of page faults is mapping a file at least >as large as your actual free RAM, and then repeatedly dancing from one >end to the other in steps of the page size - as each new chunk of the >file is touched, it has to be loaded, only to be discarded before it >gets needed again. For this reason, when choosing algorithms to be used >with such virtual memory, you want to try to keep them using addresses >in the same area as much as possible. > >Also successfully allocating that sort of size of RAM may do the same >thing, since program memory is usually backed by 'virtual memory', which >is exactly this sort of file mapping, onto a temporary bit of file. > >This is also why Windows usually grinds to a halt before actually >'running out of memory'. It spends its time continually loading and >discarding virtual memory. > >Alan Bellingham >-- >alanb@episys.com
Technical Details
Message-ID:
<3f293e2b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!news-in-sterling.newsfeed.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3f28f191$1@newsgroups.borland.com> <VA.00001e5c.062c93ff@email.address.sorry> <3f291ea0$1@newsgroups.borland.com> <538iivgclj4qfo2ui8evdkarffsoqr181h@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ec1f290b7afbc30f X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-31 09:08:44 PST From: "MWP" <mwp@overclockers.com.au> Sender: "MWP" <mwp@overclockers.com.au> Reply-To: "MWP" <mwp@overclockers.com.au> Subject: Re: PageFaults... are they a problem?? Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 203.16.214.242 203.16.214.242 X-Forwarded-For: unknown, 150.101.76.119 References: <3f28f191$1@newsgroups.borland.com> <VA.00001e5c.062c93ff@email.address.sorry> <3f291ea0$1@newsgroups.borland.com> <538iivgclj4qfo2ui8evdkarffsoqr181h@4ax.com> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3f293e2b$1@newsgroups.borland.com> Date: 31 Jul 2003 09:04:59 -0700 X-Trace: newsgroups.borland.com 1059667499 207.105.83.65 (31 Jul 2003 09:04:59 -0700) Lines: 67 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!news-in-sterling.newsfeed.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail