logo
Published on

OS : 가상메모리

Authors
  • avatar
    Name
    Bora Choi
    Twitter

Virtual Storage(Memory)

  • Non-continuous allocation
  • 사용자 프로그램을 여러 개의 block으로 분할
  • 실행 시, 필요한 block들만 메모리에 적재
    • 나머지 block들은 swap device에 존재
  • 기법들
    • paging system
    • segmentation system
    • hybrid paging/ segmentation system

Address Mapping

  • Continuous allocation

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

    • Virtual address(가상주소) = relative address : logical address(논리주소), 연속된 메모리 할당을 가정한 주소
    • Real address(실제주소) = absolute(physical) : 실제 메모리에 적재된 주소

    ⇒ virtual address ⇒ real address 로 변환

Block Mapping

  • 사용자 프로그램을 block 단위로 분할 : 각 block에 대한 address mapping 정보 유지

Virtual address : v = (b,d)

  • b = block number
  • d = displacement(offset) in a block
  • Block map table (BMT) - Address mapping 정보 관리
    • kernel 공간에 프로세스 마다 하나의 BMT를 가짐
    • Residence bit : 해당 블록이 메모리에 적재되었는지 여부 (0 / 1)

Block Mapping의 흐름

  1. 프로세스의 BMT에 접근
  2. BMT에서 block b에 대한 항목(entry)를 찾음
  3. Residence bit 검사
    1. residence bit = 0 경우, swap device에서 해당 블록을 메모리로 가져 옴. BTM업데이트 후 3-2 단계 수행
    2. residence bit =1 경우, BMT에서 b에 대한 real address 값 a확인
  4. 실제 주소 r 계산(r=a+d)
  5. r을 이용하여 메모리에 접근

Virtual Storage Methods

Paging System

  • 프로그램을 같은 크기의 블록으로 분할(pages)
  • Terminologies
    • Page : 프로그램의 분할된 block
    • Page frame : 메모리의 분할 영역, page와 같은 크기로 분할

특징

  • 논리적 분할이 아님 (크기에 따른 분할) - Page 공유(sharing) 및 보호(protection) 과정이 복잡함 : segmentation대비
  • Simple and efficient : Segmentation대비
  • No external fragmentation : internal fragmentation 발생 가능

Address Mapping

Virtual address : v = (p,d)

  • p : page number
  • d : displacement(offset)
  • PMT(page map table) 사용
  • Address mapping mechanism
    • Direct mapping(직접 사상)
    • Associative mapping(연관 사상)
      • TLB(Translation Look-aside Buffer)
    • Hybrid direct/associative mapping

Direct mapping

  • block mapping과 유사

  • 흐름

    1. 해당 프로세스의 PMT가 저장되어 있는 주소b에 접근

    2. 해당 PMT에서 page p에 대한 entry찾음

      • P의 entry위치 = b + q * entrySize
    3. 찾아진 entry의 존재 비트 검사

      1. Residence bit = 0인 경우(page fault), swap device에서 해당 page를 메모리로 적재 PMT를 갱신한 후 3-2 단계 수행

        ✳️ page fault : Context switching 발생(I/O) ⇒ overhead‼️

      2. residence bit = 1 인 경우, 해당 entry에서 page frame 번호 p’를 확인

    4. p’와 가상 주소의 변위 d를 사용하여 실제 주소 r 형성

      • r= p’ * pageSize + d
    5. 실제 주소 r로 주기억장치에 접근

  • 문제점

    • 메모리 접근 횟수가 2배 : 성능저하(performance degradation)
    • PMT를 위한 메모리 공간 필요
  • 해결 방안

    • Associative mapping(TLB)
    • PMT를 위한 전용 기억장치(공간) 사용
      • Dedicated register or cache memory
    • Hierarchical paging
    • Hashed page table

Memory Management

  • page와 같은 크기로 미리 분할하여 관리/사용
    • page fram
    • 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 page
      • read-only data
      • read-write data
        • 병행성(concurrency)제어 기법 관리하에서만 가능
  • Procedure page sharing

    • 프로세스들이 shared pagedㅔ 대한 정보를 PMT의 같은 entry에 저장하도록 함

Page Protection

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

Segmentation System

  • 프로그램을 논리적 block으로 분할(segment)
    • block의 크기가 서로 다를 수 있음
    • stack, heap, main procedure, shared lib, etc.
  • 특징
    • 메모리를 미리 분할 하지 않음 : VPM과 유사
    • Segment sharing/protection이 용이함
    • Address mapping 및 메모리 관리의 overhead가 큼
    • No internal fragmentation : External fragmentation 발생 가능

Adress mappin

Virtual address : v = (s,d)
s: segment number
d: displacement in a segment

  • Segment Map Table(SMT)
  • Address mapping mechanism => paging system과 유사

흐름

  1. 프로세스의 SMT가 저장되어 있는 주소 b에 접근
  2. SMT에서 segment s의 entry 찾음
    • s의 entry 위치 = b + s * entrySize
  3. 찾아진 Entry에 대해 다음 단계들을 순차적으로 실행
    1. 존재 비트가 0인 경우,
      //missng segment fault
      swap device로 부터 해당 segment를 메모리로 적재 SMT를 갱신
    2. 변위(d)가 segmnet 길이보다 큰 경우 (d>Is),
      segment overflow exception 처리 모듈을 호출
    3. 허가되지 않은 연산일 경우(protection bit field검사).
      segment protection exception 처리 모듈을 호출
  4. 실제 주소 r 계산 ( r = as+d)
  5. r로 메모리에 접근

Memory management

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

Segment sharing/protection

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

paging vs segmentation

  • paging system

    장점

    • simple

    • low overhead

    단점

    • no logical concept for partitioning
    • complex page sharing mechanism
  • Segmentation system

    장점

    • logical contept for partitioning

    • simple and easy sharing mechanism

    단점

    • high management overhead

Hybrid paging/segmentation

  • paging과 semgentation의 정점 결합
  • 프로그램 분할
    1. 논리 단위의 segment로 분할
    2. 각 segment를 고정된 크기의 page들로 분할
  • page 단위로 메모리에 적재
    => No external fragmentation Address mapping

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

s:segment number p: page number d: offset in a page

  • SMT 와 PMT 모두 사용

    • 각 프로세스 마다 하나의 SMT
    • 각 segment마다 하나의 PMT
  • Address mapping

    • direct, associated 등
  • 메모리 관리

    • FPM과 유사
  • 전체 테이블 수 증가

    • 메모리 소모가 큼
    • Address mapping과정이 복잡하다
  • Direct mapping의 경우 메모리 접근이 3배

    • 성능이 저하될 수 있음