All the tips/hints/fixes/other information posted here are at your own risk. Some of the steps here could result in damage to your computer. For example, using a Windows registry editor like RegEdit could result in unintended serious changes that may be difficult or impossible to reverse. Backups are always encouraged.

04 September 2007

Smart Defragging by Layout.ini for Free

By default, Windows XP tracks what files load during boot and application launches, and it uses that information to prefetch files into RAM. Additionally, the prefetch data are parsed into a file, %WINDIR%\Prefetch\layout.ini, which is used by XP's built-in Disk Defragmenter to optimize the layout of those files on the hard drive for faster access. Also, by default, a limited defrag operation takes place in the background during idle every three days just for the files specified in layout.ini. You might get a bigger performance benefit, however, but running by defragging by layout.ini more often. The command to do this layout.ini defrag is defrag c: -b. The "-b" switch is almost undocumented, and might have originally meant "boot", but it relocates boot and application launch files contiguously and nearer to the beginning of the hard drive for faster access. Since it moves only hundreds of files instead of tens of thousands, it's much faster than a normal disk defragmentation. If you want, you can make a Scheduled Task to run defrag c: -b however often you like (I have Scheduled Task to run this quick defrag every day during idle). If you want to additionally disable the 3-day operation, uncheck "Optimize hard drive when idle" in Tweak UI (or set EnableAutoLayout to 0 in the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OptimalLayout ).

You will still need to defragment the hard drive from time to time. It is most effective to do so before the desktop loads. The utility ScanDefrag is very useful in that regard. A normal defragmentation with Disk Defragmenter includes optimizations guided by layout.ini.

Some otherwise really excellent defrag utilities will actually undo the defrag by layout.ini. (Windows XP Disk Defragmenter respects layout.ini.) For normal desktop/workstation use, the Windows defragmenter is best IMHO.

NB: For this tip to work, you need the default registry entries below:

Key Name: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg\BootOptimizeFunction
Name: Enable
Type: REG_SZ
Value: Y
I believe this enables Disk Defragmenter to respect layout.ini.

Key Name: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters
Name: EnablePrefetcher
Value: 3
0 = Prefetching Disabled; 1 = Application Prefetching Only; 2 = Boot Prefetching Only; 3 = Both Boot & Application Prefetching Enabled

PS Running Rundll32.exe advapi32.dll,ProcessIdleTasks will rebuild Layout.ini from the prefetch data and then (if EnableAutoLayout is set to 1) optimize layout on the disk from the refreshed layout.ini. The command also launches other tasks that happen during idle, such as System Restore.

No comments:

Post a Comment