Comment by Brian_K_White

Comment by Brian_K_White 11 hours ago

1 reply

There is no such partial or mixed exe problem from paging.

It doesn't matter if it was paged out, virtual memory is still just memory.

Paging out & restoring some memory doesn't know or care where the contents originally came from. It doesn't have an optimization that goes "Oh this chunk of memory is an executable file. I can skip writing this out to the swap file, and later when I need to restore it I can just read the original file instead of swap."

For files that a program opens, an open handle is an open handle. The entire file is available in whatever state it was at the time the handle was opened, modulo whatever changes this specific handle has made.

If a program closes and re-opens handles, then it always knew that the entire world could have changed between those 2 opens. Same if it opens non-exclusive. If it opens without exclusive or closes & reopens, then it's ok for the data to change between each access.

There are problems during updates, but they are much higher level and safer than that. Open file handles are open file handles, and currenly loaded exes are consistent and sane until they close. All the problems are in the higher level domains of processes interacting with each other.

anonymars 10 hours ago

You're right that the file handle protects from such a mixed read (which is why replacing an in-use loaded file is not super straightforward) so that wasn't phrased well. I point out that there also exists a race condition of loading multiple dlls.

But in fact it is true that the pages that are mapped to a file on disk will not be redundantly written to the page file. Some pages might if they were modified by relocation fixups.

More info: https://devblogs.microsoft.com/oldnewthing/20170119-00/?p=95...

That links to this which is also salient: https://learn.microsoft.com/en-us/archive/blogs/larryosterma...

And in case you're wondering how this plays with ASLR: https://devblogs.microsoft.com/oldnewthing/20160413-00/?p=93...