11/08/2012
Delivering fast boot times in Windows 8 (PART II)
Qualitatively, people say they prefer to shut down because they want to have their PC completely âoffâ so that it uses no power â either to preserve battery life or to reduce their energy use. Hibernate is also a good option for this since it similarly has no power draw, and many people really like it. However, itâs clearly not for everyone, since one of the other things weâve heard is that many people want to turn their PCs on and have it be a âfresh startâ rather than running all of the stuff from their previous session. Sleep/resume is the best option for fast on/off transitions on todayâs PCs, but it still consumes some power in order to preserve the contents of RAM, which means battery drain â even if itâs only a little bit on a well optimized system. All of this is happening with the backdrop of how we all use our mobile phones today, which is almost never restarting them, and always using what feels closest to a sleep-like state.
Our challenge then, was to design a way to meet all of these desires on todayâs PCs without requiring some special new hardware. These were our goals:
Effectively zero watt power draw when off
A fresh session after boot
Very fast times between pressing the power button and being able to use the PC.
In Windows 7 we made many improvements to the boot path, including parallel initialization of device drivers, and trigger-start services, but it was clear weâd have to get even more creative (and less incremental) if we hoped to get boot performance anywhere close to fast enough to meet all of these needs.
Our solution is a new fast startup mode which is a hybrid of traditional cold boot and resuming from hibernate.
Before I go into exactly how it works though, a little background is probably helpful on how shutdown and boot works today in Windows 7.
Shutdown entails:
The user initiates a shutdown by selecting âshut downâ from the Start menu, or by pressing the power button; or an application initiates shutdown by calling an API such as ExitWindowsEx() or InitiateShutdown().
Windows broadcasts messages to running applications, giving them a chance to save data and settings. Applications can also request a little extra time to finish what theyâre doing.
Windows closes the user sessions for each logged on user.
Windows sends messages to services notifying them that a shutdown has begun, and subsequently shuts them down. It shuts down ordered services that have a dependency serially, and the rest in parallel. If a service doesnât respond, it is shut down forcefully.
Windows broadcasts messages to devices, signaling them to shut down.
Windows closes the system session (also known as âsession 0â).
Windows flushes any pending data to the system drive to ensure it is saved completely.
Windows sends a signal via the ACPI interface to the system to power down the PC.
And boot entails:
After pressing the power button, the PCâs firmware initiates a Power-On Self Test (POST) and loads firmware settings. This pre-boot process ends when a valid system disk is detected.
irmware reads the master boot record (MBR), and then starts Bootmgr.exe. Bootmgr.exe finds and starts the Windows loader (Winload.exe) on the Windows boot partition.
Essential drivers required to start the Windows kernel are loaded and the kernel starts to run, loading into memory the system registry hive and additional drivers that are marked as BOOT_START.
The kernel passes control to the session manager process (Smss.exe) which initializes the system session, and loads and starts the devices and drivers that are not marked BOOT_START.
Winlogon.exe starts, the user logon screen appears, the service control manager starts services, and any Group Policy scripts are run. When the user logs in, Windows creates a session for that user.
Explorer.exe starts, the system creates the desktop window manager (DWM) process, which initializes the desktop and displays it.
There are a lot more specific details here, if anyone wants to go deeper: http://msdn.microsoft.com/en-us/windows/hardware/gg463386
The key thing to remember though is that in a traditional shutdown, we close all of the user sessions, and in the kernel session we close services and devices to prepare for a complete shutdown.
Now hereâs the key difference for Windows 8: as in Windows 7, we close the user sessions, but instead of closing the kernel session, we hibernate it. Compared to a full hibernate, which includes a lot of memory pages in use by apps, session 0 hibernation data is much smaller, which takes substantially less time to write to disk. If youâre not familiar with hibernation, weâre effectively saving the system state and memory contents to a file on disk (hiberfil.sys) and then reading that back in on resume and restoring contents back to memory. Using this technique with boot gives us a significant advantage for boot times, since reading the hiberfile in and reinitializing drivers is much faster on most systems (30-70% faster on most systems weâve tested).
Bar chart comparing Windows 8 fast startup times to Windows 7 cold boot times on 30 different PC configurations. The Windows 8 startup times are all between 15 and 33 seconds, while the Windows 7 cold boot times are between 25 and 72 seconds.