reference: kocw์ ๋ฐํจ๊ฒฝ ๊ต์๋ ๊ฐ์์ ๊ถ์ง์ฑ ๊ต์๋ ๊ฐ์(๋ํ ์ ๊ท ์์
)
์์
์ ๋ฃ๊ณ ๋์ ๊ฐ์ ๊ต์ฌ๋ฅผ ํ์ดํํ๊ณ ํ๊ธฐํ ๋ถ๋ถ์ ์ถ๊ฐ์ ์ผ๋ก ์ ๋ฆฌํ์์ต๋๋ค.
์น๋ทฐ์์ toc๋ฅผ ์ ๊ณตํฉ๋๋ค.
github์ md ํ์ผ๋ก ๋ณด๋ ๊ฒ ํธํ์๋ค๋ฉด, ์ฌ๊ธฐ๋ก ์ด๋ํด์ฃผ์๋ฉด ๋ฉ๋๋ค.
01 Logical vs Physical Address
Logical Address (Virtual Address)
- ํ๋ก์ธ์ค๋ง๋ค ๋ ๋ฆฝ์ ์ผ๋ก ๊ฐ์ง๋ ์ฃผ์ ๊ณต๊ฐ
- ๊ฐ ํ๋ก์ธ์ค๋ง๋ค 0๋ฒ์ง๋ถํฐ ์์
- CPU๊ฐ ๋ณด๋ ์ฃผ์๋ Logical Address
Physical Address
- ๋ฉ๋ชจ๋ฆฌ์ ์ค์ ์ฌ๋ผ๊ฐ๋ ์์น
02 ์ฃผ์ ๋ฐ์ธ๋ฉ (Address Binding)
์ฃผ์ ๋ฐ์ธ๋ฉ: ์ฃผ์๋ฅผ ๊ฒฐ์ ํ๋ ๊ฒ
- Symbolic Address → Logical Address → Physical Address
์ปดํ์ผ ์: (์๋ฐํ๊ฒ ๋งํ๋ฉด assembler์ ์ํด) ๋ ผ๋ฆฌ์ ์ฃผ์๋ฅผ ๊ฐ๋ ์คํ ํ์ผ์ด ์์ฑ
์คํ์์ ์: loader์ ์ํด physical address๊ฐ ํ ๋น๋จ
Compile time binding
- ๋ฌผ๋ฆฌ์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์๊ฐ ์ปดํ์ผ ์ ์ด๋ฏธ ์๋ ค์ง
- ์์ ์์น ๋ณ๊ฒฝ์ ์ฌ์ปดํ์ผ
- ์ปดํ์ผ๋ฌ๋ ์ ๋ ์ฝ๋(absolute code) ์์ฑ - ์ ๋ ์ ์์ง์ด๋๊น
Load time binding
- loader์ ์ฑ ์ํ์ ๋ฌผ๋ฆฌ์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์ ๋ถ์ฌ
- ์ปดํ์ผ๋ฌ๊ฐ ์ฌ๋ฐฐ์น๊ฐ๋ฅ ์ฝ๋ (relocatable code) ๋ฅผ ์์ฑํ ๊ฒฝ์ฐ ๊ฐ๋ฅ - ์๋ ์ฃผ์๋ ๊ณ ์ ๋๊ณ , ์ ๋ ์ฃผ์๋ ๋ณ๊ฒฝ ๊ฐ๋ฅ
Execution time binding (Run Time Binding)
- ์ํ์ด ์์๋ ์ดํ์๋ ํ๋ก์ธ์ค์ ๋ฉ๋ชจ๋ฆฌ ์ ์์น๋ฅผ ์ฎ๊ธธ ์ ์์
- CPU๊ฐ ์ฃผ์๋ฅผ ์ฐธ์กฐํ ๋๋ง๋ค Binding์ ์ ๊ฒ (Address Mapping Table - 300์๋๋ฐ ์ง๊ธ ์๋ฐ๊ผ๋ ์ ๊ฐ์ด ๋ฌผ์ด๋ด)
- ํ๋์จ์ด์ ์ธ ์ง์์ด ํ์
- (base limit registers, MMU)
03 Memory Management Unit (MMU)
Dynamic Relocation ์, Hardware Support for Address Translation
MMU (Memory Management Unit)
- Logical address๋ฅผ Physical Address๋ก ๋งคํํด ์ฃผ๋ Hardware device
MMU Scheme
- ์ฌ์ฉ์ ํ๋ก์ธ์ค๊ฐ CPU์์ ์ํ๋๋ฉฐ ์์ฑํด์ฃผ๋ ๋ชจ๋ ์ฃผ์๊ฐ์ ๋ํด (cpu๋ 0๋ฒ์ง์์๋ถํฐ ์์ํ๋ logical address๋ง ์๋ค) Base Register (= Relocation Register)์ ๊ฐ์ ๋ํ๋ค.
User Program
- Logical Address๋ง์ ๋ค๋ฃฌ๋ค.
- ์ค์ Physical Address๋ฅผ ๋ณผ ์ ์์ผ๋ฉฐ ์ ํ์๊ฐ ์๋ค.
์ด์์ฒด์ ๋ฐ ์ฌ์ฉ์ ํ๋ก์ธ์ค ๊ฐ์ ๋ฉ๋ชจ๋ฆฌ ๋ณดํธ๋ฅผ ์ํด ์ฌ์ฉํ๋ ๋ ์ง์คํฐ
- Relocation Register (Base Register): ์ ๊ทผํ ์ ์๋ ๋ฌผ๋ฆฌ์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์์ ์ต์๊ฐ
- Limit Register: ๋
ผ๋ฆฌ์ ์ฃผ์์ ๋ฒ์
- logical address < limit register๋ฅผ ๋ง์กฑํ์ง ๋ชปํ๋ฉด trap (software interrupt - exception ๋ฐ์)
- kernal์ด ๋ณดํต process๋ฅผ killํ๊ณ ์ฌ์ฉ์์๊ฒ segmentation fault๊ฐ ๋์ ํ๋ก๊ทธ๋จ์ด ๋๋ฌ์์ ์๋ฆฐ๋ค.
04 ์ฉ์ด ์ ๋ฆฌ
04-1 Dynamic Loading
- ํ๋ก์ธ์ค ์ ์ฒด๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ๋ฏธ๋ฆฌ ๋ค ์ฌ๋ฆฌ๋ ๊ฒ์ด ์๋๋ผ ํด๋น ๋ฃจํด์ด ๋ถ๋ ค์ง ๋ ๋ฉ๋ชจ๋ฆฌ์ loadํ๋ ๊ฒ
- Memory Utilization์ ํฅ์
- ๊ฐ๋์ฉ ์ฌ์ฉ๋๋ ๋ง์ ์์ ์ฝ๋์ ๊ฒฝ์ฐ ์ ์ฉ
- ex) ์ค๋ฅ ์ฒ๋ฆฌ ๋ฃจํด
- ์ด์์ฒด์ ์ ํน๋ณํ ์ง์ ์์ด ํ๋ก๊ทธ๋จ ์์ฒด์์ ๊ตฌํ ๊ฐ๋ฅ
- OS๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํตํด ์ง์ ๊ฐ๋ฅ. ์ฆ OS ์์ฒด์ ๊ธฐ๋ฅ์ ์๋
* Loading: ๋ฉ๋ชจ๋ฆฌ์ ๋ฐ์ดํฐ๋ฅผ ์ฌ๋ฆฌ๋ ๊ฒ
์ฌ๊ธฐ์ ๋งํ๋ Dynamic Loading์ ์ด์์ฒด์ ๊ฐ ํ๋ ๊ฒ์ด ์๋ ํ๋ก๊ทธ๋๋จธ๊ฐ ์งํํ๋ ๊ฒ์ ๋งํจ.
04-2 Dynamic Linking
- Linking์ ์คํ ์๊ฐ (Execution Time)๊น์ง ๋ฏธ๋ฃจ๋ ๊ธฐ๋ฒ
- Static Linking
- ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํ๋ก๊ทธ๋จ์ ์คํ ํ์ผ ์ฝ๋์ ํฌํจ๋จ
- ์คํ ํ์ผ์ ํฌ๊ธฐ๊ฐ ์ปค์ง
- ๋์ผํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ฐ๊ฐ์ ํ๋ก์ธ์ค๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ฆฌ๋ฏ๋ก ๋ฉ๋ชจ๋ฆฌ ๋ญ๋น
- ์) printf ํจ์์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฝ๋
- Dynamic Linking
- ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์คํ์ ์ฐ๊ฒฐ๋จ
- ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํธ์ถ ๋ถ๋ถ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฃจํด์ ์์น๋ฅผ ์ฐพ๊ธฐ ์ํ stub์ด๋ผ๋ ์์ ์ฝ๋๋ฅผ ๋
- ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ด๋ฏธ ๋ฉ๋ชจ๋ฆฌ์ ์์ผ๋ฉด ๊ทธ ๋ฃจํด์ ์ฃผ์๋ก ๊ฐ๊ณ ์์ผ๋ฉด ๋์คํฌ์์ ์ฝ์ด์ด
- ์ด์์ฒด์ ์ ๋์์ด ํ์
04-3 Overlays
- ๋ฉ๋ชจ๋ฆฌ์ ํ๋ก์ธ์ค์ ๋ถ๋ถ ์ค ์ค์ ํ์ํ ์ ๋ณด๋ง์ ์ฌ๋ฆผ
- ํ๋ก์ธ์ค์ ํฌ๊ธฐ๊ฐ ๋ฉ๋ชจ๋ฆฌ๋ณด๋ค ํด ๋ ์ ์ฉ
- ์ด์์ฒด์ ์ ์ง์์์ด ์ฌ์ฉ์์ ์ํด ๊ตฌํ
- ์์ ๊ณต๊ฐ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ์ด์ฐฝ๊ธฐ ์์คํ
์์ ์์์
์ผ๋ก ํ๋ก๊ทธ๋๋จธ๊ฐ ๊ตฌํ
- Manual Overlay ๋ผ๊ณ ๋ ๋ถ๋ฆ
- ํ๋ก๊ทธ๋๋ฐ์ด ๋งค์ฐ ๋ณต์ก
04-4 Swapping
- Swapping
- ํ๋ก์ธ์ค๋ฅผ ์ผ์์ ์ผ๋ก ๋ฉ๋ชจ๋ฆฌ์์ Backing Store๋ก ์ซ์๋ด๋ ๊ฒ
- paging๊ณผ ๋ค๋ฅด๊ฒ ํ๋ก์ธ์ค๊ฐ ํต์งธ๋ก ์์ง์.
- Backing Store (Swap area)
- ๋์คํฌ(disk): ๋ง์ ์ฌ์ฉ์์ ํ๋ก์ธ์ค ์ด๋ฏธ์ง๋ฅผ ๋ด์ ๋งํผ ์ถฉ๋ถํ ๋น ๋ฅด๊ณ ํฐ ์ ์ฅ ๊ณต๊ฐ
- Swap in / Swap out
- ์ผ๋ฐ์ ์ผ๋ก ์ค๊ธฐ ์ค์ผ์ฅด๋ฌ(swapper)์ ์ํด swap out ์ํฌ ํ๋ก์ธ์ค ์ ์
- priority-based CPU scheduling algorithm
- ์ฐ์ ์์๊ฐ ๋ฎ์ ํ๋ก์ธ์ค๋ฅผ swapped out ์ํด
- ์ฐ์ ์์๊ฐ ๋์ ํ๋ก์ธ์ค๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ ค ๋์
- Compile Time ํน์ Load time binding์์๋ ์๋ ๋ฉ๋ชจ๋ฆฌ ์์น๋ก swap in ํด์ผ ํจ
- Execution time binding์์๋ ์ถํ ๋น ๋ฉ๋ชจ๋ฆฌ ์์ญ ์๋ฌด ๊ณณ์๋ ์ฌ๋ฆด ์ ์์
- Swap Time์ ๋๋ถ๋ถ Transfer time (swap ๋๋ ์์ ๋น๋กํ๋ ์๊ฐ)์
05 Allocation of Physical Memory
- ๋ฉ๋ชจ๋ฆฌ๋ ์ผ๋ฐ์ ์ผ๋ก ๋ ์์ญ์ผ๋ก ๋๋์ด ์ฌ์ฉ
- OS ์์ฃผ ์์ญ: Interrupt Vector์ ํจ๊ป ๋ฎ์ ์ฃผ์ ์์ญ ์ฌ์ฉ
- ์ฌ์ฉ์ ํ๋ก์ธ์ค ์์ญ: ๋์ ์ฃผ์ ์์ญ ์ฌ์ฉ
- ์ฌ์ฉ์ ํ๋ก์ธ์ค ์์ญ์ ํ ๋น ๋ฐฉ๋ฒ
- Contiguous allocation
- ๊ฐ๊ฐ์ ํ๋ก์ธ์ค๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ์ฐ์์ ์ธ ๊ณต๊ฐ์ ์ ์ฌ๋๋๋ก ํ๋ ๊ฒ
- Fixed Partition Allocation - ๊ณ ์ ๋ถํ ๋ฐฉ์
- Variable Partition Allocation - ๊ฐ๋ณ ๋ถํ ๋ฐฉ์
- Noncontiguous allocation
- ํ๋์ ํ๋ก์ธ์ค๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ฌ ์์ญ์ ๋ถ์ฐ๋์ด ์ฌ๋ผ๊ฐ ์ ์์
- Paging
- Segmentation
- Paged Segmentation
- Contiguous allocation
์ด์ ๋ถํฐ ์ด ๋ด์ฉ์ ๋ํด ํจ์ฌ ์์ธํ๊ฒ ์ดํด๋ณผ ๊ฒ์ด๋ค !
์ด ๋ชฉ์ฐจ๋ฅผ ๊ธฐ์ตํ๊ธธ ๋ฐ๋๋ค.
06 Contiguous Allocation
06-1. ๊ณ ์ ๋ถํ (Fixed Partition) ๋ฐฉ์๊ณผ ๊ฐ๋ณ ๋ถํ (Variable Partition) ๋ฐฉ์
- ๊ณ ์ ๋ถํ (Fixed Partition) ๋ฐฉ์
- ๋ฌผ๋ฆฌ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋ช ๊ฐ์ ์๊ตฌ์ ๋ถํ (partition)๋ก ๋๋
- ๋ถํ ์ ํฌ๊ธฐ๊ฐ ๋ชจ๋ ๋์ผํ ๋ฐฉ์๊ณผ ์๋ก ๋ค๋ฅธ ๋ฐฉ์์ด ์กด์ฌ
- ๋ถํ ๋น ํ๋์ ํ๋ก๊ทธ๋จ ์ ์ฌ
- ์ตํต์ฑ์ด ์์
- ๋์์ ๋ฉ๋ชจ๋ฆฌ์ load๋๋ ํ๋ก๊ทธ๋จ์ ์๊ฐ ๊ณ ์ ๋จ (4๊ฐ์ ๋ถํ → ๋์์ ์ต๋ 4๊ฐ ํ๋ก๊ทธ๋จ ๋ก๋)
- ์ต๋ ์ํ ๊ฐ๋ฅ ํ๋ก๊ทธ๋จ ํฌ๊ธฐ ์ ํ
- Internal Fragmentation ๋ฐ์ (External Fragmentation๋ ๋ฐ์)
- ๊ฐ๋ณ ๋ถํ (Variable Partition) ๋ฐฉ์
- ํ๋ก๊ทธ๋จ์ ํฌ๊ธฐ๋ฅผ ๊ณ ๋ คํด์ ํ ๋น
- ๋ถํ ์ ํฌ๊ธฐ, ๊ฐ์๊ฐ ๋์ ์ผ๋ก ํ ๋น
- ๊ธฐ์ ์ ๊ด๋ฆฌ ๊ธฐ๋ฒ ํ์
- External Fragmentation ๋ฐ์
06-2. Fragmentation๊ณผ Hole
- fragmentation
- External fragmentation (์ธ๋ถ ์กฐ๊ฐ)
- ํ๋ก๊ทธ๋จ์ ํฌ๊ธฐ๋ณด๋ค ๋ถํ ์ ํฌ๊ธฐ๊ฐ ์์ ๊ฒฝ์ฐ
- ์๋ฌด ํ๋ก๊ทธ๋จ์๋ ๋ฐฐ์ ๋์ง ์์ ๋น ๊ณณ์ธ๋ฐ๋ ํ๋ก๊ทธ๋จ์ด ์ฌ๋ผ๊ฐ ์ ์๋ ์์ ๋ถํ
- Internal fragmentation (๋ด๋ถ ์กฐ๊ฐ)
- ํ๋ก๊ทธ๋จ ํฌ๊ธฐ๋ณด๋ค ๋ถํ ์ ํฌ๊ธฐ๊ฐ ํฐ ๊ฒฝ์ฐ
- ํ๋์ ๋ถํ ๋ด๋ถ์์ ๋ฐ์ํ๋ ์ฌ์ฉ๋์ง ์๋ ๋ฉ๋ชจ๋ฆฌ ์กฐ๊ฐ
- ํน์ ํ๋ก๊ทธ๋จ์ ๋ฐฐ์ ๋์์ง๋ง ์ฌ์ฉ๋์ง ์๋ ๊ณต๊ฐ
- External fragmentation (์ธ๋ถ ์กฐ๊ฐ)
- Hole
- ๊ฐ์ฉ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ
- ๋ค์ํ ํฌ๊ธฐ์ hole๋ค์ด ๋ฉ๋ชจ๋ฆฌ ์ฌ๋ฌ ๊ณณ์ ํฉ์ด์ ธ ์์
- ํ๋ก์ธ์ค๊ฐ ๋์ฐฉํ๋ฉด ์์ฉ๊ฐ๋ฅํ hole์ ํ ๋น
- ์ด์์ฒด์ ๋ ๋ค์์ ์ ๋ณด๋ฅผ ์ ์ง
- ํ ๋น ๊ณต๊ฐ
- ๊ฐ์ฉ ๊ณต๊ฐ (Hole)
๋์ ๋น์ทํ๋ฐ ๋์์ค๊ฐ ๋ค๋ฆ
fragmentation์ ์ฐ์ง ๋ชปํ๋ ๊ณต๊ฐ(๋ฉ๋ชจ๋ฆฌ ๋ญ๋น), hole๋ ์ธ ์ ์๋ ๊ณต๊ฐ
06-3. Dynamic Storage Allocation Problem
๊ฐ๋ณ ๋ถํ ๋ฐฉ์์์ Size n์ธ ์์ฒญ์ ๋ง์กฑํ๋ ๊ฐ์ฅ ์ ์ ํ hole์ ์ฐพ๋ ๋ฌธ์
- First-fit
- Size๊ฐ n์ด์์ธ ๊ฒ ์ค ์ต์ด๋ก ์ฐพ์์ง๋ hole์ ํ ๋น
- Best-fit
- Size๊ฐ n ์ด์์ธ ๊ฐ์ฅ ์์ hole์ ์ฐพ์์ ํ ๋น
- Hole๋ค์ ๋ฆฌ์คํธ๊ฐ ํฌ๊ธฐ์์ผ๋ก ์ ๋ ฌ๋์ง ์์ ๊ฒฝ์ฐ ๋ชจ๋ hole์ ๋ฆฌ์คํธ๋ฅผ ํ์ํด์ผํจ
- ๋ง์ ์์ ์์ฃผ ์์ hole๋ค์ด ์์ฑ๋จ
- Worst-fit
- ๊ฐ์ฅ ํฐ hole์ ํ ๋น
- ์ญ์ ๋ชจ๋ ๋ฆฌ์คํธ๋ฅผ ํ์ํด์ผ ํจ
- ์๋์ ์ผ๋ก ์์ฃผ ํฐ hole๋ค์ด ์์ฑ๋จ
์คํ์ ์ผ๋ก first-fit์ด๋ best-fit์ด worst-fit๋ณด๋ค ์๋์ ๊ณต๊ฐ ์ด์ฉ์ ์ธก๋ฉด์์ ํจ๊ณผ์ ์ธ ๊ฒ์ผ๋ก ์๋ ค์ง
06-4. Compaction (๋ญ์นจ)
- External Fragmentation ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ํ๊ฐ์ง ๋ฐฉ๋ฒ
- ์ฌ์ฉ ์ค์ธ ๋ฉ๋ชจ๋ฆฌ ์์ญ์ ํ๊ตฐ๋ฐ๋ก ๋ชฐ๊ณ hole๋ค์ ๋ค๋ฅธ ํ ๊ณณ์ผ๋ก ๋ชฐ์ ํฐ block์ ๋ง๋๋ ๊ฒ
- Compaction์ ํ๋ก์ธ์ค์ ์ฃผ์๊ฐ ์คํ ์๊ฐ์ ๋์ ์ผ๋ก ์ฌ๋ฐฐ์น ๊ฐ๋ฅํ ๊ฒฝ์ฐ์๋ง ์ค์ํ ์ ์๋ค.
- ์ฆ, Execution time binding (=run time binding)์์ ์ ์ฉ ๊ฐ๋ฅ
- ๋งค์ฐ ๋น์ฉ์ด ๋ง์ด ๋๋ ๋ฐฉ๋ฒ์
- ์ต์ํ์ ๋ฉ๋ชจ๋ฆฌ ์ด๋์ผ๋ก compactionํ๋ ๋ฐฉ๋ฒ์ ๋งค์ฐ ๋ณต์กํ ๋ฌธ์
07 Paging
07-1. paging์ ๊ธฐ๋ณธ
Paging
- Process์ virtual memory (logical memory)๋ฅผ ๋์ผํ ์ฌ์ด์ฆ์ page ๋จ์๋ก ๋๋
- Virtual Memory์ ๋ด์ฉ์ด Page ๋จ์๋ก noncontiguousํ๊ฒ ์ ์ฅ๋จ
- ์ผ๋ถ๋ backing storage์, ์ผ๋ถ๋ physical memory์ ์ ์ฅ
Basic Method
- physical memory๋ฅผ ๋์ผํ ํฌ๊ธฐ์ frame์ผ๋ก ๋๋
- logical memory๋ฅผ ๋์ผ ํฌ๊ธฐ์ page๋ก ๋๋
- ๋ชจ๋ ๊ฐ์ฉ ํ๋ ์๋ค์ ๊ด๋ฆฌ
- page table์ ์ฌ์ฉํ์ฌ logical address๋ฅผ physical address๋ก ๋ณํ
- external fragmentation ๋ฐ์ ์ํจ (page์ frame ์ฌ์ด์ฆ๊ฐ ๊ฐ๊ธฐ์ ์ด๋๋ ๋ฃ์ ์ ์์)
- internal fragmentation ๋ฐ์ ๊ฐ๋ฅ (๋ง์ง๋ง์ผ๋ก ์๋ฆฐ ํ์ด์ง๋ ๋ชจ๋ ๊ณต๊ฐ์ ์ฌ์ฉํ์ง ์์ ์ ์์)
07-2. Address Translation
page number๋ฅผ frame number๋ก ๋ณํํ์ฌ physical address ๊ณ์ฐ์ ํ์ฌ ์ ๊ทผํ ์ ์๋ค.
- CPU <page number (p), page offset (d)> ์ด ๋ ๊ฐ์ง๋ก ๊ตฌ์ฑ๋ virtual address๋ฅผ ์ฌ์ฉํ๋ค.
- page number (p)
- page table์ index๋ก ์ฌ์ฉ
- ํด๋น index์๋ ๊ทธ ํ์ด์ง์ ๋ฌผ๋ฆฌ์ ๋ฉ๋ชจ๋ฆฌ ์์ base address๊ฐ ์ ์ฅ๋จ
- page offset (d)
- base address ์ ๋ํด์ ธ์ physical address ๊ฐ ๊ตฌํด์ง
- page number (p)
07-3. Implementation of Page Table
- page table์ main memory์ ์์ฃผ
- Page-Table Base Register (PTBR)๊ฐ Page Table์ ๊ฐ๋ฆฌํด
- Page-Table Length Register (PTLR)๊ฐ ํ ์ด๋ธ ํฌ๊ธฐ๋ฅผ ๋ณด๊ด
- ๋ชจ๋ ๋ฉ๋ชจ๋ฆฌ ์ ๊ทผ ์ฐ์ฐ์๋ 2๋ฒ์ memory access ํ์
- Page Table ์ ๊ทผ 1๋ฒ + ์ค์ data/Instruction ์ ๊ทผ 1๋ฒ
- ์๋ ํฅ์์ ์ํด associative register ํน์ translation lock-aside buffer(TLB)๋ผ ๋ถ๋ฆฌ๋ ๊ณ ์์ lookup hardware cache ์ฌ์ฉ
Associative registers (TLB) : parallel search๊ฐ ๊ฐ๋ฅ
- TLB์๋ page Table ์ค ์ผ๋ถ๋ง ์กด์ฌ
- TLB์ Address Translation
- page table ์ค ์ผ๋ถ๊ฐ associative register์ ๋ณด๊ด๋์ด ์์
- ๋ง์ฝ ํด๋น page num๊ฐ associative register์ ์๋ ๊ฒฝ์ฐ ๊ณง๋ฐ๋ก frame # num์ ์ป์
- ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ main memory์ ์๋ page table๋ก ๋ถํฐ frame # num์ ์ป์
- TLB๋ context switch ๋ flush (remove old entries)
07-4. Effective Access Time
Associative register lookup time = e
memory cycle time = 1
Hit ratio = a (associative register์์ ์ฐพ์์ง๋ ๋น์จ)
Effective Access Time = (1 + e)a + (2 + e)(1 - a)
---> 2 + e - a
07-5. 2 Level page table
page table์ ์ํ ๊ณต๊ฐ์ ์ค์ด๊ธฐ ์ํด ์ฌ์ฉ
ํ๋์ ์ปดํจํฐ๋ address space๊ฐ ๋งค์ฐ ํฐ ํ๋ก๊ทธ๋จ์ ์ง์
- 32 bit address ์ฌ์ฉ์ → 2^32 (4GB)์ ์ฃผ์ ๊ณต๊ฐ
- Page Size๊ฐ 4K (2^(2+10))์ 1M (2^20)๊ฐ์ page table entry๊ฐ ํ์
- ๊ฐ page entry๊ฐ 4B ์ ํ๋ก์ธ์ค ๋น (page table entry ์ * page entry size) 4M ์ page table ํ์
- ๊ทธ๋ฌ๋ ๋๋ถ๋ถ์ ํ๋ก๊ทธ๋จ์ 4G์ ์ฃผ์ ๊ณต๊ฐ ์ค ์ง๊ทนํ ์ผ๋ถ๋ถ๋ง ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ page table ๊ณต๊ฐ์ด ์ฌํ๊ฒ ๋ญ๋น๋จ
→ ํ์ด์ง ํ ์ด๋ธ ์์ฒด๋ฅผ ํ์ด์ง๋ก ๊ตฌ์ฑ
→ ์ฌ์ฉ๋์ง ์๋ ์ฃผ์ ๊ณต๊ฐ์ ๋ํ outer page table์ ์ํธ๋ฆฌ ๊ฐ์ NULL (๋์ํ๋ inner page table์ด ์์)
์์
- p1์ outer page table์ index(page number)์ด๊ณ
- p2๋ outer page table์ page์์์ ๋ณ์(displacement) (page offset)
Multilevel Paging and Performance
- Address Space๊ฐ ๋ ์ปค์ง๋ฉด ๋ค๋จ๊ณ ํ์ด์ง ํ ์ด๋ธ ํ์
- ๊ฐ ๋จ๊ณ์ ํ์ด์ง ํ ์ด๋ธ์ด ๋ฉ๋ชจ๋ฆฌ์ ์กด์ฌํ๋ฏ๋ก Logical address์ physical address ๋ณํ์ ๋ ๋ง์ ๋ฉ๋ชจ๋ฆฌ ์ ๊ทผ ํ์
- TLB๋ฅผ ํตํด ๋ฉ๋ชจ๋ฆฌ ์ ๊ทผ ์๊ฐ์ ์ค์ผ ์ ์์
- 4๋จ๊ณ ํ์ด์ง ํ
์ด๋ธ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ
- ๋ฉ๋ชจ๋ฆฌ ์ ๊ทผ ์๊ฐ์ด 100ns, TLB ์ ๊ทผ ์๊ฐ์ด 20ns, hit ratio๊ฐ 98%์ธ ๊ฒฝ์ฐ
- effective memory access time = 0.98 * 120 + 0.02 * 520(=(4+1)*100ns+20ns) → 128ns
- ๊ฒฐ๊ณผ์ ์ผ๋ก ์ฃผ์๋ณํ์ ์ํด 28ns๋ง ์์
- ๋ฉ๋ชจ๋ฆฌ ์ ๊ทผ ์๊ฐ์ด 100ns, TLB ์ ๊ทผ ์๊ฐ์ด 20ns, hit ratio๊ฐ 98%์ธ ๊ฒฝ์ฐ
07-7. Memory Protection
Page Table์ ๊ฐ entry๋ง๋ค ์๋์ bit๋ฅผ ๋๋ค.
- Protection bit
- Page์ ๋ํ ์ ๊ทผ ๊ถํ (read/write/read-only)
- Valid-invalid bit
- valid๋ ํด๋น ์ฃผ์์ frame์ ๊ทธ ํ๋ก์ธ์ค๋ฅผ ๊ตฌ์ฑํ๋ ์ ํจํ ๋ด์ฉ์ด ์์์ ๋ปํจ (์ ๊ทผ ํ์ฉ)
- invalid๋ ํด๋น ์ฃผ์์ frame์ ์ ํจํ ๋ด์ฉ์ด ์์์ ๋ปํจ (์ ๊ทผ ๋ถํ)
- ํ๋ก์ธ์ค๊ฐ ๊ทธ ์ฃผ์ ๋ถ๋ถ์ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ
- ํด๋น ํ์ด์ง๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ผ์ ์์ง ์๊ณ swap area์ ์๋ ๊ฒฝ์ฐ
07-8. Inverted Page Table
Page Table์ด ๋งค์ฐ ํฐ ์ด์
- ๋ชจ๋ process ๋ณ๋ก ๊ทธ logical address์ ๋์ํ๋ ๋ชจ๋ page์ ๋ํด page table entry๊ฐ ์กด๋
- ๋์ํ๋ page๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ์๋ ์๋๋ ๊ฐ์ page table์๋ entry๋ก ์กด์ฌ
Inverted Page table
- Page frame ํ๋๋น page table์ ํ๋์ entry๋ฅผ ๋ ๊ฒ ( system - wide )
- ๊ฐ page table entry๋ ๊ฐ๊ฐ์ ๋ฌผ๋ฆฌ์ ๋ฉ๋ชจ๋ฆฌ์ page frame์ด ๋ด๊ณ ์๋ ๋ด์ฉ ํ์ (process-id, process์ logiscal address)
- ๋จ์ : ํ ์ด๋ธ ์ ์ฒด๋ฅผ ํ์ํด์ผํจ
- ์กฐ์น : associative register ์ฌ์ฉ (expensive)
07-9. Shared Page
Shared code
- Re-entrant Code (=Pure code) : ์๋์ ๋ ์กฐ๊ฑด์ ๋ง์กฑํด์ผํจ
- read only๋ก ํ์ฌ ํ๋ก์ธ์ค ๊ฐ์ ํ๋์ code๋ง ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ฆผ
- Shared code๋ ๋ชจ๋ ํ๋ก์ธ์ค์ logical address space์์ ๋์ผํ ์์น์ ์์ด์ผ ํจ
Private Code and Data
- ๊ฐ ํ๋ก์ธ์ค๋ค์ ๋ ์์ ์ผ๋ก ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ฆผ
- Private data๋ logical address space์ ์๋ฌด๊ณณ์ ์๋ ๋ฌด๋ฐฉ
08 Segmentation
08-1. Segment
ํ๋ก๊ทธ๋จ์ ์๋ฏธ ๋จ์์ธ ์ฌ๋ฌ ๊ฐ์ segment๋ก ๊ตฌ์ฑ (↔ page๋ ๋์ผํ ํฌ๊ธฐ ๋จ์)
- ์๊ฒ๋ ํ๋ก๊ทธ๋จ์ ๊ตฌ์ฑํ๋ ํจ์ ํ๋ํ๋๋ฅผ ์ธ๊ทธ๋จผํธ๋ก ์ ์
- ํฌ๊ฒ๋ ํ๋ก๊ทธ๋จ ์ ์ฒด๋ฅผ ํ๋์ ์ธ๊ทธ๋จผํธ๋ก ์ ์ ๊ฐ๋ฅ
- ์ผ๋ฐ์ ์ผ๋ก๋ code, data, stack ๋ถ๋ถ์ด ํ๋์ฉ์ ์ธ๊ทธ๋จผํธ๋ก ์ ์๋จ
- ํ๋ก์ธ์ค๋ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ด code, data, stack์ผ๋ก ๋๋์ด์ ธ ์์.
segment๋ ๋ค์๊ณผ ๊ฐ์ logical unit ๋ค์. ๋ค์ํ ํฌ๊ธฐ์ ๋ฌถ๋ ๋ฐฉ๋ฒ์ด ์์ ์ ์์.
- main(), function, global variables, stack, symbol table, arrays
08-2. Segmentation Architecture
- ๐ ๋ ผ๋ฆฌ์ ์ฃผ์๋ segment-number (2๋ฒ segment), offset (100๋ฒ์ง) ์ผ๋ก ๊ตฌ์ฑ๋จ
- ๐ Segment table
- each table entry has:
- limit: length of the segment (2๋ฒ segment์ size)
- base: starting physical address of the segment (2๋ฒ segment์ physical ์์ ๋ฒ์ง)
- each table entry has:
- ๐ segment table base register (STBR)
- ๋ฌผ๋ฆฌ์ ๋ฉ๋ชจ๋ฆฌ์์์ segment table์ ์์น
- ๐ segment table length register (STLR)
- ํ๋ก๊ทธ๋จ์ด ์ฌ์ฉํ๋ segment์ ์
- segment number s is legal if s < STLR.
- ์ ๋๋ฑ์ด ์๋๋? segment ๊ฐ์๊ฐ 5๊ฐ (STLR = 5)์ผ ๋, s๋ 0~4 ๊ฐ์ด ๊ฐ๋ฅ
*** segment์ ๊ธธ์ด๊ฐ ๋์ผํ์ง ์์ผ๋ฏ๋ก ๊ฐ๋ณ๋ถํ ๋ฐฉ์์์์ ๋์ผํ ๋ฌธ์ ์ ๋ค์ด ๋ฐ์ํ๋ค.
- ๐ Allocation
- first-fit / best fit
- ๋จ์ : external fragementation ๋ฐ์
*** segment๋ ์๋ฏธ ๋จ์์ด๊ธฐ ๋๋ฌธ์ ๊ณต์ ์ ๋ณด์์ ์์ด paging๋ณด๋ค ํจ์ฌ ํจ๊ณผ์ ์ด๋ค.
- ๐ Protection
- ๊ฐ ์ธ๊ทธ๋จผํธ ๋ณ๋ก protection bit๊ฐ ์์ -
- Each entry:
- Valid bit = 0 → illegal segment
- Read/Write/Execution ๊ถํ bit
- ๐ Sharing
- shared segment
- same segment number
08-3. Segmentation with Paging
ํฐ ํ์ segment๋ก ๋๋ด๋๋ฐ, segment ์์ page๋ก ๋๋ ๋ฐฉ์์ด๋ค.
pure segmentation ๊ณผ์ ์ฐจ์ด์
- segment-table entry๊ฐsegment๋ฅผ ๊ตฌ์ฑํ๋ page table์ base address๋ฅผ ๊ฐ์ง๊ณ ์์
- segment์ base address๋ฅผ ๊ฐ์ง๊ณ ์๋ ๊ฒ์ด ์๋๋ผ
์ฅ์
- segment๊ฐ 4K ๋ฐฐ์๋งํผ ์์ง์ด๊ธฐ ๋๋ฌธ์ fragmentation์ด ์ค์ด๋ฆ.
๋จ์
- ๋ณต์กํ ๊ตฌ์กฐ(logic) → bug ๊ฐ๋ฅ์ฑ์ด ์ฆ๊ฐํ๊ณ ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ์ ์ํฅ
- fragmentation์ด ๋ฐ์ํ๊ธด ํจ
<์์ ๊ทธ๋ฆผ ์ค๋ช >
segment number๊ณผ offset(d)๋ฅผ cpu๊ฐ ์์ฒญํ๋ฉด
STBR์ ๊ฐ์ ์ด์ฉํ์ฌ segment table์ ์ ๊ทผํด์ ์์ฒญํ segment number์ ์ ํ(๊ธธ์ด)๊ณผ page-table์ base ๊ฐ์ ์์๋ธ๋ค.
(segment table์ STBR + segment number๋ก ์ ๊ทผํ๋ฏ์ด page-table์ base ๊ฐ์ ์์๋ธ ๊ฒ์ด๋ค. ๊ทธ๋ฆฌ๊ณ ๊ฐ segment๋ ๋ค๋ฅธ page table์ ์ฐธ์กฐํ๋ค๋ ๊ฒ์ ์ ์ ์๋ค.)
offset์ ํด๋น segment์ limit๊ณผ ๋น๊ตํ ํ legalํ๋ค๋ฉด (segment์) offset๋ฅผ ๋ค์ page number์ sub-offset ๋ฒํธ๋ก ๋๋๋ค.
page table์ base ๊ฐ์ page number์ ๋ํด ์ฐพ๊ฒ ๋ frame๊ณผ sub-offset ์ผ๋ก ์ํ๋ ๋ฉ๋ชจ๋ฆฌ์ ์ ๊ทผํ ์ ์๊ฒ ๋๋ค.
์ ๋ฆฌํ์๋ฉด, segment number๋ก segment table์ ํตํด ์ํ๋ ํ์ด์ง ํ ์ด๋ธ์ ์ฐพ๋๋ค.
offset์ผ๋ก ๋ช ๋ฒ์งธ page(frame), ์ด๋์ ์กด์ฌํ๋์ง ์์๋ธ๋ค.
'OS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
11์ฅ File Systems Implementation (0) | 2021.06.19 |
---|---|
10์ฅ File Systems (0) | 2021.06.19 |
9์ฅ Virtual Memory (0) | 2021.06.19 |
7์ฅ Deadlock (0) | 2021.06.19 |
6์ฅ Process Synchronization (0) | 2021.06.19 |
5์ฅ CPU scheduling (0) | 2021.06.18 |