XEN에서 Page Fault 처리 방법
출처: http://wiki.xensource.com/xenwiki/XenMemoryManagement
XEN 위키에서 가져왔습니다. 중간에 SimonKagstrom이라는 분이 불명확한 부분과 오류가 있는 부분을 정정해달라고 쓴 부분이 있지만 XEN에서 메모리가상화의 원리에 대해서 그림으로 이해가 되더군요. 그래서 이렇게 올려봅니다.
어설푼 영어실력으로 제가 이해한 것은 다음과 같습니다.
- 페이지 폴트가 일어나면 XEN이 먼저 가로채고 어떤 OS에서 발생한 Page Fault에서 발생했는지 판단해서 해당 Guest OS의 PageFault핸들러에게 인터럽트를 전달합니다.
- Page Fault를 전달받은 Guest는 자신의 페이지디렉토리를 검색하여 없는 것을 알고 페이지를 매핑해주는 작업을 하거나 잘못된 주소접근이라고 응용에게 리턴하겠지요
- 이때 페이지를 매핑해줄때는 XEN에서 특별히 제공해주는 기능 get_page(), phys_to_machine()을 통해서 머신물리주소를 구한 후 얻어진 Guest가상주소와 머신물리주소로 매핑을 합니다(HYPERVISOR_MMU_update())
여기서 Guest OS의 커널이 변경되어야 하는걸 명확히 보여주는데요. Windows같은 OS는 직접 커널을 변경할 수 없을터인데 이런 경우에 XEN에 어떤 형태로 처리해주는 궁금하네요.
아 그리고 제가 번역한게 엉망이어서 틀린부분좀 정정 부탁드려요 +_+
들어가면서
특별한 공지가 없으면 여기서 소개되는 정보는 Xen/unstable(x86)에서 참고한것이다.
Guest interface to Xen memory management
Start of day
At the StartOfDay (when a guest domain has just started), the Xen hypervisor passes a pointer to a start_info_t structure. This contains an initial page directory address (pt_base) and an address to the PhysicalAddress to MachineAddress translation (mfn_list).
Physical memory handed to the domain
PageTable 업데이트
이부분에서 불명확한 부분과 에러를 수정해줄분 없나요? // SimonKagstrom
애플리케이션에서 공유라이브러리, 물리메모리에 매핑되지 않은 애플리게이션의 코드와 같이, 애플리케이션에서 매핑되지 않아서 페이지폴트가 발생할수 있을거라 가정한다.
We assume that an application causes a page fault on e.g., code in a shared library, i.e. code that is in physical memory but not mapped to the application. We'll assume that the page directory exists, but does not have a page table or a page mapped for the faulting virtual address. The following will then happen (the steps are outlined in the figure below):
-
Page Fault가 발생하면 XEN이 인터럽트되고 게스트의 Trap Table을 통해서 인터럽트를 전달한다(HYPERVISOR_set_trap_table()을 통해서 등록된). Guest는 이후에 애플리케이션에 페이지를 맵하기 위해서 물리페이지를 찾을 것이다.
Xen receives the page fault and delivers it to the guest through the trap table (installed by HYPERVISOR_set_trap_table()). The guest will thereafter lookup a physical page to map into the application.
page_fault_handler(virt_addr) {
...
pgdir_entry = virt_to_pgdir(virt_addr);
pgtab_entry = virt_to_pgtab(virt_addr);
phys_page = virt_to_phys(virt_addr);
...
2. Guest는 Page Directory를 찾고 해당주소에 매핑된 페이지테이블이 없는 것을 알것이다. The guest looks up the page directory and finds that there exists no mapping (to a page table) for that address.
3. 새로운 페이지를 얻기위해 Guest는 다음과 같은 동작을 취할것이다. To get a new page table page, the guest will
- 페이지테이블을 위해서 새로운 페이지를 구한다. Get a new page (get_page()) for the page table
-
M2P변환테이블을 통하여 머신물리주소를 가상물리주소로 변환한다. Translate the pseudo-physical address of the page to a machine address through the machine->physical translation table, e.g.,
pgtab = get_page();
pgtab_mach_addr = machine_to_physical(pgtab);
4. 게스트는 HYPERVISOR_MMU_update()를 통해 게스트의 페이지디렉토리에 머신페이지테이블의 페이지의 머신물리주소를 넣는다. The guest inserts the machine address of the page table page into the page directory through HYPERVISOR_MMU_update(), i.e., something like (simplified syntax)
HYPERVISOR_mmu_update(pgdir_entry | MMU_NORMAL_PT_UPDATE, pgtab_mach_addr | PGTAB_PROTECTION, ...);
(페이지테이블은 접근가능하다 the page table page is now accessible)
5. The guest must then instruct Xen to pin this page as a page table page (simplified syntax): <-- 해석요망!!
HYPERVISOR_mmuext_op(MMUEXT_PIN_L2_TABLE, pgtab_mach_addr, ...);
6. 끝으로 게스트는 물리페이지를 페이지테이블에 맵할것이다. Finally the guest will map the physical page into the page table
phys_page_mach_addr = machine_to_physical(phys_page);
Pinning pages
Sharing pages with other domains
XenMemoryManagement (2006-02-10 08:26:18에 SimonKagstrom가(이) 마지막으로 수정)
History
Last edited on 06/30/2008 09:07 by seyool
Comments (0)