Skip to content

Commit

Permalink
lecture cache
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Dec 17, 2024
1 parent b615ebc commit 9d44b7f
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "์šด์˜์ฒด์ œ ์ด๊ฒƒ์ €๊ฒƒ ๋ฉ”๋ชจ๋“ค (final)"
title: "[OS] Virtual Memory"
toc: true
toc_sticky: true
categories: ["Operating System"]
Expand Down Expand Up @@ -138,9 +138,15 @@ process์—์„œ `fork()`๋ฅผ ์‹คํ–‰ํ•˜๋ฉด, ๋ชจ๋“  ๊ฒƒ์ด ๋˜‘๊ฐ™์€ ๋ณต์ œ๋ณธ์„ ๋งŒ
- ํŽ˜์ด์ง€ ํฌ๊ธฐ๋Š” 4 Kb ($2^12$)
- offset bit๊ฐ€ 12 bit๋กœ ๊ณ ์ •
- 32-bit ์‹œ์Šคํ…œ์€ 2๋‹จ๊ณ„ ํŽ˜์ด์ง€ ํ…Œ์ด๋ธ”๋กœ ๋‚˜๋ˆ”
- $2^32 = 2^10 \cdot 2^10 \cdot 2^12$
- $2^{32} = 2^{10} \cdot 2^{10} \cdot 2^{12}$
- 64-bit ์‹œ์Šคํ…œ์€ 4๋‹จ๊ณ„ ํŽ˜์ด์ง€ ํ…Œ์ด๋ธ”๋กœ ๋‚˜๋ˆ”
- $2^64 = 2^32 \cdot 2^10 \cdot 2^10 \cdot 2^12$
- $2^{64} = 2^{32} \cdot 2^{10} \cdot 2^{10} \cdot 2^{12}$

# Kernel Memory is not swapped out

์ปค๋„ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ Demand Paging์˜ ๋Œ€์ƒ์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ฆ‰, ์ง€๊ธˆ๊นŒ์ง€ Paging๊ณผ ๊ด€๋ จ๋˜์–ด ์‚ดํŽด๋ณธ ๋ชจ๋“  ๊ฒƒ์€ User ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์— ๋Œ€ํ•œ ํ…Œํฌ๋‹‰ ์ž…๋‹ˆ๋‹ค.

์ปค๋„์˜ ๋™์ž‘์€ ํ•ญ์ƒ ์‹ ์†ํ•˜๊ฒŒ ์ˆ˜ํ–‰ ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋””์Šคํฌ์— ๋‚ด๋ฆฌ๊ฑฐ๋‚˜ ์˜ฌ๋ฆฌ๋Š” Demand Paging ๊ธฐ๋ฒ•์€ ์ปค๋„ ๋™์ž‘์„ ๋Š๋ฆฌ๊ฒŒ ๋งŒ๋“ค์–ด ์ „์ฒด ์‹œ์Šคํ…œ์˜ ํผํฌ๋จผ์Šค๋ฅผ ๋–จ์–ด๋œจ๋ฆฌ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, ์ปค๋„ ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ์€ ๋ฌผ๋ฆฌ ๋ฉ”๋ชจ๋ฆฌ์— ์ƒ์ฃผ(resident)ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

# Page Address Extension

Expand All @@ -150,7 +156,37 @@ PAE

# Slab Allocator

์Œ... ๋ญ”๊ฐ€ ์š”๊ฒŒ ์ž˜ ์ดํ•ด๊ฐ€ ์•ˆ ๋˜๋„น
์ปค๋„ ๊ฐ์ฒด๋“ค์„ ๋Œ€์ƒ์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.

`PCB`๋‚˜ `inode`์™€ ๊ฐ™์€ ์ปค๋„ ๊ฐ์ฒด๋“ค์„ ํ”„๋กœ๊ทธ๋žจ์„ ์šด์˜ํ•˜๋ฉด์„œ ์ž์ฃผ ํ• ๋‹น ๋˜๊ฑฐ๋‚˜ ํ• ๋‹น ํ•ด์ œ ๋ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ `PCB` ํ•˜๋‚˜๋ฅผ ์ƒ์„ฑํ•  ๋•Œ๋งˆ๋‹ค, Page๋ฅผ ํ•˜๋‚˜ ํ• ๋‹น ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, ์ด๊ฒƒ์€ ๋น„ํšจ์œจ์ ์ด๊ณ  ๋‚ด๋ถ€ ๋‹จํŽธํ™”๊ฐ€ ์ผ์–ด๋‚˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๊ฐ™์€ ์ข…๋ฅ˜์˜ ๊ฐ์ฒด๋ฅผ ํ•˜๋‚˜์˜ ํŽ˜์ด์ง€์— ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋Š” ์Šฌ๋žฉ(slab)์„ ์šด์˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ๋ฅผ ํ†ตํ•ด ์ดํ•ด ํ•ด๋ด…์‹œ๋‹ค. ํŒŒ์ผ ์‹œ์Šคํ…œ์—์„œ ํŒŒ์ผ์ด๋‚˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” `inode`๋ผ๋Š” ๊ตฌ์กฐ์ฒด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์˜ ํฌ๊ธฐ๊ฐ€ 128 ๋ฐ”์ดํŠธ๋ผ๊ณ  ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๋งŒ์•ฝ Slab Allocator๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด, `inode` ๊ฐ์ฒด๋ฅผ ํ• ๋‹นํ•˜๊ธฐ ์œ„ํ•œ ํ• ๋‹น ์š”์ฒญ์„ ํ•  ๊ฒƒ ์ž…๋‹ˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ๋Š” ๋ฒ„๋”” ์‹œ์Šคํ…œ์— ์˜ํ•ด ํ• ๋‹น ๋˜๋Š”๋ฐ, `inode`๋Š” 128 ๋ฐ”์ดํŠธ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ตœ์†Œ ๋‹จ์œ„์ธ 4 Kb์˜ ํŽ˜์ด์ง€ ํ•˜๋‚˜๊ฐ€ ํ• ๋‹น ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด 3 Kb ์ •๋„์˜ ๋‚จ์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋‚ญ๋น„ ๋˜๊ณ , ์ด๋Š” ๋‚ด๋ถ€ ๋‹จํŽธํ™”๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

Slab Allocator๋Š” `inode` ์‚ฌ์ด์ฆˆ์— ๋งž๋Š” 128 ๋ฐ”์ดํŠธ ํฌ๊ธฐ๋ฅผ ์œ„ํ•œ ๋ฉ”๋ชจ๋ฆฌ ๋ธ”๋ก์„ ๋ฏธ๋ฆฌ ์ค€๋น„ํ•˜๊ณ  ์ด๋ฅผ "์Šฌ๋žฉ"์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์Šฌ๋žฉ์€ 4 Kb ํŽ˜์ด์ง€ ํ•˜๋‚˜๋ฅผ ์—ฌ๋Ÿฌ 128 ๋ฐ”์ดํŠธ ๊ฐ์ฒด๋กœ ๋‚˜๋ˆ„์–ด ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์ƒˆ๋กœ์šด `inode` ํ• ๋‹น ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด, OS๋Š” ์Šฌ๋žฉ์— ๋ฏธ๋ฆฌ ์ค€๋น„๋œ 128 ๋ฐ”์ดํŠธ ์Šฌ๋กฏ์„ ํ•˜๋‚˜ ๊บผ๋‚ด๊ณ , ๊ทธ ์Šฌ๋กฏ์— `inode` ๊ฐ์ฒด๋ฅผ ํ• ๋‹น ํ•ฉ๋‹ˆ๋‹ค.

# Buddy System vs. Slab Allocator

Buddy System๊ณผ Slab Allocator๋Š” ๋ฐฐํƒ€์ ์ด์ง€ ์•Š๊ณ , ๋‘˜์„ ๊ฐ™์ด ์“ฐ๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

# No Swapping in mobile platform

Android OS์˜ ๊ฒฝ์šฐ, ๋ฌผ๋ฆฌ ๋ฉ”๋ชจ๋ฆฌ์˜ ๋‚ด์šฉ์„ ๋””์Šคํฌ๋กœ ๋‚ด๋ฆฌ๋Š” Swapping์„ ์ฑ„ํƒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๋Œ€์‹ , ๊ฐ€์šฉ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•ด์ง€๋ฉด ํ˜„์žฌ ์‹คํ–‰๋˜๋Š” ์•ฑ์„ ์ข…๋ฃŒ ํ•˜๋Š”๋ฐ, ์ข…๋ฃŒ ์ „์— ์•ฑ์˜ ์ƒํƒœ๋“ค์„ Flash ์ €์žฅ์†Œ์— ๊ธฐ๋กํ•˜๊ณ , ์•ฑ์„ ์žฌ์‹œ์ž‘ ํ–ˆ์„ ๋•Œ Flash ์ €์žฅ์†Œ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์„œ ๋น ๋ฅธ ์žฌ์‹œ์ž‘์„ ์ง€์› ํ•ฉ๋‹ˆ๋‹ค.

# TLB Miss Handling

Virtual Memory์˜ ์ฃผ์†Œ ๋ณ€ํ™˜์ด ๋ฉ”๋ชจ๋ฆฌ์— ์ ‘๊ทผํ•˜์ง€ ์•Š๊ณ ๋„, ๋” ๋น ๋ฅด๊ฒŒ ๋ณ€ํ™˜ํ•˜๊ธฐ ์œ„ํ•ด ๋„์ž…ํ•œ๊ฒŒ TLB ์บ์‹œ์ด๊ณ , ์š”๊ฑด HW์ž„.

TLB Hit ์ƒํ™ฉ์—์„œ์•ผ ๋‹น์—ฐํžˆ TLB ์บ์‹œ๊ฐ€ ๋™์ž‘์„ ์ž˜ ํ•˜๊ฒ ์ง€๋งŒ, TLB Miss๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ๊ทธ๋•Œ๋ถ€ํ„ฐ ์ƒํ™ฉ์ด ์ข€ ๋ณต์žกํ•ด์ง.

์ผ๋‹จ TLB Miss๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด, MMU(Memory Management Unit)์—์„œ ํŽ˜์ด์ง€ ํ…Œ์ด๋ธ”์„ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ๊ฒ€์ƒ‰ํ•จ. ์ฃผ์†Œ ๋ณ€ํ™˜์„ ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜๋ฉด ๊ทธ ๊ฐ’์„ TLB ์บ์‹œ์— ์ฑ„์›Œ๋„ฃ์Œ.

๊ทธ๋Ÿฐ๋ฐ, ์ตœ์‹ ์˜ ์•„ํ‚คํ…์ฒ˜์—์„œ๋Š” TLB Miss๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด, MMU ์žฅ์น˜๊ฐ€ ์•„๋‹ˆ๋ผ "Kernel Trap"์„ ๋ฐœ์ƒ์‹œ์ผœ์„œ ์†Œํ”„ํŠธ์›จ์–ด(์ปค๋„)์ด ์ด๋ฅผ ํ•ธ๋“ค๋ง ํ•˜๋„๋ก ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Œ!! ์ž„๋ฒ ๋””๋“œ ์‹œ์Šคํ…œ์—๊ณผ, ์ผ๋ถ€ RISC ์•„ํ‚คํ…์ฒ˜์˜ CPU์—์„œ๋Š” ํ•˜๋“œ์›จ์–ด ๋ณต์žก์„ฑ์„ ์ตœ์†Œํ™” ํ•˜๊ธฐ ์œ„ํ•ด ์ด๋ ‡๊ฒŒ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค๊ณ  ํ•จ.

# Buddy System vs. Slab
๋’ท ๋‚ด์šฉ์ด ์•„์ง๋„ ๋‚จ์•˜๋‹ค๋‹ˆ... 82p๋ถ€ํ„ฐ ๋ณด์ž!

113 changes: 113 additions & 0 deletions _posts/computer-science/operating-system/2024-12-17-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
title: "[OS] Cache"
toc: true
toc_sticky: true
categories: ["Operating System"]
excerpt: ""
---

3๋…„๊ฐ„ ์‚ฐ์—…๊ธฐ๋Šฅ์š”์›์œผ๋กœ ๋ณต๋ฌด ํ•˜๊ณ , ๋ณตํ•™ํ•ด ์ปด๊ณต๊ณผ ์ˆ˜์—…์„ ๋“ฃ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋™์•ˆ ๋งŽ์ด ๋ฐฐ์› ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ, ์—ฌ์ „ํžˆ ๋ถ€์กฑํ•œ ๋ถ€๋ถ„์ด ๋งŽ๋„ค์š” ^^;; ์—ญ์‹œ ์„ธ์ƒ๋„ ๋„“๊ณ  ๊ณต๋ถ€์˜ ๊ธธ๋„ ๋„“์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
{: .notice--info}

# ๋“ค์–ด๊ฐ€๋ฉฐ

์š” ํฌ์ŠคํŠธ๋Š” ์šด์˜์ฒด์ œ๋ฅผ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ์งง๊ฒŒ ๋ฉ”๋ชจ ํ–ˆ๋˜ ๊ฒƒ๋“ค์„ ๋ชจ์€ ๊ธ€ ์ž…๋‹ˆ๋‹ค. OS ๋‚ด์šฉ์„ ๋ณต์Šตํ•˜๋ฉด์„œ ์‚ดํŽด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ™‚

# Cache Write

- Write Through
- ์บ์‹œ ๋ธ”๋ก์— ์—…๋Žƒ์ด ์žˆ์„ ๋•Œ, ์ฆ‰์‹œ ๋ฌผ๋ฆฌ ์ €์žฅ์†Œ์— ์“ฐ๊ธฐ
- Write Back
- ์บ์‹œ ๋ธ”๋ก์ด ๊ต์ฒด ๋  ๋•Œ, ๋ฌผ๋ฆฌ ์ €์žฅ์†Œ์— ์“ฐ๊ธฐ

# Cache Lookups

- Fully-associative
- ๋‚จ์€ ์Šฌ๋กฏ ์ค‘์— ํ•œ ๊ณณ์— ์ €์žฅํ•จ.
- ์บ์‹œ ๊ฒ€์ƒ‰ ๋•Œ๋Š”, ๋ชจ๋“  ์Šฌ๋กฏ์„ ์ „์ฒด ํƒ์ƒ‰ํ•ด์„œ ๋งค์นญ ํ•˜๋Š” ์Šฌ๋กฏ์ด ์žˆ์œผ๋ฉด ๋ฐ˜ํ™˜.
- Conflict Miss ํšŸ์ˆ˜๊ฐ€ ๋‚ฎ์Œ
- Direct-mapped
- Hash ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ์Šฌ๋กฏ์˜ ์œ„์น˜๋ฅผ ๊ฒฐ์ •ํ•จ.
- ๋น ๋ฅธ ํƒ์ƒ‰
- Conflict Miss ํšŸ์ˆ˜๊ฐ€ ๋†’์Œ
- Set-associative
- Hash ํ•จ์ˆ˜๋กœ ์–ด๋–ค ์„ธํŠธ์— ์ €์žฅํ• ์ง€ ๊ฒฐ์ •
- ์„ธํŠธ๊ฐ€ ๊ฒฐ์ •๋˜๋ฉด, ๊ทธ ์„ธํŠธ์˜ ์Šฌ๋กฏ ์ค‘ ํ•˜๋‚˜์— ์ €์žฅํ•จ.
- ์บ์‹œ ๊ฒ€์ƒ‰ ๋•Œ๋Š”, ๊ทธ ์„ธํŠธ์˜ ์Šฌ๋กฏ์„ ์ „์ฒด ํƒ์ƒ‰.

# Page Fault is Trap

Trap vs. Interrupt์— ๋Œ€ํ•ด์„  [์š”๊ธฐ](/2024/12/16/virtual-memory/#gate-mechanism) ์ฐธ๊ณ !

Sys Call์€ ๋ชจ๋‘ Trap์ž„. HW ๊ด€๋ จ ํ•ธ๋“ค๋ง์€ Interrupt์ž„.


# Direct Memory Access

๋ณธ๋ž˜ ๋””์Šคํฌ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”์ธ ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌํ•˜๋ ค๋ฉด CPU๊ฐ€ ์ด๊ฑธ ์ˆ˜ํ–‰ํ•ด์•ผ ํ–ˆ์Œ. ๊ทธ๋Ÿฐ๋ฐ, CPU ๋Œ€์‹  ์ด ์ž‘์—…์„ ์œ„์ž„ ๋ฐ›์•„ ์ˆ˜ํ–‰ํ•˜๋Š” ํ…Œํฌ๋‹‰์ž„.


# Bookkeeping Bits

- page modified
- page recently used

Bookkeeping Bits๋Š” TLB์™€ Page Table ๋‘˜๋‹ค ๊ด€๋ฆฌํ•˜๊ณ , Page ์ˆ˜์ •์ด๋‚˜ ์ ‘๊ทผ์ด ๋ฐœ์ƒ ํ–ˆ์„ ๋•Œ, ๋‘ ๊ณณ ๋ชจ๋‘์— ๋ฐ˜์˜ํ•จ. (19p)

# Cache Replacement Policy

Cache miss๊ฐ€ ๋ฐœ์ƒ ํ–ˆ์„ ๋•Œ, ์–ด๋–ค ์บ์‹œ ์Šฌ๋กฏ์„ evict ํ•  ๊ฑด์ง€!!

Hashing ๊ธฐ๋ฐ˜์œผ๋กœ ์บ์‹œ์— ์ ‘๊ทผํ•˜๋Š” Direct Mapped Cache์—์„œ๋Š” ๊ณ ๋ คํ•˜์ง€ ์•Š์•„๋„ ๋จ!

## MIN (best algorithm)

์ตœ์ ์˜ Cache Exchange ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ฆ๋ช…๋จ. Cache Miss ํšŸ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ์ ์Œ.

์•ž์œผ๋กœ ๊ฐ€์žฅ ์˜ค๋žซ๋™์•ˆ ์‚ฌ์šฉ๋˜์ง€ ์•Š์„ ์บ์‹œ ํ•ญ๋ชฉ์„ Evict ํ•˜๋Š” ์ „๋žต์ž„

## LRU (near best)

MIN์— ๊ฐ€์žฅ ๊ทผ์ ‘ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜.

ํ˜„์žฌ ์บ์‹œ ์Šฌ๋กฏ์— ์˜ฌ๋ผ๊ฐ„ ํ•ญ๋ชฉ ์ค‘์—์„œ ๊ฐ€์žฅ ์˜ค๋žซ๋™์•ˆ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ํ•ญ๋ชฉ์„ Evict ํ•˜๋Š” ์ „๋žต.


# Cache ์‚ฌ์ด์ฆˆ๋ฅผ ๋Š˜๋ฆฌ๋ฉด Miss๊ฐ€ ์ค„์–ด๋“ค๊นŒ?

Nope! ์บ์‹œ ์‚ฌ์ด์ฆˆ๋ฅผ ๋Š˜๋ ค๋„ Cache Miss ํšŸ์ˆ˜๊ฐ€ ์ค„์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์Œ. (Belady's Anomaly๋ผ๊ณ  ํ•จ.) (34p)

์‚ฌ์‹ค ์š” ๋ฌธ์ œ๋Š” FIFO์—์„œ๋งŒ ๋ฐœ์ƒํ•˜๋Š” ๊ฑฐ๋ผ๊ณ  ํ•จ. ์ด์œ ๋Š” ์บ์‹œ ์Šฌ๋กฏ ์ˆ˜๊ฐ€ ์ฆ๊ฐ€ํ•˜๋ฉด์„œ, ๊ต์ฒด ์ˆœ์„œ๊ฐ€ ๋ฐ”๋€Œ๋ฉด์„œ ์˜คํžˆ๋ ค ๋ถ„๋ฆฌํ•˜๊ฒŒ ๋™์ž‘ํ•  ์ˆ˜ ์žˆ์–ด์„œ๋ผ๊ณ  ํ•จ. LRU์—์„œ๋Š” ๊ฒช์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•จ.

# Page Pool

ppt ๋‚ด์šฉ์„ ์ฝ๋Š”๋ฐ, ์„ค๋ช…์ด ๋ช…ํ™•ํ•˜์ง€ ์•Š์•„์„œ ์ดํ•ดํ•˜๋Š”๋ฐ ํ•œ์ฐธ ๊ฑธ๋ฆผ;;

Frame Table์— ์žˆ๋Š” ํŽ˜์ด์ง€๋“ค์˜ ์ตœ๊ทผ ์‚ฌ์šฉ ์—ฌ๋ถ€๋ฅผ ๋ณด์กฐ ํ•ด์ฃผ๋Š” ์ž๋ฃŒ๊ตฌ์กฐ์ด์ž ๋ฉ”์ปค๋‹ˆ์ฆ˜์ž„.

Page Pool์—์„  ๊ฐ ํŽ˜์ด์ง€๋ฅผ ํด๋ฆฐ ํŽ˜์ด์ง€์™€ ๋”ํ‹ฐ ํŽ˜์ด์ง€๋กœ ๊ตฌ๋ถ„ํ•จ. Page Fault๋กœ ์ธํ•ด Frame Table์—์„œ ํŽ˜์ด์ง€๋ฅผ ํ•˜๋‚˜ ๋น„์›Œ์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด๋ผ๋ฉด

- ํŽ˜์ด์ง€๊ฐ€ ํด๋ฆฐ ํŽ˜์ด์ง€๋ผ๋ฉด
- ์ฆ‰์‹œ ๊ต์ฒด ๊ฐ€๋Šฅ
- ํŽ˜์ด์ง€๊ฐ€ ๋”ํ‹ฐ ํŽ˜์ด์ง€๋ผ๋ฉด
- Write back ํ›„ ๊ต์ฒด ๊ฐ€๋Šฅ

์—ฌ๊ธฐ๊นŒ์ง€๋Š” ๊ธฐ์กด Frame Table์ด๋ž‘ ๋™์ผํ•จ. ํ•ต์‹ฌ์€ ์ง€๊ธˆ๋ถ€ํ„ฐ์ธ๋ฐ, OS๋Š” Page Pool์„ ๋น„๋™๊ธฐ(async)ํ•˜๊ฒŒ ๊ด€๋ฆฌํ•จ. ๊ทธ๋ž˜์„œ ์ฃผ๊ธฐ์ ์œผ๋กœ ๋Œ๋ฉด์„œ ๋”ํ‹ฐ ํŽ˜์ด์ง€๋Š” Write Back์„ ์ˆ˜ํ–‰ํ•ด ํด๋ฆฐ ํŽ˜์ด์ง€๋กœ ๋งŒ๋“ค์–ด์คŒ.

์ด๊ฒƒ์€ ๋”ํ‹ฐ ํŽ˜์ด์ง€๋ฅผ Write Back ํ•˜๋Š”๋ฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๋‹ˆ, ์ด๋Ÿฐ ์ƒํ™ฉ์ด Page Fault์—์„œ ์ตœ๋Œ€ํ•œ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋„๋ก ํ•˜๊ธฐ ์œ„ํ•œ ๋ฉ”์ปค๋‹ˆ์ฆ˜์ž„!

# Thrashing

๊ฐ€์šฉ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์ด ์•„์ฃผ์•„์ฃผ ๋‚ฎ์•„์„œ, ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ์— ์ ‘๊ทผํ•  ๋•Œ ๋งˆ๋‹ค Page Fault๊ฐ€ ๋ฐœ์ƒํ•˜๊ฑฐ๋‚˜, ์‹œ์Šคํ…œ ์ „๋ฐ˜์ ์œผ๋กœ Page Fault ๋ฐœ์ƒ ๋นˆ๋„๊ฐ€ ๋†’์€ ์ƒํƒœ. ์‹ฌ๊ฐํ•œ ์„ฑ๋Šฅ ์ €ํ•˜๊ฐ€ ์ผ์–ด๋‚˜๊ณ  ์žˆ๋‹ค๋Š” ์˜๋ฏธ์ž„.

Working Set์„ ์ง€์›ํ•ด ์ค„ ๋งŒํผ ๋ฌผ๋ฆฌ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์ถฉ๋ถ„ํ•˜์ง€ ๋ชป ํ•œ ์ƒํ™ฉ์—์„œ ๋ฐœ์ƒํ•จ.

์ด๋Ÿฐ ํ˜„์ƒ์„ ๋ฐฉ์ง€ํ•˜๋ ค๋ฉด??

- ๊ฐ ํ”„๋กœ์„ธ์Šค๊ฐ€ ํ•„์š”๋กœ ํ•˜๋Š” ์ตœ์†Œํ•œ์˜ ํ”„๋ ˆ์ž„ ๊ฐฏ์ˆ˜๋ฅผ ๋ณด์žฅํ•ด์ค˜์•ผ ํ•จ.
- ์‹œ์Šคํ…œ์— ๋™์‹œ์— ์‹คํ–‰๋˜๋Š” ํ”„๋กœ์„ธ์Šค ์ˆ˜๋ฅผ ์ค„์—ฌ์„œ ๋ฉ”๋ชจ๋ฆฌ ๊ฒฐ์Ÿ์„ ์™„ํ™” ํ•œ๋‹ค.
- ์ข€๋” ํšจ์œจ์ ์ธ ํŽ˜์ด์ง€ ๊ต์ฒด ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ฑ„ํƒ ํ•œ๋‹ค.
- ๊ทธ๋ƒฅ ๋ฌผ๋ฆฌ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ฆ์„คํ•œ๋‹ค.

44p๋ถ€ํ„ฐ ๋ณผ ๊ฒƒ

0 comments on commit 9d44b7f

Please sign in to comment.