Zeroing out my memory does cause them to page in faster after all

Not too long ago, I answered the question "If I zero out my memory pages, does that make them page in faster?" with "No."

Turns out that I was working from outdated information.

My former colleague Adrian Oney (who, among other things, has shared with us the story of the USB Cart of Death) confirms the information in the white paper shared by commenter John Doe, namely that starting in Windows Vista, the memory manager does check whether a page that is about to paged out consists entirely of zeroes. If so, then the memory manager turns the page into a demand-zero page rather than a page stored in the pagefile (that happens to contain nothing but zeroes).

Adrian said that he wrote the original prototype which confirmed that the extra check was worth it. "Some of this was due to apps dirtying their zero-init pages with inits to zero. Some of it was due to user mode zeroing pages for security reasons. But it was common enough to make it worthwhile."

I suspect that the increasing use of virtualization may contribute to this virtuous cycle as well. If the app is running in a virtual machine, then it's a big win to avoid having to perform virtualized I/O.

Comments (6)
  1. DWalker07 says:

    Could you add a quick addendum/correction to your September 7, 2016 blog post, for those who may stumble on that? In the interests of accuracy. Thanks!

  2. Joshua says:

    I suspect that virtualization was indeed why it was worth it. Linux has this habit of using the idle job to zero freed pages in the background.

    (It doesn’t take much for checking for zero page to win because most memory use on a part page is at the beginning of the page and rep cmpsd (comparing against the real zero page of course) is really fast compared to the time required to write to disk.

  3. Of course, even better (on a POSIX system) is to just call madvise() and indicate that you don’t care about the contents without actually having to touch them. Does Windows have a comparable facility?

    1. Yes. Look for an article about this after the new year.

  4. kantos says:

    I can’t imagine how big the page file would get without support for this, particularly on virtualization servers. The performance boost from the avoided IOPs alone must be massive.

    1. Alois Kraus says:

      With memory compression of Windows 10 you get these checks anyway. It even allows private page sharing between different processes which adds: If I ensure that my memory contents (page aligned) in different processes are identical will it then page faster to: Yes (see ). On Server 2012 and later the memory manager can share private identical pages already if you enable that memory manager setting. As far as I know it has been pretty much disabled in Windows 10 for security reasons. Memory compression is on Windows 10 the best setting to make things page faster if much identical or zeroed out memory is about to be paged out.

Comments are closed.

Skip to main content