수정입니다
15. Address Translation 본문
Memory Virtualization with Efficiency and Control
- CPU virtualization을 실행할 때 hardware의 도움을 받아서 한 프로세스가 일정시간동안 수행하고, 다른 프로세서가 또 일정시간동안 수행하게 하는 limited direct execution(LDE) 라는 환경을 만듬
- 이렇게 하면서 CPU 가상화의 efficiency와 control을 높일 수 있었음
- memry virtualization도 비슷하게, hardware의 도움(reg, TLB, page-table)을 이용하여, 한 프로세스가 다른 프로세스의 address space를 침범하지 못하도록 함.
Address Translation
- hardware가 virtual address를 physical address로 바꿔줌 (sw가 하면 느리다)
- OS는 hardware가 변환할 때 필요한 정보를 제공해 줌(physical 주소 같은..)
Example : Address Translation
void func()
int x = 3;
x = x + 3;
- x는 address space의 stack에 저장되어 있음
- x = x + 3를 만나면 이 명령이 세개의 assmbly code로 변환이 됨.
- load : address space에 있는 x 값을 cpu의 register로 load 함
- increment : cpu의 ALU를 이용하여 계산
- store : 계산한 값을 다시 memory로 보냄
# Assembly
//intel
128 : movl 0x0(%ebx), %eax // load 0+ebs into eax
132 : addl $0x03, %eax // add 3 to eax register
135 : movl %eax, 0x0(%ebx) // store eax back to mem
//ARM
ldr r0 [r1] // r0 reg에 r1 reg가 담고 있는 값 load
add r0, r0, #3 // r0 reg에 +3 연산
str r0 [r1] // r0 reg가 담고 있는 값을 r1 reg에 store
- 결과적으로 pc에 insturction을 fetch하고, 이걸 decode하고, execute하는데에 총 메모리 5번 접근
- 1. 첫번째 inst fetch
- 2. load 명령 수행
- 3. 두번째 inst fetch
- x - ALU는 memory 접근 x
- 4. 세번째 inst fetch
- 5. store 명령 수행
Relocation Address Space
- OS는 process를 physical memory에 어떤 부분에 위치시키는데, 0번지는 사용하지 않음
A single Relocated Process & base, bound register
- base register : physical memory의 실제 시작 주소를 담는 register
- bound register : address space의 크기를 담는 register(phsical mem의 끝 주소를 담기도 함)
Dynamic(Hardware base) Relocation
- program이 시작되면, OS는 이 process를 physical의 어디에 위치시킬지 결정해야함
- set the base register a value
physical address = virtual address + base
- 모든 virtual address는 0보다 크거나 같고 bound보다 작아야함
0 ≤ virtual address < bounds
Relocation and Address Translation
- virtual의 128번지 inst를 fetch 한다고 해보자
physical => 128 + 32KB(base) = 128 + 32 * 2^10 = 128 + 32768 = 32896
- 이후 load 명령 execute (15KB)
physical => 15KB + 32KB = 47KB
Two ways of Bounds Register
- the size of address space
- phsical address of the end of address space
=> 그니까 base가 32면, addr space 크기인 16일지, 32+16 = 48 해서 48일지 잘 체크하기
OS Issues for Memory Virtualization
- OS는 3가지 critical moment에서 적절한 action을 취해야 한다.
- process가 실행을 시작 할 때, 빈공간을 찾아줘야 함(relocaton을 하는 것)
- process가 끝날 때, memory에서 reclaiming 해줘야 함
- context switch 할 때 base-and-bound를 saving & restoring 해줘야 함
=> base,bound는 cpu내 한 쌍밖에 없으므로, context switching 시 각 프로세스의 PCB에 base-and-bound를 저장함
=> memory에 관련된 register의 내용을 바꿔주는 것이 process의 address space를 바꾸는 방법이다.
OS Issues: When a Process Starts Running
- OS가 free list를 보고, 하나를 픽 해서 relocation
- free list는 현재 physical memory에서 사용되지 않고 있는 공간의 list
OS Issues: When a Process Is Terminated
- OS가 사용하지 않는, free된 공간을 free list에 다시 집어 넣어 줘야함
OS Issues: When Context Switch Occurs
- OS는 base-bound pair를 save, restore 해줘야 한다.. => PCB 이용
'전공 > 운영체제' 카테고리의 다른 글
17. Free-Space Management (1) | 2024.01.11 |
---|---|
16. Segmentation (2) | 2024.01.09 |
14. Memory API (0) | 2024.01.04 |
13. The Abstraction: Address Space (1) | 2024.01.04 |
10. Multiprocessor Scheduling(Advanced) (0) | 2024.01.01 |