유튜브에 있는 김덕수 교수님의 Operating System 강의를 듣고 정리한 내용입니다.
중간에 등장하는 ppt 내용들은 모두 강의자료를 캡처한 것입니다.
🔧 Virtual Memory (가상 메모리)
Virtual address |
Address mapping |
 |
 |
- 사용자 프로그램을 여러 개의 block으로 분할
- 프로세스 실행 시, 필요한 block들만 메모리에 적재
- 나머지 block들은 swap device에 존재
- Non-continuous allocation
- Virtual address (Logical address)
- Real address (Physical address)
- Address mapping = virtual address → real address
- 기법들
- Paging sysem
- Segmentation system
- Hybrid system
Block mapping
Block Map Table |
Mapping |
 |
 |
- virtual address v = (b,d)
- b : block number
- d : displacement(offset) in a block
- Block map table (BMT)
- 커널 공간에 프로세스마다 하나의 BMT 가짐
- residence bit: 해당 블록이 메모리에 적재되었는지 여부 (1/0)
- 필요한 블록이 메모리에 있다면
- 필요한 블록이 메모리에 없다면
- swap device에서 블록을 메모리에 가져온 후 실제 주소 다시 계산
🔧 Paging System

- 프로그램을 같은 크기의 블록으로 분할
- page: 분할된 block
- page frame: 메모리의 분할 영역 (page와 같은 크기)
- 논리적 분할이 아님 (같은 함수가 쪼개질 수 있음)
- Page sharing(공유) 및 protection(보호) 과정이 복잡
- 간단하고 빠름
- Extenal fragmentation 없음
- Intenal fragmentation 발생 가능 (맨 마지막 꼭다리)
- Swap device를 어디로 설정하느냐에 따라 성능 차이 (실제 윈도우에서 설정 가능)
Address mapping
- Page Map Table (PMT) 사용
- Direct mapping
- Associative mapping
- Hybrid mapping
Direct mapping
PMT |
Mapping |
 |
 |
- Block mapping과 같은 방법
- Residence bit = 0 인 경우 (swap device에서 페이지 가져와야 함)
- page fault 발생
- Context switching 발생 (overhead)
- page fault 줄이는 것이 성능을 결정짓는 중요한 요소
- 문제점
- 메모리 접근 횟수가 2배 (PMT 확인, 실제 메모리 접근)
- PMT를 위한 메모리 공간 필요 (커널에 존재)
Associative mapping

- Translation Look-aside Buffer (TLB)에 PMT 적재 (변환 색인 버퍼)
- PMT 전용 하드웨어 (캐시)
- PMT 병렬 탐색
- Low overhead & high speed
- Expensive
Hybrid mapping

- Direct + Associative 혼합
- 작은 크기의 TLB 사용
- PMT: 메모리(커널)에 저장
- TLB: PMT 중 일부 entry들만 적재
- 최근에 사용된 page들 저장
- Locality 원리
- 먼저 TLB 탐색, TLB에 없으면 PMT 탐색
Memory management

- Frame table
- 메모리를 page와 같은 크기로 미리 분할하여 관리/사용
- FPM과 유사
- 비어있는 공간을 linked list로 저장
- 구성
- Allocated/Available : 프로세스에 할당 되었나
- PID : 어떤 페이지가 올라왔느냐
- Link : 사용 가능한 공간 (빈 공간) 포인터
- AV : 빈 공간의 시작점
Page sharing

- Non-continuous allocation 이기 때문에 여러 프로세스가 특정 page 공유 가능
- procedure page (Pure code)
- data page
- read-only data
- read-write data (concurrency 제어 하에서만 가능)
page sharing 문제점
Data page |
Procedure page |
 |
 |
- Data page sharing에서는 큰 문제 없음
- Procedure page의 경우 페이지 중간으로 이동해야 하는 경우가 생김 (if, switch, …)
- 이때 테이블에 따라 주소가 다르게 표현되기 때문에 어디로 가야하는지 알려줄 수가 없음
- 따라서 프로세스들이 page를 공유하면 PMT의 같은 entry에 저장하도록 맞춰줌 (ex. k번째 entry로 통일)
Page protection

- 페이지를 공유할 때 PMT에 protection bit 사용
- V : 메모리에 적재 여부
- R : 읽기 여부
- W : 수정 여부
- E : 실행 여부
🔧 Segmentation System

- 프로그램을 논리적 block으로 분할
- Block의 크기가 서로 다름
- ex) stack, heap, main procedure, shared lib, …
- 메모리를 미리 분할하지 않음 (VPM과 유사)
- Segment sharing/protection이 용이함
- Address mapping 및 메모리 관리 overhead 큼
- Internal fragmentation 없음
Address mapping (Direct mapping)
Segment Map Table |
Direct Mapping |
 |
 |
- Segment Map Table (SMT) 이용
- residence bit가 0인 경우 : segment fault
- offset d가 segement length보다 큰 경우 : segment overflow
Memory management
Partition Table (State Table) |
Sharing & Protection |
 |
 |
- Segment 적재 시, 크기에 맞추어 분할 후 적재
- VPM과 유사
- 논리적 분할이기 때문에 공유 및 보호가 용이함
🔧 Hybrid Paging & Segmentation System

- paging system의 장점: 관리가 편함
- segmentation system의 장점: 메모리의 효율적 활용
- Hybrid System
-
- 논리 단위의 segemt로 분할
-
- 각 segment를 고정된 크기의 page로 분할
- Page단위로 메모리에 적재
Address mapping
PMT & SMT |
Direct Mapping |
 |
 |
- Virtual address : v = (s, p, d)
- SMT와 PMT 모두 사용
- 각 프로세스마다 하나의 SMT
- 각 segment마다 하나의 PMT
- 장점
- page sharing/protection이 쉬움
- 메모리 관리 overhead 작음
- 단점
- address mapping 과정이 복잡함 (3배)
- 메모리 소모가 큼
맨 위로 이동하기
OS 카테고리 내 다른 글 보러가기
댓글 남기기