4 minute read

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

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

์š” ํฌ์ŠคํŠธ๋Š” ์šด์˜์ฒด์ œ๋ฅผ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ์งง๊ฒŒ ๋ฉ”๋ชจ ํ–ˆ๋˜ ๊ฒƒ๋“ค์„ ๋ชจ์€ ๊ธ€ ์ž…๋‹ˆ๋‹ค. 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์— ๋Œ€ํ•ด์„  ์š”๊ธฐ ์ฐธ๊ณ !

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๋ถ€ํ„ฐ ๋ณผ ๊ฒƒ