찬란

가상 메모리 (Virtual memory) 본문

운영체제

가상 메모리 (Virtual memory)

chan4 2023. 6. 10. 17:29

해당 블로그의 내용은 학교에서 배운 내용을 개인적으로 정리한 내용이므로, 잘못된 부분이 있을 수도 있습니다. 

 

 

Virtual storage (memory)

  • Non-continuous allocation (비연속적 할당)
  • 사용자 프로그램을 여러 개의 block으로 분할
  • 실행 시, 필요한 block들만 메모리에 적재
  • 기법
    • Paging system
    • Segmentation system
    • Hybrid paging / segmentation system

주소 매핑 (Address mapping)

 

연속적 할당 (Continuous allocation)

  • 상대 주소 (Relative address)
    • 프로그램의 시작 주소를 0으로 가정한 주소
  • 재배치 (Relocation)
    • 메모리 할당 후, 할당된 주소에 따라 상대 주소들을 조정하는 작업 

비연속적 할당 (Non-continuous allocation)

  • 가상 주소 (Virtual address = relative address)
    • 논리 주소(Logical address)
      • 연속된 메모리 할당을 가정한 주소
    • 실제 주소(Real address = absolute)
      • 실제 메모리에 적재된 주소
  • 주소 매핑 (Address mapping)
    • 가상 주소 >> 실제 주소 
  • 사용자/프로세스는 실행 프로그램 전체가 메모리에 연속적으로 적재되었다고 가정하고 실행 할 수 있음 

Block mapping

  • 사용자 프로그램을 block 단위로 분할/관리
    • 각 block에 대한 address mapping 정보 유지
  • Virtual address : v = (b, d)
    • b = block number
    • d = displacement(offset). 변위값 
  • BMT, Block Map Table
    • 주소 매핑 정보 관리
      • 커널 공간에 프로세스마다 하나의 BMT를 가짐 
    • Residence bit
      • 해당 블록이 메모리에 적재되었는지 여부 (0 또는 1)

 

Virtual storage methods

  • Paging system
  • Segmemtation system
  • Hybrid paging / Segmemtation system

Paging system

  • 프로그램을 같은 크기의 블록으로 분할 (Pages)
  • Page
    • 프로그램의 분할된 Block
  • Page frame
    • 메모리의 분할 영역
    • Page와 같은 크기로 분할 
  • 논리적 분할이 아님 (크기에 따른 분할)
    • 페이지 공유(Sharing) 및 보호(Protection) 과정이 복잡
      • Segmentation 대비
    • 간단하고 효과적임
    • 외부 단편화 없음
      • 대신 내부 단편화 발생 가능 

Virtual address : v = (p, d)

  • p = page number
  • d = displacement (offset)

주소 매핑

  • PMT, Page Map Table
    • Residence bit
    • Secondary storage address (Swap-device의 위치)
    • Page frame number

주소 매핑 메커니즘

 

직접 사상 (Direct mapping)

  • Block mapping 방법과 유사
  • 문제점
    • 메모리 접근 횟수가 2배
      • 성능 저하
    • PMT를 위한 메모리 공간 필요
  • 해결방안
    • TLB, Associative mapping
    • PMT를 위한 전용 기억장치(공간) 사용
      • Dedicated register or cache memory

연관 사상 (Association mapping)

  • TLB(Translation Look-aside Buffer)에 PMT 적재 
    • PMT의 임시저장 Cache 역할을 함 
  • PMT를 병렬 탐색
  • Low overhead
  • high speed 
  • Expensive hardware
    • 큰 PMT를 다루기 어려움

Hybrid direct / associate mapping

  • 두 기법을 혼합하여 사용
    • HW 비용은 줄이고, 연관 사상만의 장점 활용
  • 작은 크기의 TLB 사용 
    • PMT : 메모리 (커널 공간)에 저장
    • TLB : PMT 중 일부 entry 들을 적재
      • 최근에 사용된 page들에 대한 entry 저장 
    • 지역성(Locality) 활용
      • 프로그램의 수행과정에서 한번 접근한 영역을 다시 접근 
      • 또는 인접 영역을 다시 접근할 가능성이 높음 

메모리 관리 (Memory management)

  • Page와 같은 크기로 미리 분할하여 관리/사용
    • Page frame
    • FPM 기법과 유사

Frame Table

  • Page frame 당 하나의 entry
  • 구성
    • Allocated/available field
    • PID field
    • Link field : For free list (사용가능한 fp들을 연결)
    • AV : Free list header (free list의 시작점)

Page sharing

  • 여러 프로세스가 특정 page를 공유 가능
    • Non-continuous allocation
  • 공유 가능 page
    • Procedure pages
      • Pure code (reenter code)
    • Data pages
      • Read-only data
      • Read-write data
        • 병행성 제어 기법 관리하에서만 기능 

Page protection

  • 여러 프로세스가 page를 공유할 때, Protection bit 사용

Segmentation system

  • 프로그램을 논리적 Block으로 분할 (Segment)
    • Block의 크기가 서로 다를 수 있음
    • ex) stack, heap, main procedure, shared Lib
  • 메모리를 미리 분할하지 않음
    • VPM과 유사
  • Segment sharing / protection 이 용이함
  • 주소 매핑 및 메모리 관리의 overhead가 큼
    • 전용 HW 활용으로 해결 가능 
  • 내부 단편화 없음
    • 외부 단편화 발생 가능 

Virtual address : v = (s, d)

  • s = segment number
  • d = displacement(offset)
  • Segment Map Table (SMT)
  • Address mapping mechanism
    • Paging system과 유사 

SMT, Segment Map Table

  • Residence bit
  • Secondary storage address
  • segment length
  • protection bits (R/W/X/A)

직접 사상 (Direct mapping)

  • Residence 비트가 0인 경우, Segment fault
  • 변위(d)가 segment 길이보다 큰 경우 
    • segment overflow exception 처리 모듈을 호출
  • 허가되지 않은 연산을 경우 (protection bit field 검사)
    • segment protection exception 처리 모듈을 호출 

메모리 관리

  • VPM과 유사
    • Segment 적재 시, 크기에 맞추어 분할 후 적재

Segment sharing & protection

  • 논리적으로 분할되어 있어, 공유 및 보호가 용이함 

 

Hybrid paging / segmentation system

  • PagingSegmentation의 장점 결합
  • 프로그램 분할
    • 논리 단위의 Segment로 분할
    • 각 segment를 고정된 크기의 page들로 분할 
    • Page sharing / protection이 쉬움
    • 메모리 할당/관리 overhead가 작음
    • 외부 단편화 없음
  • Page 단위로 메모리에 적재 
  • 전체 테이블의 수 증가
    • 메모리 소모가 큼
    • Address mapping 과정이 복잡 (3번 접근)
  • 직접 사상의 경우, 메모리 접근이 3배
    • 성능 저하 요인 

Virtual address : v = (s, p, d)

  • s = segment number
  • p = page number
  • d = offset in page
  • SMT와 PMT 모두 사용
    • 각 프로세스 마다 하나의 SMT
    • 각 segment마다 하나의 PMT
  • Address mapping
    • 직접, 연관 사상
  • 메모리 관리
    • FPM(Fixed Partition Multi-programming)과 유사

SMT in Hybrid mechanism

  • Residence bit 없음
    • 메모리에 올라가는 것은 page이기 때문 
  • PMT address 
  • SMT entry에서 PMT 를 찾음 

PMT for a segment

  • Residence bit 
  • page frame number
Comments