| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Page Faults
How concerned should I be if I have say 80 new page faults per update of Task Manager? This an application which has 8 threads collecting data at high speed and shipping it out through a socket. I don't know how top feel about page faults.
__________________
Wakeup in the morning and kick the day in the teeth!! Or something like that. "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do." |
|
#2
|
|||
|
|||
|
Page faults are not necessarily bad. What you're probably thinking of as a really bad thing is an invalid page fault, which most of us remember in those ugly Windows 3.1 error boxes.
(The following is in abstract terms and does not refer to any particular implementation of a memory management scheme, so don't complain if <your_OS> does it a bit differently )The definition of a page fault has much to do with memory management on the operating system level. Each process has memory space, separated into pages. A page is the smallest chunk of memory that can be allocated to a process. Therefore, each memory address can be thought of a page number plus an offset within that page. If everything was stored in physical memory, this would not be a problem. However, when you get virtual memory thrown into the mix, things get a lot more complicated. Basically, virtual memory gives you the illusion of a lot more memory, but you can only directly access data that is in physical memory. Since there is more virtual memory than physical memory, not all memory pages are actually held in physical memory at one particular time. If your process tries to access a piece of data, it first must look at what page the data is in. Then, if that page of data is not located in physical memory, it must be read from the disk. This is a page fault.As you can see, page faults are simply a normal operation of an operating system, so they aren't inherently bad. However, they do indicate that data is being swapped between physical memory and the hard disk, so a lot of page faults can cause performance problems. Last edited by Bob Davis; June 26th, 2003 at 03:59 PM. |
|
#3
|
||||
|
||||
|
Thanks Bob.
I guess I was more asking what are these performance penalties. I see them refered to and I refer to them myself, but I have never seem them quantified. I am sure it is OS and platform dependent.
__________________
Wakeup in the morning and kick the day in the teeth!! Or something like that. "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do." |
|
#4
|
||||
|
||||
|
You can examine page fault operations by running
diskperf - (diskperf -y) - and using performance monitor. It'll tell you, with a bit of math, if the fault was satisfied by disk or by memory - you can determine if its a bottle neck or not.
__________________
Its coming up on National Novel Writing Month! |
|
#5
|
||||
|
||||
|
Thanks MDMD.
Oh No MATH ![]()
__________________
Wakeup in the morning and kick the day in the teeth!! Or something like that. "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do." Last edited by souldog; June 26th, 2003 at 06:47 PM. |
|
#6
|
||||
|
||||
|
come on, everybody likes a good equation
I would be interested to hear it.
|
|
#7
|
||||
|
||||
|
Alright. But its complicated, complex, and unbelievably difficult and
advanced. Code:
A - B = C ![]() [edit] Chapter 12 - Detecting Memory Bottlenecks in the NT resource kit is a good reference for measuring this stuff. [/edit]
__________________
Its coming up on National Novel Writing Month! Last edited by mdmd; June 26th, 2003 at 08:29 PM. |
|
#8
|
||||
|
||||
|
So if disk reads/second is zero (or small relative to faults/second)then the page then it did not need to go to the disk.
Thanks alot. I do not have a problem
__________________
Wakeup in the morning and kick the day in the teeth!! Or something like that. "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do." |
|
#9
|
||||
|
||||
|
Right, there's no problem now. But if you're going to distribute the
app on other machines it might have a problem. Try it on a sqlserver machine and set sqlserver's working memory set to 1/2 the available ram and see where your page faults go. Or write a second app that does a VirtualLock() on half the available ram, then run your app at the same time. If you're doing 80 page faults per second and they all start going to disk then you might surpass the # reads per second that a disk drive can perform and you'll have a bottleneck. The number in the chapter I listed above suggested it was 40 reads/sec. Probably never happen, but you can reduce it by maybe providing you're own allocators for the stl stuff you're using and use memory from a memory pool of a good size and VirtualLock() it for the time you need. Maybe look into SetProcessWorkingSetSize() And thats pretty much all I can say about this There is mostlikely a good Richter article in the msdn or online that would give a good page fault discussion and how to reduce them if needed.
__________________
Its coming up on National Novel Writing Month! |
|
#10
|
||||
|
||||
|
thanks mdmd. I am not going to distribute this software. I provide the computer as well, but that doesn't mean I am not going to address the problem. What book is that chapter from?
__________________
Wakeup in the morning and kick the day in the teeth!! Or something like that. "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do." |
|
#11
|
||||
|
||||
|
the NT resource kit. I use the apr2000 msdn. I couldn't find it
in the online version but I didn't really look too hard - just searched for the title.
__________________
Its coming up on National Novel Writing Month! |
|
#12
|
||||
|
||||
|
Quote:
of the msdn - where I got the above quote. So maybe the issue is normal considering you have 8 threads, and won't ever be an issue. Don't really know. I am curious if there is a way to stop them anyways. [EDIT] Maybe not, TLB I don't think would cause page fault [/EDIT]
__________________
Its coming up on National Novel Writing Month! Last edited by mdmd; June 27th, 2003 at 01:49 AM. |
|
#13
|
||||
|
||||
|
If you really want to understand then put on your glasses,contacts, or beer goggles and start reading all the articles on the virtual-memory manager in Windows NT (the core)....and then start thinking about VirtualAlloc.
You'll enjoy the literature, and be better able to decide the course, and what a page fault really entails. Not for the faint of heart, or anyone with ADD... ![]() Slmming page faults, when your system is getting slammed itself (and not by you of course) can actually improve your performance as your working set size isn't reduced (obvious) but that's a worse case scenario. My .02 cents... |
|
#14
|
||||
|
||||
|
If you can, use small static buffers. In one application I was writing, the basic algorithm needed an N^2 matrix of integers where N could be anything up to 1 million. It worked fine with VirtualAlloc, however page faults (and of course memory consumption) were a problem. I changed the algorithm so that it operates only locally on a submatrix at a time, so allocated only an M^2 matrix (where M is something like 500 and fixed, regardless of N). No page faults anymore and even with the extra processing required it was running about 5 times faster.
Then again, as others have said, page faults may come from having a lot of threads and you may not be able to change that. If you avoid allocating dynamic memory regularly in threads (i.e. avoid stuff like std::set, map, list, string, however std::vector is fine) then you can at least minimize the probability of page faults.
__________________
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily. Supports C++ and VB out of the box, but can be configured for other languages. |
|
#15
|
||||
|
||||
|
Thanks Mick and Yves. Well this is a big thing to really understand. I have started reading the intel architecture manuals and by golly I am going to get it.
__________________
Wakeup in the morning and kick the day in the teeth!! Or something like that. "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do." |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|