9 ms·
I have no idea on how many other OSes do this, but at least OpenBSD will use idle time to pre-clear memory pages that have been returned to the OS, so that when
by IcePic 8y ago
I have no idea on how many other OSes do this, but at least OpenBSD will use idle time to pre-clear memory pages that have been returned to the OS, so that when the next process has them mapped, it doesn't have to zero-fill-on-demand at the very latest moment.
It has to be done at some point, but if you keep a queue of pages needing to be cleared and dealing with as many as you can while any core is idle, a non-100% busy system can be seen as to "improve" performance a bit by timeshifting the task to not-directly-after-former process but also not when the new process is calling for memory to be mapped in.
But when that list is empty, doing the right kind of CPU sleep is totally worthwhile of course.
- sedatk 8y agoWindows also has a similar thread called “Zero Page Thread” which has the lowest priority on the system (even lower than IDLE, IIRC).
- ovi256 8y ago>lower than IDLE Any idea why that's necessary ? So it's preempted by a IDLE process.
- bonzini 8y agoIDLE is the priority of a process that runs only when the system is otherwise idle. It shouldn't be preempted by zeroing memory.
- na412 8y agoBut then under what circumstances will the zero page thread ever be scheduled?
- blattimwind 8y agoWhen there are no runnable idle threads.
- masklinn 8y agoIt's confusing, but "idle" is a priority class as well as a state: https://docs.microsoft.com/en-us/windows/desktop/procthread/scheduling-priorities https://docs.microsoft.com/en-us/windows/desktop/procthread/... The idle task (when there's nothing to run) doesn't have a priority at all, it just gets run when nothing else is available. the "idle" priority is an actual priority, for when there's no higher-priority task to run. The ZPT is prioritized below "idle", so super-duper-low priority.
- dTal 8y agoThank you for this clear explanation. It is confusing!
- chaosite 8y agoSo the zero page process runs when one core is busy but the rest are free?
- klodolph 8y agoIt runs when the there are no higher-priority processes to schedule on a particular core. IDLE processes are higher priority, so as long as an IDLE process can be scheduled, the zero page process won't run.
- JdeBP 8y agoWindows NT thread scheduling does not work that way. If the Zero Page Thread is ready to run, the processor's Idle Thread is not scheduled. Idle Threads do not live on ready queues, and are only dispatched when there is no thread available from the processor's ready queue. Also, do not conflate the user-thread idle priority class with the (non-)priorities of Idle Threads.
- masklinn 8y agoI expect most BSDs do this. Dragonfly actually removed it two years ago: http://lists.dragonflybsd.org/pipermail/commits/2016-August/624202.html http://lists.dragonflybsd.org/pipermail/commits/2016-August/... - Pre-zeroing a page only takes 80ns on a modern cpu. vm_fault overhead in general is ~at least 1 microscond. - Pre-zeroing a page leads to a cold-cache case on-use, forcing the fault source (e.g. a userland program) to actually get the data from main memory in its likely immediate use of the faulted page, reducing performance. - Zeroing the page at fault-time is actually more optimal because it does not require any reading of dynamic ram and leaves the cache hot. - Multiple synth and build tests show that active idle-time zeroing of pages actually reduces performance somewhat and incidental allocations of already-zerod pages (from page-table tear-downs) do not affect performance in any meaningful way.
- mehrdadn 8y agoWhy don't they just avoid the cache pollution issues with non-polluting writes? _mm_stream_si128 comes to mind.
- Tuna-Fish 8y agoThat's the exact opposite of what you want to do. The starting point is that there is stale, useless data in ram. Then a usermode program requests an empty page, and usually when they do this they want to immediately use it.(1) Using non-polluting writes, you have to use main memory bandwidth both for clearing the page, and also for bringing the page back to cache immediately afterwards when the program uses it. Using writes that just allocate new, cleared dirty lines in cache (like the AMD CLZERO), it avoids both the write (which will happen later, when the lines are evicted from cache, probably after the lines have been used by the program), and the read because the lines are now all in the cache. (1) And on Linux this is trivially true, because Linux only allocates and clears the page when it is first accessed.
- mehrdadn 8y agoI don't follow. Who is "you" here? The user-mode program, or the kernel-mode zero-page thread (or whatever its name is)? I'm talking about the zero-page thread here, which is zeroing pages in the background long before any thread has requested access. Those threads do not want to evict anything from the cache. This seems exactly what we want.
- brann0 8y agoI think the article talks about idle time itself, when there's no workload. OS doing bookkeeping means CPU isn't idle.