1. 程式人生 > >Virtualization and Performance: Understanding VM Exits

Virtualization and Performance: Understanding VM Exits

翻譯自:Virtualization and Performance: Understanding VM Exits

出於對特定指令 或 特定事件(eg.  page fault)的響應而導致的VM Exit(虛擬機器退出)是造成虛擬化系統性能下降的主要原因。但是你有沒有想過,為什麼會這樣?無論出於什麼原因,VM Exit的背後究竟發生了什麼?

VM Exit意味著從當前執行的VM 到 VMM之間存在一個轉換點,而VMM出於特定原因必須執行系統控制。通常,處理器必須儲存VM退出時執行狀態的快照。對於英特爾架構,大概有如下幾步:

  1. 在VM-exit information fields 處記錄導致VM Eixt的資訊(包括exit reason, exit qualification, guest address),並更新VM-entry control fields.
  2. 儲存處於Guest Mode狀態下的CPU狀態,包括control registers(控制暫存器), debug registers(除錯暫存器), MSRs  segment registers(段暫存器), descriptor-table registers, RIP, RSP, and RFLAGS, 以及非狀態暫存器。
  3. MSRs  用於控制報告處理器效能,將MSRs  儲存到VM-exit MSR-store area
  4. 根據host-state area和一些VM-exit controls載入processor state,包括control registers, debug registers, MSRs, host table and descriptor-table registers, RIP, RSP, and RFLAGS, page-directory pointer table entries, as well as non-register state.
  5. 從VM-exit MSR-store area載入MSRs

哦,不要忘記在VMM執行了系統管理功能之後,將執行相應的VM entry,將處理器控制從VMM轉移到VM!

現在,您可以看到為什麼VM退出會產生相當大的開銷,為單個轉換(VM到VMM)浪費數百或數千個CPU週期。 順便說一下,為了緩解這個問題,Intel付出了相當大的努力減少了單個轉換(VM到VMM)所需的時鐘週期數。