Cost of a page fault trap

前端 未结 1 1472
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-13 19:05

I have an application which periodically (after each 1 or 2 seconds) takes checkpoints by forking itself. So checkpoint is a fork of the original process which just stays idle u

相关标签:
1条回答
  • 2021-02-13 19:15

    You can do the rough math for an educated guess yourself. Assuming no disk access (~10 billion cycles), you have to account for

    • 160 cycles for the trap and returning (approximately, on x86_64)
    • validity checks, quota, accounting, and whatnot (unknown, probably a few hundred to a thousand cycles)
    • aligned memcpy of 4096 bytes, something around 500-800 cycles
    • TLB invalidation (adds 10-100 cycles on first access)
    • either eviction of other cached data or one guaranteed cache miss (80-400 cycles) depending on the implementation of the memcpy. It matters a lot on your access pattern whether one or the other is better.

    So all in all, we're talking of something around 2000 cycles, with some of the effects (e.g. TLB and cache effects) being spread out and not immediately visible. Omondi and Sedukhin reported 1700 cycles on P-III back in 2003, which is consistent with this estimate.

    Note that if the page has never been written to before, things are slightly different according to a comment by L. Torvalds back in 2000. A copy-on-write miss on a zero page pulls another zero page from the pool and doesn't copy zeroes. That's pretty much a guaranteed cache miss too, though.

    0 讨论(0)
提交回复
热议问题