Reclaiming memory from Metro style apps


Modern operating systems take a different view of the resources on the system. Regardless of the form factor, it is important for the OS to more effectively manage resource utilization than in the past. Currently, it is far too easy for a single process to consume available resources (memory, CPU, disk I/O) even when this does not improve the overall performance for end-users. The very role of an OS is to balance resources and make sure you can complete all the things that you want to do on your PC. Much of the manual control present in most OS implementations is designed to work around errant software—software that gets in a state where resource consumption is unbounded. Even if the software is not malicious, which is often the case, the ability to build well-behaved software was limited by the complexity of resource allocation APIs. The modern API set in WinRT is designed for programmers to more easily build software that gets the work done while not “taking over” your PC. This is something that makes all PC form factors and all software better.

In this post, group program manager Bill Karagounis on our Fundamentals team details the behind-the-scenes efforts to reclaim memory even when apps are suspended, and how this all happens without developers needing to worry.
–Steven


Previous blog posts have discussed the Metro style application model using Windows Runtime. An important attribute of this app model is that apps are suspended when they are no longer visible to the user. Suspending Metro style apps in the background is a good thing, as it conserves CPU for other apps and ensures that background apps don’t cause activity that can consume resources, thereby improving the battery life and increasing responsiveness. This is outlined in detail in Sharif Farag and Ben Srour’s blog post, Improving power efficiency for applications.

But what about the memory these apps are taking up when suspended? We pointed out earlier that, as a practical matter, the OS will handle this and that your other processes will not feel memory pressure because there are suspended processes. This was an important design consideration. But we know that some of you are still curious how this will all work.

Starting with the Windows 8 Consumer Preview, whenever Windows detects memory pressure on the system, it will repurpose nearly all the memory that suspended Metro style apps would otherwise hold onto. Windows 8 can reclaim this memory without having to terminate an app.


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

Memory, responsiveness, and Metro style apps

For any type of app (Metro style or desktop), Windows tries to regulate physical memory allocations on behalf of that app, regardless of the memory requests it has made. Windows has always behaved this way to keep memory available in anticipation of future app memory needs. Windows is careful to only allocate physical memory to an app when the app tries to touch it, even if the app had “allocated” it earlier. Windows will also page out or repurpose parts of memory from an app if the pages of memory haven’t been touched in a long time.

It is important to understand the goal is not to deny memory to a requesting process, but to delay allocating physical memory as long as possible (until the user actually touches the app) because as with many resources, there is a tendency for software to over-budget. The OS is the place where all these requests come together and it has the information to see that meeting all the fully budgeted requests would ultimately starve every process. Not only would work not complete, but the system will essentially lock up. This happens even if the memory is virtual—instead of running out of RAM, your PC would simply swap pages in and out of disk.

The physical memory given to a process at any point in time is referred to as the “working set” of the process. A private working set represents physical memory that is unique to a process. Processes also touch other pages of physical memory that are “shared,” which several processes can reference. When you look at the Processes view in Task Manager, the memory for a specific process is actually its current private working set. NOTE: For simplicity, when I refer to “working set” in this blog, I mean “private working set.”

When the system starts to run low on available memory, the OS will look in all processes for pages of physical memory that it can repurpose to satisfy other needs in the system, even by paging out memory when necessary. For desktop apps, Windows will try to keep the most important (frequently accessed) pages of memory in the app’s working set; this is because desktop apps expect to be able to run code at any time, even when they’re in the background. It’s a fine balance though: if too many pages of memory were to be removed from a desktop app, it could affect the app’s responsiveness due to additional disk I/O (as the app tries to touch memory that has been paged to disk under the covers).

For a deep dive on Windows memory management, see Mark Russinovich’s “Mysteries of Windows Memory Management Revealed” talks: part 1 & part 2.

Metro style apps, however, are different from desktop apps, in that they are usually suspended whenever they are no longer in the foreground. When they’re suspended, they aren’t touching ANY of their memory.

To illustrate, I’ve highlighted a few suspended Metro style apps with memory held in their working sets in the screenshot below.

Task Manager, Processes tab, showing 11 suspended apps, using from 63.3MB to 3.8MB of memory, each

Suspended apps holding on to memory

NOTE: In the Consumer Preview build, the Suspended status does not show
in the Processes view of Task Manager by default; you have to choose to show it
via an option on the View menu.

If there isn’t memory pressure in a system, it’s actually a good thing (most efficient) to just leave memory in the suspended apps’ working sets. But if there is some memory pressure, the fact that these Metro style apps are suspended presents an opportunity to get almost all the memory in these working sets back for other apps, without terminating them.

Reclaiming memory from suspended Metro style apps

In Windows 8 Consumer Preview, we can efficiently write the whole (private) working set of a suspended Metro style app to disk, in order to gain additional memory when the system detects pressure.

This process is analogous to hibernating a specific app, and then resuming it when the user switches back to the app. We’re taking advantage of the suspend/resume mechanism of Metro style apps to empty or re-populate an app’s working set.

The sequence of events is described below:

    1. The Process Lifetime Manager (PLM) detects memory pressure in the system and asks the Memory Manager (MM) to empty the working set of a specific process that houses a suspended Metro style app.

Flow diagram: Memory 1.6/2.0 GB (80%), arrow to Process Lifetime Manager (PLM), arrow to Memory Manager (MM), and three more arrows from PLM to 3 suspended Metro style apps

    1. MM moves the pages of memory from the working set of the app to the operating system’s modified page list (which is a list of memory whose contents are to be written out to disk before being reused).

Before: moving the memory pages for suspended app to Modified Page List, working set is 40.3 MB. After moving, the working set is 0.7 MB, and modified page list has new items in list.

    1. The working set pages on the modified page list are written out asynchronously, as dictated by the usual MM policies (written out opportunistically in the background, writes triggered when under memory pressure).

Modified Page List shown with arrow to disk, writing pages to disk asynchronously

    1. Even after the suspended apps working set is written to disk, the memory pages removed from a process are left intact on the operating system’s standby list. This is a cache of useful pages of memory that can be repurposed for other apps, if necessary. If these pages are immediately needed again by their original process, they are quickly moved back.

Pages shown in both Modified Page List and Standby List

If a user switches back to the app while its working set pages are still in physical memory (on the modified page list or the standby list), it’s straightforward: the pages will be added back into the app’s process immediately. If they are no longer available, Windows will read in the app’s working set from disk in an optimized manner.

“Reclaiming memory” in action

To get a feel for how this works, let’s walk through an example with real running code.

The initial state is represented by the screenshot above. I had several Metro style apps running on a PC with 2GB of RAM. The Metro style apps were in the background, and therefore Windows suspended them. I then started opening more apps to drive up memory use on the system and trigger the new functionality.

In the next screenshot, below, you’ll notice that I opened some apps in order to introduce additional memory pressure and induce the behavior described above. As you can see, Windows emptied the working sets of the suspended Metro style apps (highlighted).

Processes tab of Task Manager, with all suspended apps using less than 1 MB of memory each.

Working sets of Metro style apps emptied

Let’s compare the “before” and “after” working sets of the original Metro style apps (some of the “after” stats cannot be seen because Task Manager ran out of room to show all 27 launched apps):

Metro style app

Working set before (MB)

Working set after (MB)

Flixster

23.5

0.5

Flow

15.2

0.6

Kindle

23.1

0.5

LiveComm

3.8

0.3

Lyrics

65.3

0.9

Maps

28.1

0.8

Remote Desktop

21.0

0.5

SkyDrive

23.1

0.5

Store

26.9

0.6

Weather

42.0

0.8

Windows Reader

9.2

0.4

So in this example, we liberated over 250 MB of physical RAM for other apps to use without shutting down the suspended apps.

Responsiveness when reading the working set back in

A test for this new facility is how responsive a suspended app is after its working set contents are emptied and you decide to switch back to the app.

While I was running this test, I used the “Lyrics” app as my indicator of responsiveness. The Lyrics app can display the lyrics of a song as well as play back a music video. When the Lyrics app goes to the background, it gets suspended, which stops the playback.

After driving memory use to the point where working sets were emptied, I opened additional apps and used the system for a while to ensure that a swap back to the app was going to read the working set from disk. I then triggered the switch back to the Lyrics app (below).

Processes tab of task manager, Lyrics app is now consuming 97.4MB of memory

Lyrics app’s working set is repopulated

The key indicator I was looking for was how long it would take from the time I triggered the switch back to the app to the point where I could hear sound again. On a low-end machine, with a high memory load, it’s hard to perceive a difference in responsiveness when switching back to the app whose working set was being read from disk compared to when its working set was still in memory. Your mileage will vary though: the larger the working set, the longer it will take to read-in from disk. We’re also continuing to reduce the amount we have to write to disk for Metro style apps and further optimizing this feature.

This functionality is something that everyone with the Consumer Preview release can try for themselves. Just open up a number of Metro style apps and desktop apps to generate some memory pressure, and then switch back to a suspended Metro style app that has had its working set emptied.

NOTE: Windows will still close Metro style apps if memory gets into the critical range. However, this feature will enable a system to run more applications before getting to that point.

Reading in a working set optimally

To have a responsive experience when you switch back to a suspended app whose working set is on disk, we’ve optimized how we write the working set in the first place, so that reading it in is as efficient as possible.

When we write out the working set of a suspended Metro style app, the working set pages are being written out to disk sequentially. This allows us to read the data back into a process using a small number of large sequential disk reads. The screenshot below is from our Windows Performance Analyzer (WPA) tool that comes as part of the Assessment and Deployment Kit (ADK), showing a visual representation of disk reads during this process. I’ve highlighted the working set “read-in” I/O. You can clearly see the sequential stream as we repopulate an app’s working set.

Windows Performance Analyzer

Sequential read I/Os to repopulate an app’s working set (WPA Tool)

Reading back sequential data from almost any storage device is really fast. Most rotational disks can achieve between 50-100MB per second. If a storage device is flash-based (like an SSD), you can get upwards of 200MB per second for these reads.

We expect that many apps will take less than a second of I/O to get the working set of a suspended app back into memory.

Conclusion

By definition, all PCs of all form factors have limited physical memory. The challenges of managing memory do not change when you add more physical memory, so long as you are actually running more programs that request more memory.

Several classes of modern software will continue to evolve to use more and more memory – photo editing of giant RAW images, in-memory databases, very large spreadsheets, and so on. Whether these have WinRT-based implementations or desktop implementations, the OS needs to evolve to manage these ever-increasing memory requests. WinRT is an opportunity for programmers to use an API that allows access to all the memory they need while putting the user first in terms of responsiveness and getting work done. I hope you’ll try this out this feature in Windows 8 Consumer Preview.

– Bill Karagounis

Comments (84)

  1. Mike says:

    Amazing work!

  2. Andalusio says:

    Cool explanation. Already noticed the differences between Windows 7 and 8 WRT memory management. Still observing how it might effect high memory-consuming apps that get "suspended".

  3. MikeW says:

    When I'm working on the desktop ( where frankly, the Metro interface has no appeal), I'd rather not have to wade through all the Metro processes when looking at Task Manager.

  4. Ryan says:

    Nice work!

  5. Stephen says:

    @MikeW if you aren't using metro apps (because they have no appeal) then what metro apps are you wading through. Nice paradox.

  6. How does this impact background processes of Metro apps like playing a song or doing some other processing (though I'm currently under the impression that other than select set of pre-defined tasks, applications aren't allowed to do anything unless they are the active application)? Will the app just not enter a suspended state and therefore continue to act as 'normal'?

    I ask because with a slow internet connection pulling up web pages or any other web-based service takes forever, so I like switching between that a something else (like a game). It get's annoying when my email sync, IE load, weather update, and other functions keep pausing and terminating. I could see this becoming much more painful if SSL connections or large file uploads are terminated, via application suspension, to keep memory free instead of paging it out.

    Otherwise, this idea behind memory management is great work.

  7. Gigetto LoStronzo says:

    Finally there will only be four editions of Windows: Windows 8 (for consumers), Windows 8 Pro (for businesses and enthusiasts), Windows RT (pre-installed on ARM computers and tablets) and Windows 8 Enterprise (for enterprises, of course).

  8. pmbAustin says:

    PLEASE don't let nearly THREE WEEKS go by between posts again!  At least ONE post a week!  I was DYING here without an update! :-)

  9. B8Blog says:

    @ pmbAustin  — sorry.  we had a few holidays here in the US and wanted to make sure the authors of the posts were online when they went live.

  10. Arturo says:

    #pmbAustin

    Same here.

  11. hamakaze nihon says:

    And after a long time updating now. And editions and the official name is fixed. I fairly Edition configuration is nice and neat and. 7 And the same product name use code name is intact.

    What is the release date? Early release.

    But be a good OS. That reputation in the Japan was not very well….

  12. jader3rd says:

    While I do like what's being done with Metro apps, I still find Windows to be too agresive with paging out to disk. I find it annoying when Task Manager is open, showing me that 68% of RAM was in use, while hard faults are still occuring. My machine has RAM, let's use it.

  13. John Mitas says:

    I'm interested in how you protect the memory pages written to disk ?! This sounds awesome BUT also sounds like you need a strong security mechanish around it to ensure people don't forcebly intercept and alter the memory files?!

  14. There are two main reasons why people are jailbreaking/rooting their iDevices and Androids:

    -Install pirated software and/or homebrew

    -Customize the device

    Please let us customize our devices a little more than just changing two colors…

    I want my Windosw Phone to look like this:

    img37.imageshack.us/…/screenshot89562.jpg (Created using the Phone 8 WP7 App)

    Same for Windows 8 and Bing (i hate bing for not letting me use my own pic, i like some of the Bing pics, but hate most of them)

    Thanks

  15. Darien says:

    Call it what it is: paging.  Metro memory managing is just an updated swap file.  No thanks.  Not impressed.  Won't do too much for a system running Autodesk products alongside Adobe Photoshop with Word and Outlook open.

  16. "Metro style apps, however, are different from desktop apps, in that they are usually suspended whenever they are no longer in the foreground. When they’re suspended, they aren’t touching ANY of their memory."

    There must be an way for the apps to opt out of those aggressive power saving techniques.

    Until recently, I was an extremely happy Windows Phone user (I have an HTC Radar since December).

    But the fact that switching to another app, or even to the start screen, pauses the GPS tracking apps makes me seriously consider switching to Android, as it seems to support real multitasking.

    I use the "RunKeeper" and "Run The Map" apps and I hate it when the GPS tracking is interrupted and the recorded track is not continuous just because I switched to the Start Screen or Bing by accidentally pressing the start/search buttons, or because I wanted to take a peek at an email, or to quickly snap a picture.

    Not only that, but upon returning to the app I have to wait 10-20 seconds for it to regain GPS lock. This is stupid.

    Real multitasking is a must for me, on all my devices. Some apps are crippled without real multitasking support.

    The user and/or the app developer should be able to decide which apps benefit from real multitasking, without, pauses, dehydrations, evictions, hibernations, etc.

    If you still insist on denying us real multitasking support, at the very least a feature like "background GPS tracking" should be introduced. In the same way that music keeps playing while I use other apps, GPS tracking should still work while I use other apps.

  17. Alex says:

    Vlad NC – Windows Phone app developers have the option of "opting in" to multitasking, it just means your GPS tracking app didn't do that.

  18. @c_barth.

    Even when you switch away from metro style apps, they aren't suspended immediately, they can save state and can continue processing for a short while. You can actually see this happening in the video above at the 4:01 point.  I switched away from the "Finance" app to the task manager and it was a few seconds before the apps' status in TM turned to "suspended".

    Additionally, the "Improving power efficiency for applications" blog referred to at the top of the post contains a section titled "Performing Background activities" which discusses the WinRT background processing model and the system facilities provided for Metro style apps. This API is there for developers to use for background work and leverages Windows 8 to do the heavy lifting associated with doing background processing in a battery-life friendly way.

  19. huh? says:

    @Darien: I am not sure what is your point? The apps that you described are desktop apps. The memory management are for metro apps that are SUSPENDED. If the app is not suspended, then essentially you're using it. Plus, if you are running these intensive apps, then I would assume that you have tons of memory.

  20. Fula says:

    Is this also applicable on mobile platforms? If so, how do you mitigate the effects on NAND lifetime?  Do you have an in-memory reclaim mechanism that would then be flushed to disk, (something akin to compressing pages and purging to disk as they age).

  21. I'm glad you brought up this topic again. I am trying to include metro apps in my work habits. This usually results in a combination of 6-8 desktop apps (e.g. Windows Explorer, Word, EndNote, OneNote, PersonalBrain, PDF XChange Viewer, some dictionary, and Zune) and some of those metro apps: Internet Explorer, Mail, Messaging, and People.

    1) Messaging seems to have problem keeping me constantly online. I have the same problem on my Windows Phone. The app doesn’t follow the status of my network connection: it says I’m online when I’m not and doesn’t always switch when I get online. I use instant messaging a lot to communicate with my wife, and when I resort only to metro apps (on Windows 8 as well as on Windows Phone) my wife always has problem communicating with me.

    2) When I write emails, I must sometimes consult other apps, e.g. copy some text from a webpage. Today, as I was using Mail to write an email, the app has been suspended twice. Not only had I to wait for Mail to reopen (there are always a few moments of wait), but both times I came back in the wrong place: rather than being brought back in my draft, I was rerouted to the inbox, where the drafts folder doesn’t even appear. This is really disturbing.

    3) In my browser, there are usually 2-5 tabs open. Using the metro IE, I lost my tabs twice in about 2 hours because of (so it seems) this suspending process. And again, each time I want to get back to suspended IE tabs, I must wait until the app is reloaded, a process that seems to take more time when there are multiple tabs.

    4) When suspended metro apps get reloaded, I often encounter responsiveness problems: for some reason, it often lags or freezes.

    5) And to bring back an issue that really bothers me, the current metro snap ratio makes it impossible to write a text while consulting another text. Microsoft should definitely implement metro snap with a third ratio (50-50). This is rather essential.

    Question: Suppose I am watching a movie on the Web, if IE gets suspended, will it keep in memory what has already been loaded from the movie or will I have to load it all over again?

  22. Enigmaticatious says:

    @Darien,

    If this wasn't done, then your memory hogging desktop apps simply wouldn't have the additional memory freed up. Considering that Metro Apps are generally a "use one at a time" deal by their definition, it should only ever have one app to suspend or active at any given time, and considering the memory size for these is small, it shouldn't be a problem.

    99% of the time, all but one Metro App will be using physical memory, and your desktop apps will benefit from having more physical memory to play around with.

    The bottom line here guys is that you will always have a limitation on the phyiscal memory you have, and the more applications, drivers, processes, services, etc you want running at once the less of that memory is available. Either you allow each individual process to simply take what it needs and you end up constantly fighting between apps (which is your fault for opening too many things), or you need this kind of memory management. If your not happy with what it does, just put more RAM in your machine and you shouldn't see it ever getting into "memory pressure" which is the trigger for this kind of management being put into effect.

    Simple really

  23. alomgir says:

    Simply awesome

  24. DrPizza says:

    This working set reduction, is this similar to the SetProcessWorkingSetSize(<process>, -1, -1) that Windows used to do in DefWindowProc in response to SC_MINIMIZE, or is it different/more aggressive than that?

  25. dgschrei says:

    I like the idea behind this way of handling memory, but I have got one big worry with this.

    Doesn't this mean that Windows will write very large amounts of data to the disk?

    On a normal PC that has an HDD that is not that big of a deal, since HDDs are almost infinitely rewriteable.

    But with modern systems that sport a SSD this would very much be a problem since they do have a limited amount of rewrites.

    Wouldn't the system described above wear out the NAND in most tablet devices rather quickly?

  26. myWP7 says:

    The task switcher on left hand side with thumbnails is little confusing and hard to find apps, can you consider adding the app names above thumbnails.

  27. justStandardUserLikeSomeneoIphoneorIpadfan says:

    so will be anything else that is new except metro apps in this windows 8, I mean there is many features, but for basic user I don't see any news except metro apps that was represented like one year ago?

  28. Stive says:

    so will be anything else that is new except metro apps in this windows 8, I mean there is many features, but for basic user I don't see any news except metro apps that was represented like one year ago?

  29. alvatrus says:

    Suppose I'm listening to an audio-blog in IE-metro.

    How can I prevent IE to switch to the background (and turn off audio) when I'm checking the Mail app?

  30. KAL says:

    Shouldn't all suspended apps have their memory repurposed as soon as they are suspended, to save more power, other system resources, etc.?

  31. hamakaze japan says:

    Continue reading morning…. Sorry, this article and so much regardless.

    Edition's simple but ARM version of Windows that the name Twitter Nori because you feel so mistaken 『tsuito another name it wanted. I want to say it. After would be the problem. I hope is able to transfer the much better OS.

  32. @Azul Wizard

    Android devices do not need to be rooted to install software from places other than the official store because you can easily install any app you like from anywhere. You can even install alternative app stores if you want. The only limits are the sandbox security model and your own common sense.  I suspect the desire to root in Android is restricted mostly to users with end of life / unsupported devices or subsidized phones who want to rejuvenate the device.

    The picture on iOS different. Devices are tied to one store and so there is a far stronger desire to break out just to be free of what many consider a tyranny / golden cage. Of course rooting enables the user to get pirated software but it also lets them install software which has run afoul of the official policy. e.g. many Apple TV devices get broken so people can run the XBMC software which lets them play a greater range of video formats.

    I think Windows 8 devices would be smart NOT to follow the iOS model. Install an app store by default but do not restrict what software a user may install and run on their own device.

  33. Chikahiro says:

    I liked what I could understand! Thanks for posting this ^_^

  34. JSM says:

    Great and very interesting post.

    By the way,  I see an unpleasing spread of the word app  to designate anything and everything.  Wouldn't it be better to keep the word 'app'  for Metro apps  and  'application' or 'program' for desktop ?  Calling Photoshop an 'app',  feels a little bit strange.

    @hamakaze japan :  a google translate of japanese to english is really funny,  keep going  :)

  35. well there is nothing to add, it's just perfect. thx for your effort making Windows 8 amazing!!!

    —————————————————————————————————————————————————————

    i have a suggestion for the taskmanager, maybe you tell it Ryan Haveson

    img801.imageshack.us/…/taskmanagers.png

    —————————————————————————————————————————————————————

    also there is a dificulty to take fullscreen screenshots (with the snipping tool) on the desktop, when a Metro app is open, because the taskswitcher on the right appears.

    imageshack.us/…/snapswitch.jpg

    thx for your afford

  36. oops typing mistake, effort not afford

  37. Sid says:

    The consumer preview is sooooooooo good, it renders the glass effect on my desktop running on P4 and 1GB ram. XP almost killed it and Windows 7 is OK (I thought XP was OK and Windows 7 was great, things changed after I installed W8 :) )

  38. ReMark says:

    Good…

    Agree with Bastian92… there are many details that need a fix.

    Example: the network status icon on the tray bar… we need something that show the U/D… so please put the option to add in the tray bar a U/D meter near the basic network status icon.

    And another quick fix… gadget are very useful with their customization (opacity, scaling, placing, etc…) but you can ADD a "Lock Widgets" option because is a bit annoying the "drag/option bar" that appear with mouse-over. If you lock them you can't move them and the bar doesn't apper. More polish.

    Ah,… sound recorder is toooooo basic!! Put a decent sound recorder on 8, I don't want to use 3rd party software to do a simple thing like recording with different options.

    Sorry for the little off topic, but we are waiting for a post about all of these little, but important, things ;-D

  39. ReMark says:

    Good…

    Agree with Bastian92… there are many details that need a fix.

    Example: the network status icon on the tray bar… we need something that show the U/D… so please put the option to add in the tray bar a U/D meter near the basic network status icon.

    And another quick fix… gadget are very useful with their customization (opacity, scaling, placing, etc…) but you can ADD a "Lock Widgets" option because is a bit annoying the "drag/option bar" that appear with mouse-over. If you lock them you can't move them and the bar doesn't apper. More polish.

    Ah,… sound recorder is toooooo basic!! Put a decent sound recorder on 8, I don't want to use 3rd party software to do a simple thing like recording with different options.

    Sorry for the little off topic, but we are waiting for a post about all of these little, but important, things ;-D

  40. Wigster says:

    So what happens if I am running some application which is executing a calculation which takes a long time, say something like Mathematica, or even some scientific code I've written: sometimes my calculations take an hour or more to finish. I clearly would like to browse away, use the computer and at the same time make sure that the calculation doesn't get suspended. Or is the idea here that such applications will *never* be used in the Metro interface?

    I think the example of Mathematica is quite pertinent, since I could imagine Wolfram writing a tablet version, which one could use when working away from a desktop machine. Then what exactly would be stopping me from executing a calculation that does not complete immediately.

  41. Bob says:

    @Enigmaticatious, "If this wasn't done, then your memory hogging desktop apps simply wouldn't have the additional memory freed up."

    This is not true. As memory pressure builds, the working set of a Metro App that is not in use would be written to the page file just like a desktop application's would be. They simply appear to be making some optimizations to treat the working set of Metro Apps as a single unit rather than just a bunch of pages when it comes time to banish the Metro App to the pagefile.

    Having worked with virtual memory systems since the days of RAM being measured in KB and MB instead of GB, and with processors clock speeds in the low Mhz instead of low Ghz, I'm surprised these kinds of optimizations weren't already in place given that they were standard practice back then and the VMS background of some of the Windows' engineers.

  42. mathiou says:

    good job but is for mobile devices make a version for pc….or they will be

    vista II

  43. LeoStorm85 says:

    Very interesting post…can't wait for the release candidate.

  44. pmbAustin says:

    The video demo would be more meaningful, I think, if it had been on an average laptop with a standard hard drive, instead of an SSD.  I'd be interesting in seeing if there's noticable lag in that case, due to the slower access speeds.

  45. @Fula,@ dgschrei

    Yes, this feature is intended for mobile devices and therefore designed for flash based storage as well as HDDs.

    The first thing to consider is that the amount of writing we do due to this feature is affected by a few variables:

      – Amount of RAM in machines running Windows 8 with non-HDDs (determines frequency of hitting the threshold when this mechanism  kicks in triggering writes);

     – Apps that people run and their private working set size at point of suspension,

     – Patterns of concurrent app use;

     – Additional memory reductions in metro style app frameworks that have come after Win8 CP; and

     – Upper bound of an apps’ private working set where we won’t write it out (apps that have very large private working sets will be notified to save state and will be terminated more aggressively when there is memory pressure).

    During the design, we had a working model of these variables to guide the implementation and also added internal “knobs” to tweak policy. Policy knobs were necessary at that stage so that after shipping Win8CP, when we had literally millions of machines with real apps sending in usage and memory telemetry, we were able to validate our assumptions around concurrent app use, app memory use and frequency of hitting the threshold where we start reclaiming memory.  This is, of course, in addition to our lab based testing.

    In terms of the code itself, a few aspects that are important for flash based storage devices are:  1. Our writes are sequential and always overwrite a block entirely, therefore, device firmware doesn’t have to do more work to perform partial remapping of blocks, avoiding write amplification. 2. We send the TRIM command periodically to re-TRIM unused parts of the file and 3. As mentioned above, we have limits on the size of an apps private working set we’ll write out.

    At this point we feel that the feature is in a good place in terms of flash-based storage devices due to the work described above. But given we’ve not shipped yet, we’ll follow our normal course of action and keep an eye on memory telemetry looking for any dramatic shifts that would necessitate any changes.

  46. Mark says:

    Mr. Karagounis – thank you very much for this article. Well written, to the point and contained actual usable info.

    I did find it unclear under what circumstances the suspending of the Metro apps would happen. On my 16gb desktop system I have run a Metro internet radio app and switched to another app and I know the radio continued to play, from the sentence "Metro style apps, however, are different from desktop apps, in that they are usually suspended whenever they are no longer in the foreground" it sounded like this shouldn't happen.

    Is the model that suspension only happens when the OS is running low on physical memory?

    p.s. I echo pmbAustin – had serious withdrawl symptoms!

  47. Bryan K says:

    This Metro app implementation, though awesome, needs some SERIOUS work. fixingwindows8.blogspot.com throws out some really good ideas on how to fix Windows 8 on the desktop.

    Come on MS… LISTEN to your consumers. Nothing needs to be set in stone…

  48. LD says:

    Is there any better memory management for background desktop windows?  I don't plan on using metro, as soon as I can deactivate it I will, and I want to see if there is any non-metro benefit to this memory management.

  49. mtoure3 says:

    impressive!!! keep up the great work guys.

  50. I made two videos about the things that doesn't work properly

    Windows 8 snap doesn't work properly on desktop

    http://www.youtube.com/watch

    You cannot close the Windows 8 desktop, when an app is launched maximized

    http://www.youtube.com/watch

  51. snipping a picture says:

    Windows 8 snipping doesn't work properly on desktop

  52. McZ says:

    @Bryan K.

    The link you posted contains only one article. Even this article is not considering that there are some users who actually do like and want to use Metro on their desktops, at least in their home office. It further states, that desktop apps are not running on tablets, in fact this is only true for ARM-tablets.

    The "hybrid UI" is considered a problem. Well, thats true. The logical quick and clean fix would be to eliminate the desktop altogether and let Win32-windows either fly over the Metro-Screen having a transparent or glassy border, or simply being started in the same dimensions as a Metro-App without any border at all.

    This is the main problem I have with W8: there should be no Metro Start Page, but a Metro Desktop. A Metro-desktop, which should have the ability to put the Eiffel tower into the background, and the ability to run in 'WP7-mode', which means one colour or a colour-family for all tiles.

    Alternatively, if the desktop is retained, why is the small Start Page-image popping up when staying with in the bottom left corner with the mouse not larger and fully accessible? And there has to be something done on discoverability, at least for the initial steps (remember W95, when there was a bumping text pointing to the start button).

  53. Sorry for post again. I deleted the videos by mistaken

    Closing the Windows 8 desktop, when a desktop app is maximized not possible

    http://www.youtube.com/watch

    Windows 8 snipping tool doesn't work properly, when Metro-style apps are open

    http://www.youtube.com/watch

  54. paranol says:

    @all commenter

    Microsoft don't apply your ideas.

    don't tire selves.

    windows 8 in desktop mode failed.

    it's problematic hectic.

  55. -to -paranol says:

    Well, Paranol, ,

    Although Microsoft don't apply our ideas, some people can get informations from many people's comments.

    And, the most important thing is you are just a bug when microsoft see you

    XD

  56. pmbAustin says:

    I have to say that I've noticed some annoying issues switching back and forth between Metro Apps, and Metro<–>Desktop.  I'm sure it's probably mostly "The App's Fault", but it's significantly annoying.  Here's an example:

    I'm playing the game "Wordament", an addictive word game that's a Metro-style app.  I switch to Desktop to browse something in IE.  When I switch back to Wordament, even if it's only a few seconds away, Wordament is back at it's "Start Screen", and I have to "swipe" to get back to where I was.  I would expect that when switching back, I'd be right back where I was, as if I hadn't left.

    It's obvious the app "knows" that it was switched away.  Maybe it's programmed to behave like this, but I'm hoping this isn't a standard behavior, or that developers need to do extra code to AVOID this behavior.

    Side Note: The pinball game (FX2?) which worked fine before, now crashes consistently on launch.  More than that, it crashes the entire OS, dropping me back to the lock-screen, and losing any Desktop apps I had running.  Not good.  Metro Apps shouldn't be able to crash the entire OS!

  57. Mark says:

    @Bastian92

    I don't think this is the proper format for reporting bugs. When I had an issue similar to yours I posted it on the Microsoft Answers website ( answers.microsoft.com/en-us ) and when it was decided it was a legitimate issue I was able to send the bug feedback to the proper Microsoft team. I suggest you give it a try – if its a real issue it would be good to bring it to the proper teams attention!

  58. Xero says:

    @pmbAustin said:I t's obvious the app "knows" that it was switched away.  Maybe it's programmed to behave like this, but I'm hoping this isn't a standard behavior, or that developers need to do extra code to AVOID this behavior.

    ..or may be it's just their way of showing the "pause" state. Whatever it is, it's definately the app developer!

  59. Xero says:

    @IE-10-Team:

    In IE9 and IE10, if the system shutdown unexpectedly (like take of the battery), on next reboot the IE9 in Windows7 and IE10 in Windows8 will forget the saved passwords, such as Gmail, Hotmail and other user preferences such as Bing region. My region is Australia. So by default it opens the Australia page. But if I change it to US-English and restart the computer it always remember my preference. But the unexpected shutdown flashes the saved preferences!! FF remembers that of Bing, Hotmail, Gmail (..yada yada) even the system shutdown abruptly, crash unexpectedly or for any reason (without saving settings.. you can reproduce it very easily!)…

    Please consider this problem seriously… looks like the user preference storage is very fragile and semi-volatile.. anyone can reproduce this issue by taking off the plug or battery when multiple tabs in IE9/IE10 are opened.. I encounter this issue on my office computer as well as my laptop at home.. both running Windows 7×64 — IE9x32 and laptop has Windows8 Consumer preview x64 with IE10x86..

    Please ask  the user-experience guys to nail this problem down sooner than later.. I always speak high of IE9 in my circle of interaction and this behavior embarrass me breaks my heart. Isn't it the priority issue and should be addressed sooner than later.. please don't take it light people are very fanatical about these minor concerns and they opt other browsers for these tiny UI, personalization and customization reasons…

  60. Xero says:

    [IE Shortcuts]

    1- While holding Ctrl, if we click the "back" or "forward" button of Windows Explorer or Internet Explorer, the corresponding page should be opened in a new tab (in case of IE) and new window (in WinExplorer's case). This shortcut is present in EVERY non-IE browsers so at least provide this *missing shortcut* in IE10.

    2- While holding the Ctrl button if you press 0 (zero) on qwerty keyboard, the zoomed page is reverted to normal. But if the 0 is pressed on numpad, the shortcut doesn't work. Since Ctrl + numpad-0-key is not reserved for any action, please override this shortcut as EVERY non-IE browser does.

  61. @Mark

    The internet radio app you’re using kept playing in the background as its developer has taken advantage of the “Background Audio” affordance as detailed in the “Improving power efficiency for applications” blog. The blog also mentions other common “processing in the background” patterns which WinRT makes available to developers.

    Metro app suspension is not tied to physical memory use, if a developer doesn’t take advantage of the background processing affordances, Metro style apps will be suspended regardless of machine type.

    Thanks for the question

  62. Why should my Alt-Tab, Task Manager and thumbnail switching lists get cluttered with running apps just because Microsoft took a fancy to not closing apps in Windows 8? How would Windows know which app to show or not show in these lists unless I completely exit it?

  63. pmbAustin says:

    @xpclient: You can right-click the thumb-nail switching list, and select "close" with the mouse.  Or you can grab the top edge of any running Metro App, and drag it down to the bottom to "throw it away".  Both of these actions remove it from the lists, and exit the app.

  64. I have a comment and 2 questions. The comment:

    This is a wonderfully thought out feature, and a genius idea! I have wanted tabbed web browsers to do something like this for months.

    The questions:

    1. Does the desktop itself ever get suspended?

    2. Is there a way for an app to mark itself "unsuspendable"? i.e., if Spotify made a metro style app, then the Spotify app would have to play music in the background while the users use other apps. This would not work if it was suspended, and it really wouldn't work if Spotify's memory was dumped.

  65. @pmbAustin, dragging from top to bottom is a too complex mouse gesture for every day use. I prefer a simple big ass Close button which MS refuses to give.

  66. Nikhil says:

    I think concept of standby memory exists in win 7 as well.

  67. We all think that keyboard and mouse would not be working well with metro ui. i.e, in Metro you have to interpret horizontal scroll into the vertical scroll of the mouse.

    However, have you guys considered using big and multi-touch trackpad like the one on macbook to navigate through windows 8?

    like, you can use two fingers to either scroll up and down or left and right, it will feel intuitive just as with touchscreen. or, you can use four fingers swipe down from up to close a metro app, just like what you do with a finger swiping from the top of the screen.

    you can use four fingers to represent "snap from the edge of the screen". I guess this will make metro work great on those non-touchscreen laptops.

    ps. you are using too many one finger gestures on touchscreen. Don't you worry about that it will confuse some gestures that are inside an app. for example, if i am slicing the fruits, i happen to slice an apple reaching the top of the screen, and just when i slice it, the app closes itself!!!

  68. pmbAustin says:

    Agree with @Azure.Ch

    Windows 8 desperately needs STANDARD track-pad gestures and support.  Two finger scroll everywhere at the very least.  And pinch to zoom on the start screen.  All of this should work, out of the box, without requiring "special" manufacturer's drivers.  A consistent "gesture language" for trackpads is desperately needed.

  69. I agree with xpclient regarding the closing of Metro apps.  The gesture to close Metro apps may work wonderfully for touch-centric platforms, but is an abomination using a keyboard/mouse combination.

  70. RPotter says:

    @DarienHawk67 I see again someone commenting about "keyboard/mouse" combo, but Alt-F4 still works for metro apps. When people say "keyboard/mouse" I think they really just mean "mouse" because Win 8 works fine for keyboard

  71. hamakaze japan says:

    @JSM

    No!

    It is the translation service on Bing of Microsoft which I was using.

    Google is not used at all recently.

    http://www.microsofttranslator.com

    http://www.bing.com/

  72. Alex says:

    Azure.Ch: "i happen to slice an apple reaching the top of the screen, and just when i slice it, the app closes itself!!!"

    Now that's funny :)

  73. Pol says:

    Windows 8 is so 5 minutes ago. Move on to Windows 9!

  74. David says:

    Will the release version of Windows 8 allow the ability to 100% turn off Metro?  (Please say yes)

  75. Bob says:

    @David

    The next version of this blog will allow the ability to 100% turn off Metro-hating trolls.

  76. Micle says:

    Great Article :)

    We can also submit our .net related links on http://www.dotnettechy.com to improve traffic.

    The dotnettechy.com is a community of .Net developers joined together to learn, to teach, to find solutions, to find interview questions and answers, to find .net website / blog collection and to have fun programming.

  77. Alex Kven says:

    @David

    I'm sure you will be happy to know that Microsoft has been working on a new OS that has metro disabled by default, and will satisfy almost all of the metro-haters and people who write destructive criticism on our blog.

    It's called Windows 7.

  78. philk says:

    What script are you using to start the metro apps? Can you make it available please?

  79. pmbAustin says:

    This is a general question/observation:

    With WinRT and Metro on Win8, Microsoft is pushing into the consumer tablet space in a big way.  Consumers are used to major OS updates and new features at least annually (thanks to iPhone, WP7, Android, and iPad).  Is Microsoft going to compete here, updating Metro features and abilities every year?

    If so, will these updates be made to Win8/Pro/Enterprise too?  And how will that dove-tail with businesses and enterprises prefering stability, and NOT having to update every year?  Will this lead to a fragmented Metro market?

    If not, how will Microsoft keep excitement about Metro/WinRT up over time, and compete with the constantly updating Android and iOS tablets out there?

  80. Ecoli says:

    Windows 8 Consumer Preview works OK, but when I create a new folder on a good flash USB disk, Windows Explorer takes too long to create it (about 4 or 5 min.). Hope Microsoft will fix this soon.

  81. @ Bryan K

    The biggest problem with this entire article, is the assumption that Microsoft is as small as Apple. Apple is a consumer company. They make products for consumers. Also remember Apple is a Hardware company. You must run there hardware to run there software. Microsoft is a Software Company. Building a platform which is "hybrid" as you have stated is essential. As you have also stated you had a "hackintosh";you had to basically either write drivers which are very in-efficient and caused more headaches then ever or run a system in verbose mode which functioned semi okay, and you still found your self trying to buy hardware similar to apple to get it to even run. The windows 8 operating system is actually going in the right direction. Not cutting the business relationships with Microsoft which is a very solid business model. It appears you have a lot to learn about the huge differences between Apple and Microsoft. You make reference to, "Who needs Win 32 Apps". Businesses do! Just because a consumer buys the next greatest thing, does not mean businesses can afford to just use an "app" that has no true meaning to there business. Apple has the ability to just discontinue support on apps of there older operating system, because lets face it, apple only came back in the lime light because of the iphone. No one owned mac, besides a niche market of people that were apple eccentric. Looks like you are talented and are heading in the right direction but maybe a little history to look back in the past will help you understand the direction Microsoft has to take with windows 8. The ability to support both business models is key to keep there market share, and maintain huge support of business, and consumer alike. Apple has a different business model, because they came later in the game essentially, and what I mean by that, as before steve jobs came back in,the company was almost bankrupt. So the ability to reinvent and tackle new tasks was much easier, because if it failed there would be no apple, thankfully for them it worked and behold the Iphone!. Good luck in your career

  82. As others have noted, you need more flexibility with running Metro apps in the background.  We have some ideas for products we might like to bring to the Metro/Windows 8/Windows Phone platform in the future, but some of the restrictions on Metro apps, such as the suspension of background apps, could preclude this – that would be a real shame.

    Windows provides built-in background tasks, you say?  As in, we just need to find the right background task, and then our Metro app can be suspended?  OK, fine, where is the background task for doing the complicated 3D algorithms our software would require?  The answer is what I thought….

    The reality is our software might need to do some very CPU intensive computations for a few minutes on a background thread.  During this time, we need to *not* be suspended if the user switches away from our app to, say, check their e-mail while they wait.  The user *knows* we are going to be doing computations, they will know this will cost them battery life – but results don't come for free, and there is no getting around the fact that CPU cycles must be spent on calculations.  The least we can do, and what we would like to be able to do, is let the user (1) switch to another app while allowing computations to continue, (2) set the priority of the thread to low, so that we can keep other apps fast and fluid while we work.  We may also need to interface with a hardware device in the background.  Once again, background suspension will absolutely break this.

    Here's the reality, a lot of useful business apps are going to need to do custom business logic in the background.  We're doing a lot more than just playing MP3 files, for heaven's sake!!  There is *no way* you will ever be able to cover every background task an app might need to do.

    Perhaps when installing the app, you can display a warning that the app multitasks and may compromise battery life.  This would be great for filtering out the random poorly-written 99 cent apps from an app store that don't really have any business running in the background. (Does a simple loan calculator app need to run in the background?  Of course not; if I was installing such an app that requested this kind of thing, I would probably find another app.)  But our users are serious users about our software and are going to be using it for a specific application; suspending it in the background would really break it.  In fact, they would probably buy a Windows 8 device just for the express purpose of running our software.

    If an app's thread is well-written and uses blocking APIs with infinite timeouts (e.g. WaitForSingleObject with infinite timeout), there is no reason in my mind that the entire private working set can't be paged out to disk – the app is not actually requiring memory or CPU.  Poorly-written threads would periodically wake (e.g. using Sleep) and poll/check something, or heaven forbid, spin in a loop and burn CPU cycles.  Either of these activities are bad for battery life and memory pressure.  Maybe you could add a performance metric that calls out the number of times an app wakes any of its threads in a minute, for example?  This could quickly weed out the bad apps that are waking when they don't need to.

    Use the Windows Desktop, that's what it's for, you say?  The writing is obviously on the wall for the desktop.  You're not supporting user-written desktop apps on Windows on ARM, and the Windows 8-based Apollo I doubt will even have the desktop.  That means you are basically forcing a Metro-only future on us (even if you haven't publicly announced it yet – this is apparently what you see 10 years from now once desktop apps fade from view).  Both of these devices (ARM tablets/laptops, and phones) could potentially be useful devices that our users will want to use.  The advances in mobile hardware of the last few years have been incredible – they are faster than the desktop computers of yesteryear.  Let us use the power available in such a small form factor!