Delivering fast boot times in Windows 8

When it comes to talking about "fundamentals" we want to start with boot time – no feature gets talked about and measured more. We designed Windows 8 so that you shouldn't have to boot all that often (and we are always going to work on reducing the number of required restarts due to patching running code). But when you do boot we want it to be as fast as possible. This is a very deep topic and we have a lot of folks focused on it. We made a bigger leap in this area with Windows 8 than we have in a long time due in no small part to cooperation across the whole ecosystem. Gabe Aul, a director of program management in Windows, authored this post (a first in what will be a series of posts on fundamentals).
--Steven

Few operations in Windows are as scrutinized, measured, and picked apart as boot. This is understandable—boot times represent an effective proxy for overall system performance and we all know the boot experience is an incredibly important thing for us to get right for customers. Data shows that 57% of desktop PC users and 45% of laptop users shut down their machines rather than putting them to sleep. Overall, half of all of users shut down their machines rather than putting them to sleep.

Pie chart of Windows 7 laptop power transtions, showing Sleep at 45%, Hibernate at 11%, and Shutdown (including Restart) at 45%
Pie chart of Windows 7 desktop power transtions, showing Sleep at 42%, Hibernate at 1%, and Shutdown (including Restart) at 57%

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:

  1. 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().
  2. 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.
  3. Windows closes the user sessions for each logged on user.
  4. 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.
  5. Windows broadcasts messages to devices, signaling them to shut down.
  6. Windows closes the system session (also known as “session 0”).
  7. Windows flushes any pending data to the system drive to ensure it is saved completely.
  8. Windows sends a signal via the ACPI interface to the system to power down the PC.

And boot entails:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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: https://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.
Sample of test results from System Integration Test lab systems.
Click to see a bigger version of this chart.

It’s faster because resuming the hibernated system session is comparatively less work than doing a full system initialization, but it’s also faster because we added a new multi-phase resume capability, which is able to use all of the cores in a multi-core system in parallel, to split the work of reading from the hiberfile and decompressing the contents. For those of you who prefer hibernating, this also results in faster resumes from hibernate as well.

A bar chart showing the relative time needed for different phases of startup. For Windows 7 Cold Boot, POST/pre-boot takes about 1/3 of the time, system initialization takes over half the time, and user session initialization takes about 1/5 of the time. For Windows 8 fast startup, POST / pre-boot is about 1/3, and then Hiberfile read and user session init each use about 1/4 of the time, and Driver init comprises a slightly smaller portion than Hiberfile and user session init.
Representation of different phases between cold boot and fast startup.
Click to see a bigger version of this chart.

It’s probably worth mentioning quickly how we treat the hiberfile—if you read this and immediately went and did a dir /s /ah hiberfile.sys  you would have found that it’s a pretty big file on disk. The hiberfile is sized by default at 75% of physical RAM. The file is essentially a reservation for hibernation data that will be written out as the system is dropping into hibernation. Typically much less space is actually used, and in the case of our fast startup usage, it’s typically ~10-15% of physical RAM but varies based on drivers, services, and other factors. The system also treats the hiberfile slightly differently than other files on disk, for example, the Volume Snapshot service ignores it (a small performance benefit.) You can disable hibernation and reclaim this space by running  powercfg /hibernate off from an elevated command prompt. But be aware that if you do this, it will disable hibernation completely, including some nice capabilities like fast startup as well as hybrid sleep, which allows desktop systems to do both a sleep and hibernate simultaneously so if a power loss occurs you can still resume from the hibernated state. You can also run powercfg /hibernate /size and specify a value between 0 and 100 for the percentage of physical RAM to reserve for the hiberfile – but be careful! Specifying too small a size can cause hibernation to fail. In general, I recommend leaving it enabled at the default value unless you’re working on a system with extremely limited disk space.

Another important thing to note about Windows 8’s fast startup mode is that, while we don’t do a full “Plug & Play” enumeration of all drivers, we still do initialize drivers in this mode. Those of you who like to cold boot in order to “freshen up” drivers and devices will be glad to know that is still effective in this new mode, even if not an identical process to a cold boot.

This new fast startup mode will yield benefits on almost all systems, whether they have a spinning HDD or a solid state drive (SSD), but for newer systems with fast SSDs it is downright amazing. Check out the video below to see for yourself:

Your browser doesn't support HTML5 video.

Download this video to view it in your favorite media player:
High quality MP4 | Lower quality MP4

One thing you’ll notice in the video was how fast the POST handoff to Windows occurred. Systems that are built using Unified Extensible Firmware Interface (UEFI) are more likely to achieve very fast pre-boot times when compared to those with traditional BIOS. This isn’t because UEFI is inherently faster, but because UEFI writers starting from scratch are more able to optimize their implementation rather than building upon a BIOS implementation that may be many years old. The good news is that most system and motherboard manufacturers have begun to implement UEFI, so these kinds of fast startup times will be more prevalent for new systems.

Of course, there are times where you may want to perform a complete shutdown – for example, if you’re opening the system to add or change some hardware. We have an option in the UI to revert back to the Windows 7 shutdown/cold boot behavior, or since that’s likely a fairly infrequent thing, you can use the new /full switch on shutdown.exe. From a cmd prompt, run: shutdown /s /full / t 0  to invoke an immediate full shutdown. Also, choosing Restart from the UI will do a full shutdown, followed by a cold boot.

Boot work is mostly owned by our Kernel Platform Group, but a number of teams came together in Windows 8 to make changes across the OS to support this new mode, plus other exciting boot changes that we’ll talk about very soon. We’re really enjoying the boot performance of Windows 8 in our internal use, and are looking forward to you being able to try it for yourselves so you can let us know what you think.

Gabe Aul