Prefetcher

From Wikipedia, the free encyclopedia - View original article

 
Jump to: navigation, search

The Prefetch is a component of Microsoft Windows which was introduced in Windows XP.[1] It is a component of the Memory Manager that can speed up the Windows boot process and shorten the amount of time it takes to start up programs by minimising disk head movements. This feature is covered by US patent 6,633,968.[2] A full explanation can be found at the Microsoft web site, MSDN Windows XP: Kernel Improvements Create a More Robust, Powerful, and Scalable OS page[3]

Since Windows Vista, the Prefetcher has been extended by SuperFetch and ReadyBoost. SuperFetch attempts to accelerate application launch times by monitoring and adapting to application usage patterns over periods of time, and caching the majority of the files and data needed by them into memory in advance so that they can be accessed very quickly when needed. ReadyBoost (when enabled) uses external memory like a USB flash drive to extend the system cache beyond the amount of RAM installed in the computer. ReadyBoost also has a component called ReadyBoot that replaces the Prefetcher for the boot process if the system has 700 MB or more RAM.[4]

Overview[edit]

When a Windows system boots, components of many files need to be read into memory and processed. Often different parts of the same file (eg Registry hives) are loaded at different times. As a result, a significant amount of time is spent 'jumping' from file to file and back again multiple times, even though a single access would be more efficient. The prefetcher works by watching what data is accessed during the boot process (including data read from the NTFS Master File Table), and recording a trace file of this activity. The boot prefetcher will continue to watch for such activity until 30 seconds after the user's shell has started, or until 60 seconds after all services have finished initializing, or until 120 seconds after the system has booted, whichever elapses first.

Future boots can then use the information recorded in this trace file to load code and data in a more efficient fashion (i.e. by re-ordering disk reads to minimise or eliminate the need to access the same file multiple times thus minimising disk head movements).

Application prefetching works in a similar fashion, but is instead localized to a single application's startup. Only the first 10 seconds of activity are monitored.[1]:458

The prefetcher stores its trace files in the "Prefetch" folder inside the Windows folder (typically C:\Windows\Prefetch). The name of the boot trace file is always NTOSBOOT-B00DFAAD.PF, and application trace files are a concatenation of the application's executable name, a hyphen, a hexadecimal representation of the hash of the path the file resides in, and a ".pf" extension. Applications that host other components (i.e. Microsoft Management Console or Dllhost) have the name of the loaded component included in the computed hash as well; this results in different trace files being created for each component.

Note that the Task Scheduler is the process responsible for parsing the trace data collected by the prefetcher and writing files to the prefetcher directory. As a result, the prefetcher will not operate correctly if the Task Scheduler service (regarded by many as a security risk) is not started.

To further improve access times, the Task Scheduler calls Windows Disk Defragmenter every three days. When the machine is idle, the lists of files and directories that were referenced during the boot process and application startups is processed.[1]:461–462 The processed result is stored in Layout.ini in the Prefetch directory, and is subsequently passed to the Disk Defragmenter, instructing it to re-order those files into sequential positions on the physical hard drive.

This will further improve performance by minimising the distance that the hard drive's heads have to be moved from one file to the next.

It is possible to trigger this re-ordering (by running "Defrag.exe %systemdrive% -b" from the command line) without running a full defragmentation.[citation needed]

Configuration[edit]

The Prefetcher's configuration is stored in the Windows Registry at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters. The EnablePrefetcher value can set to be one of the following:[5]

The recommended value is 3.[5]

Incorrect tweaking of the prefetcher[edit]

The default prefetcher setting is to optimise the speed of boot time and application loading times. Values higher than 3 do not increase performance.[5] Changing the value to 2 will not make Windows boot faster[5] (note that 2 is the default value on Windows 2003).[6]

Often found on the Internet[7] is the "/prefetch:1" application tweak,[8] which is a valid but nonetheless generally ineffective switch.[9] A second myth is that the user should delete the prefetch folder contents to speed up the computer. If this is done, Windows will need to re-create all the prefetch files again, thereby slowing down Windows during boot and program starts until the prefetch files are created—unless the prefetcher is disabled.[10][11]

Windows maintains prefetch files in the Prefetch folder for up to the 128 most recently launched programs.[12]

SSD use[edit]

The one exception to the above 'rule' is for those using Solid State Disks (SSDs).

It is hard to see how the prefetcher's lists could have any effect on systems booting from SSD drives (there being no head movement time to save) - indeed it's quite possible that boot times will be faster without pre-fetching (since the boot sequence may end up waiting whilst the SSD delivers 'future' data before it is able to access 'current' data). Those using SSDs will likely have disabled the Disk Defragmenter anyway, since all it does is 'wear out' the SSDs memory cells faster.

SSD user should thus set the EnablePrefetcher registry key value to '0' = disabled.

Microsoft say "The following instructions are for computers that have a single SSD disk, on which both the Windows system and programs and data are stored [13]."

See also[edit]

References[edit]

  1. ^ a b c Russinovich, Mark; David Solomon (2005). "Memory Management". Microsoft Windows Internals (4th edition ed.). Microsoft Press. pp. 458–462. ISBN 0-7356-1917-4. 
  2. ^ US patent 6,633,968
  3. ^ [1]
  4. ^ Inside the Windows Vista kernel
  5. ^ a b c d e http://home.comcast.net/~SupportCD/XPMyths.html#Optimization
  6. ^ http://www.microsoft.com/whdc/archive/XP_kernel.mspx
  7. ^ "Misinformation and the The Prefetch Flag". Funny, It Worked Last Time. MSDN Blogs. 25 May 2005. Retrieved 2008-12-09. "[...] this has appeared on so many, many, many sites to be urban legend." 
  8. ^ "Misinformation and the The Prefetch Flag". Funny, It Worked Last Time. MSDN Blogs. 25 May 2005. Retrieved 2008-12-09. "Secondly, one can specify a /prefetch:#flag when launching an app. [...] Some sites have guessed that this switch turns on prefetching, and suggest that you add that to every executable you care about [...]" 
  9. ^ "Misinformation and the The Prefetch Flag". Funny, It Worked Last Time. MSDN Blogs. 25 May 2005. Retrieved 2008-12-09. "Both guesses are incorrect. The /prefetch:# flag is looked at by the OS when we create the process -- however, it has one (and only one) purpose. We add the passed number to the hash. Why? [~snip~]" 
  10. ^ "Beware of Bogus XP Advice". 
  11. ^ "Windows XP: Kernel Improvements Create a More Robust, Powerful, and Scalable OS". 
  12. ^ "Misinformation and the The Prefetch Flag". Funny, It Worked Last Time. MSDN Blogs. 25 May 2005. Retrieved 2008-12-09. "For one thing, XP will just re-create that data anyways; secondly, it trims the files anyways if there's ever more than 128 of them so that it doesn't needlessly consume space." 
  13. ^ http://support.microsoft.com/kb/2727880/en-us

External links[edit]