-
9. Virtual Memory advantages and paging algorithmCS/OS 2022. 6. 23. 17:12
Virtual Memory Advantage
1. Shared Memory ( window dll , linux so .. )
Multiple Process 간의 communication의 방법으로 공유 메모리를 사용할 수 있는데, demand-paging 기법을 사용할 경우 다른 프로세스의 각각의 페이지가 같은 프레임을 가리키도록 하면 공유 메모리를 사용할 수 있다.
아래 그림을 보면 Process A의 Page1과 Process B의 Page7은 서로 같은 Memory를 가르키고 있어 공유가 가능하다.
dll in window 혹은 so in linux 이 방식으로 Physical Memory Frame을 같이 가리켜, Memory save
2. COW(Copy on Write)
Fork System call을 통하여 Parent Process가 Child Process를 생성하는데, 같은 Memory를 1. Shared Memory와 같은 방식으로 사용하다가, Write를 하는 경우에 Memory를 Copy 하여 사용한다.
3. Memory Mapped File
File System I/O
Open(), read(), write() system call을 사용하여 file 에 매번 접근될 때마다 system call을 해야 하고 디스크를 접근해야 한다.
Memory Mapped File
File을 접근하는 것을 메모리 접근하듯이 페이지를 할당하여 할 수 있도록 하는 것이며, 메모리 접근 속도가 훨씬 더 빠르므로 효율적이라 할 수 있다.
- access a file = read()
- The file contents 는 disk 에서 kernel’s buffer cache
- The data must be copied again into the process’s user-mode memory for access
https://w3.cs.jmu.edu/kirkpams/OpenCSF/Books/csf/html/MMap.html
https://stackoverflow.com/questions/26456195/why-is-reading-from-a-memory-mapped-file-so-fast
Virtual Memory 단점
Thrashing
Virtual Memory를 사용하다 보면 메모리 공간을 크게 사용할 수 있어 효율적이지만, Degree를 계속 높이다보면 Page replacement하는데 Time이 많이 소요가 되어 Page change 하는데 너무 많은 시간이 걸리는 것을 의미
Memory를 늘리던지, Working set model 방식을 사용하면 된다.
Paging Algorithm
1. FIFO
Fisrt In First Out
Queue와 동일하게 먼저 온 것부터 Page를 교체하여 준다.
2. LRU
Least recent used
가장 오래 되지 않은 Page를 Page-Out
3. LRU Approximation
LRU 알고리즘에 Hardware reference bit를 사용한다고 한다.
제일 빠르고 좋다고 한다.
4. Counting
Page가 Referenced 될 때 마다 갯수를 세어 관리
MFU / LFS가 존재한다.
'CS > OS' 카테고리의 다른 글
11. Cache&Block (0) 2022.08.08 10 . File System (0) 2022.08.08 8. Vitrual Memory (0) 2022.06.23 xv6 Test code (0) 2022.06.02 xv6 (linux Init) (0) 2022.06.02