When to do or not do INVLPG, MOV to CR3 to minimize TLB flushing

前端 未结 2 1073
梦如初夏
梦如初夏 2021-02-01 16:50

Prologue

I am an operating system hobbyist, and my kernel runs on 80486+, and already supports virtual memory.

Starting from 80386, the x86 processor family by

2条回答
  •  暖寄归人
    2021-02-01 17:54

    To your first question:

    1. You can always use INVLPG and you can do any change possible. Use of INVLPG is always safe.
    2. Reloading CR3 does not invalidate global pages in the TLB. So sometimes you must use INVLPG as reloading CR3 has no effect.
    3. INVLPG must be used for every page involved. If you are changing multiple pages at a time then there comes a point where reloading CR3 is faster than a multitude of INVLPG calls.
    4. Don't forget the Address Space Identifier extension on modern CPUs.

    To your second question:

    A page that is not mapped can not be cached in the TLB (assuming you invalidated it correctly when you unmapped it previously). So any change from not-present does not need INVLPG or CR3 reloading.

提交回复
热议问题