[Pintos] - Virtual Memory - introduction

Junyeong Fred Kim·2022년 1월 11일
0

운영체제

목록 보기
16/27

Virtual Memory

In this assignment, you will remove that limitation by building an illusion of infinite memory.

You should take care to fix any bugs in your project 2 submission before you start work on project 3, because those bugs will most likely cause the same problems in project 3.

.......🧨🧨🧨🧨

Background

Source File

VM 디렉토리에서 작업한다.

You MUST follow the given template. That is, if you submit the code, that is not based on the given template, you get 0pts.

📄 include/vm/vm.h, vm/vm.c

Provides a general interface for virtual memory. In the header file, you can see the defintion and explanation for different vm_type

  • VM_UNINIT, VM_ANON, VM_FILE, VM_PAGE_CACHE
  • 지금은 VM_PAGE_CACHE 무시, 프로젝트 4용

또한 여기에서 추가 페이지 테이블을 구현한다. 아래 참조

📄 include/vm/uninit.h, vm/uninit.c

  • uninitialized pages(vm_type = VM_UNINIT)에 대한 작업을 제공한다.

📄 include/vm/anon.h, vm/anon.c

  • anonymouse pages(vm_type = VM_ANON)에 대한 작업을 제공한다.

📄 include/vm/file.h, vm/file.c

  • file-backed pages(vm_type = VM_FILE)에 대한 작업을 제공한다.

📄 include/vm/inspect.h, vm/inspect.c

  • Contains memory inspection operations for grading. Do not change this files.

📄 include/devices/block.h, devices/block.c

block device에 섹터 기반 읽기 및 쓰기 액세스를 제공합니다. 이 인터페이스를 사용하여 block device로 swap partition에 액세스한다.


Memory Terminology

Some of these terms should be famililar from project 2, but much of it is new


pages

  • 페이지는 길이가 4,096바이트(페이지 크기)인 가상 메모리의 연속 영역이다. 페이지는 page-aligned 상태여야 한다.

  • 즉, page size로 균등하게 구분되는 virtual address에서 시작해야 한다. 따라서 64비트 virtual address의 마지막 12비트는 page offset(또는 offset)

상위 비트는 곧 도입될 페이지 테이블의 인덱스를 나타내는 데 사용되며, 64비트 시스템에서는 가상 주소를 다음과 같이 만드는 4단계 페이지 테이블을 사용한다.

63          48 47            39 38            30 29            21 20         12 11         0
+-------------+----------------+----------------+----------------+-------------+------------+
| Sign Extend |    Page-Map    | Page-Directory | Page-directory |  Page-Table |    Page    |
|             | Level-4 Offset |    Pointer     |     Offset     |   Offset    |   Offset   |
+-------------+----------------+----------------+----------------+-------------+------------+
              |                |                |                |             |            |
              +------- 9 ------+------- 9 ------+------- 9 ------+----- 9 -----+---- 12 ----+
                                          Virtual Address
  • 각 프로세스에는 virtual address KERN_BASE(0x800400000) 아래의 페이지인 사용자(virtual) 페이지의 독립적인 집합이 있다.

  • 반면에 kernel (virtual) pages 세트는 global. 어떤 스레드 또는 프로세스가 실행 중인지에 관계없이 동일한 위치에 있다.

kernel은 user 및 kernel pages 모두 액세스할 수 있지만, user process는 자체 user pages에만 액세스할 수 있다.


Frame

framephysical frame의 연속(?) 영역이다. page와 마찬가지로 frames도 page-size와 page-alinged 되어야 한다. 64비트 물리적 주소는 다음과 같이 frame numberframe offset(또는 offset)으로 나눌 수 있다.

                          12 11         0
    +-----------------------+-----------+
    |      Frame Number     |   Offset  |
    +-----------------------+-----------+
              Physical Address
  • x86-64는 물리적 주소의 메모리에 직접 액세스할 수 있는 방법을 제공하지 않는다.

  • 핀토스는 커널 가상 메모리를 물리적 메모리에 직접 매핑함으로써 이 문제를 해결한다 - 커널 가상 메모리의 첫 번째 페이지는 물리적 메모리의 첫 번째 프레임에 매핑되고, 두 번째 페이지는 두 번째 프레임에 매핑된다.

  • 그러므로 프레임은 커널 가상 메모리를 통해 접근할 수 있다.핀토스는 물리적 주소와 커널 가상 주소 사이를 변환하는 기능을 제공한다. 자세한 내용은 Virtual Addresses를 참조.


Page Tables

페이지 테이블은 CPU가 가상 주소를 물리적 주소, 즉 페이지에서 프레임으로 변환하는 데 사용하는 데이터 구조이다.

페이지 테이블 형식은 x86-64 아키텍처에 의해 결정됩니다. 핀토스는 페이지 테이블 관리 코드를 threads/mmu.c에 제공한다.

아래 다이어그램은 페이지와 프레임 간의 관계를 보여줍니다. 왼쪽의 가상 주소는 페이지 번호와 오프셋으로 구성된다. 페이지 테이블은 페이지 번호를 프레임 번호로 변환하여 수정되지 않은 오프셋과 결합하여 오른쪽의 실제 주소를 얻는다.

                          +----------+
         .--------------->|Page Table|-----------.
        /                 +----------+            |
        |   12 11 0                               V  12 11 0
    +---------+----+                         +---------+----+
    | Page Nr | Ofs|                         |Frame Nr | Ofs|
    +---------+----+                         +---------+----+
     Virt Addr   |                            Phys Addr    ^
                  \_______________________________________/
                  
profile
기억보다 기록

0개의 댓글