Windows 7 Startup Exploration

I did some digging to figure out if one can setup cold-startup testing in Windows 7 without nasty hacks. My conclusion is: sorta-kinda.

The Good – Most of the Ingredients Are Present

I haven’t actively used Windows since pre-XP days. It looks like it has come a long way since then: there is now a decent interactive shell, all kinds of settings/services can be controlled from the commandline and there is even sudo-like functionality.

PowerShell takes inspiration from the korn shell and throws in .net which allows for much nicer “shell programming” than the dominant bash shell.

mountvol is a terrible equivalent to mount in linux – but it exists, so I’m happy.

NTFS junctions are frustrating equivalents to links in a unix filesystem.

The Bad

The essential ability to completely flush filesystem caches isn’t there. This isn’t quite as embarrassing as it seems as Mac OS X’s purge command does not flush the page cache (resulting in mmapped files not purged from cache), so technically OS X has the same limitation and only Linux gets it right.

The Ugly Workaround

After much brainstorming we figured out that we can clear all relevant caches on Mac OS X by putting files that we care about on a separate partition and mounting/unmounting it for every measurement.

Ridiculously, Windows is “smarter” than that and appears to cache stuff per-drive, such that mounting/unmounting a partition has no effect on the cache. The best workaround I could come up with involves putting the said partition onto a USB disk and unplugging it in-between unmount/mount testing cycle.

Windows 7 Startup Recipe

1) Set up junctions for the 2 profile directories to point to the USB partition, unzip firefox onto that partition.

2)
$old = (get-location)
$mountpoint = $env:userprofile + "\cold"
# magic name given by running mountvol
$drive = "\\?\Volume{885d5bc3-e918-11de-a4e5-002268e3077c}\"
# Based on http://poshcode.org/696 + fiddling with UAC settings to avoid prompts
sudo mountvol $mountpoint $drive
# Mountvol doesn't seem to block until drive is mounted
sleep 1
#mountvol
cd $mountpoint\firefox
echo (pwd)
# The following command shows PowerShell awesomeness
# based on Vlad's approach
./firefox.exe -no-remote "file://$(pwd)\startup.html#$([Int64](([DateTime]::utcnow - (new-object DateTime 1970,1,1)).ticks/10000))"
cd $old
# I haven't yet figured out how to wait on firefox.exe to finish
sleep 10
sudo mountvol $mountpoint /d

3) Unplug USB drive

7 comments

  1. You can try cygwin for any linux tools you miss, not sure about tools dealing with filesystem caches but you can try…

    I can’t find any info on flushing the filesystem cache unfortunately. :(

  2. Siddharth Agarwal

    FWIW, symlinks on Windows are mostly equivalent to those on Unix, except only admins can create them (by default).

  3. You can most likely plug in and unplug a usb drive by disabling/enabling it in device manager.
    This tool should help with that: http://support.microsoft.com/kb/311272

    Hopefully that helps.

    By the way, given W7′s Superfetch, is “cold start” actually a realistic scenario at all?

  4. While junctions for the 2 profile directories to point to the USB partition ? Why don’t you set IsRelative to 0 and use an absolute path inside profiles.ini ?

  5. jmdesp, that seems like a reasonable suggestion. Unfortunately, junctions don’t bother me nearly as much as manually yanking USB.

  6. Fraser MacIntosh

    If you want to manually flush the cache on Windows systems, download the sync command from MS’ sysinternals web site. It works just like UNIX/Linux.

  7. > If you want to manually flush the cache on Windows systems, download the sync command from MS’ sysinternals web site. It works just like UNIX/Linux.

    Cache flushing talked in the article is about page cache (libraries, data etc read into memory on previous runs), not about flushing dirty pages to disk that “sync” does.