Reducing runtime memory in Windows 8

Discussion in 'Windows 8 News' started by Building Windows 8, Oct 7, 2011.

  1. Building Windows 8

    Building Windows 8

    Oct 6, 2011
    Likes Received:

    Fundamentals such as memory usage represent a key engineering tenet of Windows 8. In building Windows 8 we set out to significantly reduce the overall runtime memory requirements of the core system. This is always good for everyone and especially in a world where people want to run more and more apps at the same time or run on systems with only 1 or 2GB of memory. The laptop we talk about in this post is the exact same one we talked about at the Windows 7 PDC in 2008 – an off-the-shelf, first-generation, ATOM-based netbook with 1GB of memory. This post details our efforts around memory footprint and was authored by Bill Karagounis, the group program manager of our Performance team. --Steven
    The runtime memory usage of Windows 8 is an important factor in determining the Windows 8 system requirements, as well as the broadened spectrum of devices that will host Windows 8. As you know, we’re delivering the complete Windows 8 experience on SoC-based devices characterized by low power consumption. This makes it even more important to leave lots of memory available for multiple concurrent apps and to sustain the overall responsiveness of devices.
    Something that might not be obvious is that minimizing memory usage on low-power platforms can prolong battery life. Huh? In any PC, RAM is constantly consuming power. If an OS uses a lot of memory, it can force device manufacturers to include more physical RAM. The more RAM you have on board, the more power it uses, the less battery life you get. Having additional RAM on a tablet device can, in some instances, shave days off the amount of time the tablet can sit on your coffee table looking off but staying fresh and up to date.
    Memory usage goals

    Our goal with Windows 8 from the beginning was to ship with the same system requirements as Windows 7. We know if we do even better that there are more resources for apps, even if we keep the published requirements the same. It is fun to think about what the "low end" hardware looked like in 2009 and how you can't even find things like 256MB memory modules anymore. We wanted to ensure that people running on Windows 7-era hardware would have the option to easily upgrade their existing machines to Windows 8 and take advantage of the functionality it has to offer. We also expect that many machines that predate the Windows 7 release will run Windows 8 based on the experiences we’ve had with older machines we intentionally keep in our performance test infrastructure.
    An important task for Windows 8 was to make room for new functionality while looking for opportunities to reduce the memory consumed by existing functionality and consumed across the board. Windows 8 is tracking well towards meeting the goal we set ourselves.
    Task Manager memory use comparison

    The easiest way to make a ballpark comparison of Windows 8 vs. Windows 7 memory use is to install both operating systems on a 1GB RAM machine (minimum OS RAM requirement) and compare them when they’ve been rebooted multiple times, and then idled for a while.
    The Windows Task Manager contains the main view of system memory through its “In Use” statistic (described in detail in this doc). The below graphics compare memory consumption on Steven’s 3+ year old netbook that he was using at the //build/ keynote recently, running Windows 7 at idle, and then with the same machine running Windows 8.
    [​IMG]Figure 1 – Memory usage in Windows 7 SP1
    [​IMG]Figure 2 – Memory usage in Windows 8
    The specific hardware making up a machine, memory use of drivers, and even uptime can cause variability, so memory results will be different on different machines (or even the same machine at different times). As you can see though, Windows 8 is doing well relative to Windows 7.
    For a bit of extra fun on a test machine, go to device manager and disable your display adapter (unload the graphics driver). You’d never run your machine this way but this does give you an even closer approximation of the memory use of Windows itself. With a disabled graphics driver, the machine above gets under 200MB after idling for a while.
    NOTE: For Windows 8, a clean install also contains the extended Windows Defender technology, which, for the first time incorporates complete antimalware functionality – also optimized for memory and resource use per Jason’s blog about protecting you from malware. (This functionality does not exist on a clean install of Windows 7 where we would recommend that you add security software).
    Making room in Windows 8

    We made hundreds of specific changes to minimize OS memory use in Windows 8. I’m going to call out a few specific areas that resulted in substantial memory savings.
    Memory combining

    When assessing the contents of RAM in a typical running PC, many parts of memory have the same content. The redundant copies of data across system RAM present an opportunity to reduce the memory footprint even for services and OS components.
    How can this happen? Applications will sometimes allocate memory for future use and will initialize it all to the same value. The application may never actually use the memory as it may be there in anticipation of functionality that is the user never invokes. If multiple running applications are doing this at the same time, redundant copies of memory are in the system.
    Memory combining is a technique in which Windows efficiently assesses the content of system RAM during normal activity and locates duplicate content across all system memory. Windows will then free up duplicates and keep a single copy. If the application tries to write to the memory in future, Windows will give it a private copy. All of this happens under the covers in the memory manager, with no impact on applications. This approach can liberate 10s to 100s of MBs of memory (depending on how many applications are running concurrently).
    Service changes and reductions

    OS services configured to run all the time are a significant source of ambient memory use. When assessing the set of OS services during Windows 8 planning, we decided to remove a number of them (13), move a different set of services to “manual” start, and also made some of the “always running” services move to a “start on demand” model. This is where a “trigger” in the OS (like device arrival or the availability of a network address) causes the following to occur:
    1. The service starts.
    2. The service does its thing (whatever that happens to be).
    3. It hangs around for a while to make sure there isn’t anything else to do, and
    4. The service goes away.
    You’ll notice that Plug and Play, Windows Update, and the the user mode driver framework service are all trigger-started in Windows 8, in contrast to Windows 7, where these services were always running.
    Of course we have added a ton of new functionality (and new code) to Windows 8. Some of this new functionality is packaged in the form of new services. Of these new services, two are auto-started; all others are manual or trigger-started.
    Doing the same job with less memory

    As Windows executes applications and performs its own system housekeeping, program files and data are loaded off the disk into main memory. During Windows 7 and Windows 8 development to date, we’ve analyzed the pieces (pages) of memory during normal execution and how often they were referenced. The idea here is that if you’re going to pay the price for allocating a piece of memory, you’d better be using it (referencing it) often. If you’re not referencing that memory often but need it, consolidate it with something else.
    Shortly after we shipped Windows 7, we applied a similar technique to several of the low level components of Windows dating back to the early days of NT (early 1990s). The work included re-architecture of code and changing data structures to completely separate “hot” parts of memory (frequently referenced) from “cold” parts. By densely consolidating the hot items, we brought down the overall runtime memory cost.
    Given the nature of the changes (low-level OS), we wanted to get the work done as early as possible in the schedule to get ample runtime on the changes. To date, these changes have been in place on Windows 8 for almost 2 years with thousands of Microsoft employees using the product to get their daily jobs done. And we’ve seen consistent results showing memory usage reduced by tens of MB on an average machine.
    Lazy initialization of the “desktop”

    Back in June, you saw Steven and Julie introduce the Metro style UI for the first time. We expect many people using tablets to spend a lot of time in that environment, typically using Metro style apps. As part of that demonstration, we also showed that for Windows 8, you can also bring forward your existing applications and use them in the very familiar desktop environment.
    From a memory perspective, we’ve taken advantage of the fact that there will be some set of devices on which users will stay in the immersive, Metro style UI almost all the time. In this instance, Windows 8 will only initialize OS components unique to the desktop environment when necessary. This is another source of memory savings, approximately 23MB right now. (Note that Task Manager runs in the desktop, so the memory numbers shown above include its cost).
    More granular prioritization of memory

    Windows 8 has a better scheme for the prioritization of memory allocations made by applications and system components. This means that Windows can make better decisions about what memory to keep around and what memory to remove sooner.
    For example, antivirus programs (AV) do various checks on files when they are being opened by other programs. The memory that the AV program allocates to check virus signatures is usually a one-time allocation (it is unlikely that specific memory will be needed again). On Windows 7, the memory is treated as if it had the same priority in the system as other memory (say, memory allocated by a running instance of Microsoft Excel). If memory became scarce, Windows 7 could end up removing the memory that helps another running application (like Excel) stay responsive for the user, which wouldn’t be the best choice for system responsiveness in this case.
    In Windows 8, any program has the ability to allocate memory as “low priority.” This is an important signal to Windows that if there is memory pressure, Windows can remove this low priority memory to make space, and it doesn’t affect other memory required to sustain the responsiveness of the system.
    To wrap up, I’ve called out our philosophy and approach to reducing memory usage in Windows 8. You’ve seen some sample results and I’ve just scratched the surface on some of the engineering work done to date in this area. One thing I haven’t discussed at all is the Windows 8 application model, and process lifecycle changes made to make new Windows 8 apps more “memory friendly.” Look out for this in the //build/ content and in future blog posts, as it’s also a really important part of the story of reimagining Windows.
    We’ve already come a long way but we’re not done.
    --Bill Karagounis[​IMG]

    Continue reading...
    Building Windows 8, Oct 7, 2011
    1. Advertisements

  2. Building Windows 8


    Sep 19, 2011
    Likes Received:
    Very interesting.
    rowal5555, Oct 8, 2011
    1. Advertisements

  3. Building Windows 8


    Jul 20, 2010
    Likes Received:
    Upstate NY
    Yes, very.
    yodap, Oct 8, 2011
  4. Building Windows 8

    Kougar Moderator

    Sep 16, 2011
    Likes Received:
    This has been needed for so long... I can't even count the number of people I know that Windows has trained to stop running services. There's hundreds of services, and its an extremely annoying process to try and stop just the unused ones.
    Kougar, Oct 9, 2011
  5. Building Windows 8

    Ian Administrator

    Jan 26, 2010
    Likes Received:
    A very welcome move, especially as it's such a little tweak but could provide a decent saving - especially for all of the 3rd party services that accumulate :).
    Ian, Oct 9, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.