System
[OS] Address Translation
RealJuney
2024. 2. 3. 18:03
Hardware-based address translation: Instruction에 포함된 virtual address를 hardware가 physcial memory로 바꿔준다. 이 과정은 물론 OS의 도움도 필요하다. Hardware는 low-level 하고 빠른 mechanism만 제공할 뿐이다.
Simple Dynamic Hardware-based relocation (address translation)
문제: Address size가 phiscal memory보다 작고, 모든 process의 address size가 같은 제한 조건을 걸었을때 Virtual Memory (Address Translation)을 어떻게 구현할까?
1. Base and Bound (limit) registers
- physcial address = virutal address + base
- CPU가 위 과정을 계산해 준다.
- CPU가 virtual address가 bound (limit) register에 저장되어있는 최대 주소보다 작은지 확인한다.
- base & bound register는 MMU (Memory Management Unit)에 저장되어있다.
- MMU가 address translation에 관여한다
- CPU의 MMU당 base & bound가 한 쌍 존재하므로 context switching을 할때 메모리에 따로 저장해두는 과정이 필요하다.
2. CPU mode
- user mode / privileged mode 인지 processor status word 같은 곳에 저장해둔다
- hardware는 이 mode에 따라서 실행할 수 있는 instruction을 잘 관리해야한다.
3. OS 역할
- 프로세스가 생성될때 빈 physcial memory 공간을 찾아서 allocate 해준다.
- free list를 관리하여 빈 slot을 찾는다.
- 프로세스를 terminate시킬때 free list를 업데이트 해주고 관련 data structures들을 정리해준다.
- Context Switch가 일어날때 per-process structure 등에서 Process Control Block (PCB)등에 base-bound register들을 잘 저장해두어야한다. 또한 다시 돌아오는 경우 PCB에서 CPU의 base-bound register에 로드를 다시 해주어야한다.
- Process가 멈췄을땐 process의 address space를 physical memory 상에서 이동도 가능하다.
- 먼저 이동할 곳의 메모리에 원래 프로세스 데이터를 복사한다.
- 그 후 base-bound register들을 업데이트해준다. (이것은 Process Structure 어딘가에 보관되어 있을 것이다.)
- execption handler들을 제공해야한다.
- 이런 handler들은 boot time에 hardware에 install 시킨다.
- 예를 들어 CPU가 exception을 발생시키면 hardware는 boot time에 install된 handler의 위치를 찾아서 실행시킬 수 있다.