Why does Explorer generate a page fault every two seconds?
If you fire up Task Manager and look at the page fault count, you’ll see that even when nothing is going on, Explorer takes a page fault every two seconds. Isn’t this bad? I though you weren’t supposed to poll.
Here’s an interesting experiment: Change your update speed to High. Wow, the page fault rate quadruples to a page fault every half second. At this point, you should start suspecting some sort of Heisenbehavior, that is, that the behavior of the system is changing due to your act of observing it.
The page faults are coming from the CPU meter in the notification area. At each update, Task Manager sets a new icon into the notification area, and Explorer resizes it from the default icon size (which is the size of the icon that Task Manager hands it) to the notification icon size. To obtain the best quality image, the taskbar uses the
LR_COPYFROMRESOURCE flag. This means that the window manager goes back to
taskmgr.exe to locate the best match, which in turn triggers a soft page fault. It’s a soft page fault since the information is already in the cache (after all, we access it every two seconds!), so no actual disk access occurs. But it still shows up as a page fault, and that makes some people nervous.
What could Task Manager do to avoid triggering this false alarm and freaking people out? Well, when it calls
Shell_NotifyIcon, it could pass icons that were loaded at the size
GetSystemMetrics(SM_CYSMICON). That way, when the notification area makes a copy of the icon, it won’t need to be resized since it’s already at the correct size.
Now, there’s really nothing wrong with the soft page faults aside from all the time the shell team has to spend explaining to people that nothing is actually wrong. Next time, we’ll look at the wrong way of avoiding the soft page faults. Even though it’s the wrong way, the exercise is still instructive.
[Raymond is currently away; this message was pre-recorded.]