๐Ÿ”ฅ[Pintos][Project 3][2023.06.12~2023.06.18]Team WIL (์ค‘๊ฐ„ ์ ๊ฒ€)

Pyotatoยท2023๋…„ 6์›” 18์ผ
0
post-thumbnail

๐Ÿคซ์ต๋ช…์„ฑ ๋ณด์žฅ์„ ์œ„ํ•ด ํŒ€์› 1,2,3์œผ๋กœ ํ‘œ๊ธฐํ–ˆ์Šต๋‹ˆ๋‹ค.
๐Ÿ–๏ธ์ €๋Š” ํŒ€์›3์ž…๋‹ˆ๋‹ค.

๐Ÿ“์ง„ํ–‰ ์ƒํ™ฉ

๋‚ ์งœํŒ€์› 1ํŒ€์› 2ํŒ€์› 3
2023.06.12ํŒ€ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ์ƒ์„ฑ ๋ฐ Git book ๋ฒˆ์—ญ ๋ฐ ๊ณต๋ถ€PJT2 ootm ํ•ด๊ฒฐproject2 ๋””๋ฒ„๊น… (syn-read)
2023.06.131์ฃผ์ฐจ ๊ฐœ๋… ์žฌ์ •๋ฆฌPJT2 ๊ฐœ๋… ๋ฐ ์ฝ”๋“œ ์žฌ์ •๋ฆฌGit book ์ฝ๊ธฐ ๋ฐ ํ•ฉ์นœ ์ฝ”๋“œ ๋ถ„์„
2023.06.141์ฃผ์ฐจ ์ฝ”๋“œ ๋‹ค๋“ฌ๊ธฐ ๋ฐ 2์ฃผ์ฐจ ๊ฐœ๋… ์ •๋ฆฌ๊ถŒ์˜์ง„ ๊ต์ˆ˜๋‹˜ OS๊ฐ•์˜ ๋ณต์Šต (with CSAPP)Git book ์ฝ๊ธฐ
2023.06.152์ฃผ์ฐจ ๊ฐœ๋… ์ •๋ฆฌ ๋ฐ 2์ฃผ์ฐจ ์ฝ”๋“œ ๋‹ค๋“ฌ๊ธฐGit book ํ•™์ŠตGit book ์ฝ์œผ๋ฉด์„œ
2023.06.162์ฃผ์ฐจ ์ฝ”๋“œ ๋‹ค๋“ฌ๊ธฐGit book ํ•™์ŠตMemory Management ๊ตฌํ˜„ ์‹œ์ž‘
2023.06.17Git book ๋ฒˆ์—ญ ๋ฐ ๊ณต๋ถ€๊ตฌํ˜„Memory Management ๊ตฌํ˜„ & ๋””๋ฒ„๊น…
2023.06.18Git book ๋ฒˆ์—ญ ๋ฐ ๊ณต๋ถ€๊ตฌํ˜„Anonymous Page ๊ตฌํ˜„ ์ค‘ & ๋””๋ฒ„๊น…

๐Ÿ“‹์ƒˆ๋กœ ๋ฐฐ์šฐ๊ฒŒ ๋œ ๋‚ด์šฉ๋“ค

OS๋Š” Application์ด HW๋ฅผ ๊ฐ„ํŽธํ•˜๊ฒŒ ์“ธ ์ˆ˜ ์žˆ๋„๋ก โ€œ์ถ”์ƒํ™”โ€ ํ•ด์คŒ

โ†’ ์ถ”์ƒํ™”๋ฅผ ์œ„ํ•ด ๊ทธ๋ฆฌ๊ณ  ํ•œ์ •๋œ HW ๋ฆฌ์†Œ์Šค๋ฅผ ํšจ์œจ์ ์œผ๋กœ ์“ฐ๊ธฐ์œ„ํ•ด OS๋Š” 2๊ฐ€์ง€ ๊ฐ€์ƒ
ํ™”
โ†’ 1. CPU์˜ ๊ฐ€์ƒํ™” 2. ๋ฉ”๋ชจ๋ฆฌ์˜ ๊ฐ€์ƒํ™”
(1์ฃผ์ฐจ์—์„œ ์Šค์ผ€์ค„๋ง ํ†ตํ•ด CPU ๊ฐ€์ƒํ™” ๊ตฌํ˜„ํ•˜์˜€๊ณ , ์ด๋ฒˆ์ฃผ์ฐจ์—์„œ ๋ฉ”๋ชจ๋ฆฌ์˜ ๊ฐ€์ƒํ™” ๊ตฌ
ํ˜„)
๊ธฐ์กด PintOS๋กœ๋Š” โ€œ1. CPU ๊ฐ€์ƒํ™”โ€๋ฅผ ๊ตฌํ˜„ํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ”„๋กœ๊ทธ๋žจ์„ ๋™์‹œ์—
๊ตฌํ˜„ ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ํ”„๋กœ๊ทธ๋žจ์˜ ํฌ๊ธฐ์™€ ๊ฐฏ์ˆ˜๊ฐ€ ๋ฉ”์ธ๋ฉ”๋ชจ๋ฆฌ ํฌ๊ธฐ๋งŒํผ ํ•œ์ •๋˜์–ด ์žˆ์Œ
โ†’ ์ด๋ฅผ โ€œ2. ๋ฉ”๋ชจ๋ฆฌ์˜ ๊ฐ€์ƒํ™”โ€๋ฅผ ํ†ตํ•ด ๋” ๋งŽ๊ณ  ํฌ๊ธฐ๊ฐ€ ํฐ ํ”„๋กœ๊ทธ๋žจ์„ ๋Œ๋ฆด ์ˆ˜ ์žˆ๋„๋ก ํ•จ

Mapping ๊ธฐ๋ฒ•์—๋Š” Paging, Segmentation, Segmented paging : Mechanism
โ†’ MMU (CPU๋‚ด์˜ H/W)๊ฐ€ ์œ„์˜ ๊ธฐ๋ฒ•๋“ค์„ ์‚ฌ์šฉํ•ด์„œ ๊ฐ€์ƒ๋ฉ”๋ชจ๋ฆฌ โ†’ ๋ฌผ๋ฆฌ์ ๋ฉ”๋ชจ๋ฆฌ ๋งค
ํ•‘
โ†’ MMU๊ฐ€ ๋ฉ”์ธ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋Š” ๊ฐ๊ฐ ํ”„๋กœ์„ธ์Šค์˜ ํŽ˜์ด์ง€ํ…Œ์ด๋ธ”์„ ์ฐธ์กฐํ•˜์—ฌ ๋งคํ•‘
Mapping ์ •๋ณด(ํŽ˜์ด์ง€ ํ…Œ์ด๋ธ”)๋Š” OS๊ฐ€ ๋งŒ๋“ค์–ด์คŒ : Policy
โ†’ CPU์—์„œ Virtual Address๋ฅผ ๋ณด๋‚ด๋ฉด MMU์—์„œ ๋งคํ•‘.
โ†’ Physical Address๊ฐ€ ์—†์œผ๋ฉด page fault (exception) ๋ฐœ์ƒ
โ†’ OS๊ฐ€ page fault handler๋กœ ์ฒ˜๋ฆฌํ•จ (ํŽ˜์ด์ง€ ๊ต์ฒด/ํ• ๋‹น/๋ณดํ˜ธ)

๐Ÿ“To-Do

  • supplemental Page Table ๊ตฌํ˜„ํ•˜๊ธฐ
  • physical frame management ๊ตฌํ˜„ํ•˜๊ธฐ
  • page fault handler ์ˆ˜์ •ํ•˜๊ธฐ (lazy loading)
  • stack growth, file-mapped(mmap,munmap), annonymous
  • mmap, munmap
  • swap in/out

[๐Ÿชฒ๋””๋ฒ„๊น… ๊ด€๋ จ]ํ—ค๋” ํŒŒ์ผ ์ถ”๊ฐ€๋ฅผ ์ž˜ํ•ด์ค˜์•ผํ•จ.

  • ๋ฒ„๊ทธ์˜ ์›์ธ์ด ๋  ์ˆ˜ ์žˆ์Œ.
  • ex. ๊ฐ‘์ž๊ธฐ tid_t undefined๊ฐ€ ๋œธ..include๋ฅผ ์ž˜๋ชปํ•ด์„œ ๊ทธ๋Ÿผ

๊ฐ„๋‹จํ•œ ์šฉ์–ด ์ •๋ฆฌ

1. Page

  • ๊ฐ€์ƒํŽ˜์ด์ง€(aka page)๋Š” 4096๋ฐ”์ดํŠธ ๊ฐ€์ƒ๋ฉ”๋ชจ๋ฆฌ์˜ ์—ฐ์†๋œ ๊ณต๊ฐ„์ด๋‹ค.
  • ํŽ˜์ด์ง€๋Š” ๋ฐ˜๋“œ์‹œ page-aligned๋˜๋„๋ก ํ•ด์•ผํ•จ.
  • ํŽ˜์ด์ง€ ์‚ฌ์ด์ฆˆ(4096๋ฐ”์ดํŠธ)๋กœ ๋‚˜๋ˆ„์–ด์ง€๋Š” ๊ฐ€์ƒ ์ฃผ์†Œ๋กœ ์‹œ์ž‘ํ•ด์•ผํ•จ (๐Ÿค”why?physical address์— ๋งคํ•‘ํ•˜๊ธฐ ์œ„ํ•ด! page-alignํ•˜์ง€ ์•Š์œผ๋ฉด ํ•ด๋‹น va์— memory accessํ•˜๋Š”๋ฐ ์ง€์žฅ์žˆ์„ ์ˆ˜ ์žˆ์Œ. ๋ฐ˜๋Œ€๋กœ page-aligned๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ, data๊ฐ€ cache์— ์ •ํ™•ํžˆ load๋˜๋„๋ก ์ถ”๊ฐ€ ์—ฐ์‚ฐ์„ ํ•ด์•ผํ•  ์ˆ˜๋„ ์žˆ์–ด์„œ memory access ์‹œ๊ฐ„์„ ์ฆ๊ฐ€์‹œํ‚ค๊ณ  performance ์ €ํ•˜ ๊ฐ€๋Šฅ)
  • 64bit ๊ฐ€์ƒ ์ฃผ์†Œ์˜ ๋งˆ์ง€๋ง‰ 12๋น„ํŠธ๋Š” page offset์ž„.
    • ์ƒ์œ„ ๋น„ํŠธ(?)๋“ค์€ ํŽ˜์ด์ง€ ํ…Œ์ด๋ธ”์˜ ์ธ๋ฑ์Šค๋ฅผ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
    • 64bit ์‹œ์Šคํ…œ์—์„œ๋Š” 4๋‹จ๊ณ„ ํŽ˜์ด์ง€ ํ…Œ์ด๋ธ” ๋ฐฉ์‹ ์‚ฌ์šฉ
  • ๊ฐ€์ƒ ์ฃผ์†Œ ๊ตฌ์กฐ
  • ๊ฐ ํ”„๋กœ์„ธ์Šค๋Š” ๋…๋ฆฝ์ ์ธ user ๊ฐ€์ƒ ํŽ˜์ด์ง€๋“ค์˜ ์ง‘ํ•ฉ์„ ๊ฐ€์ง
    • ํ•ด๋‹น ํŽ˜์ด์ง€๋“ค์€ KERN_BASE(0x8004000000) ๋ฏธ๋งŒ์˜ ๊ฐ€์ƒ ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง
  • Kernel ๊ฐ€์ƒํŽ˜์ด์ง€๋Š” ์ „์—ญ์ ์ด๊ธฐ ๋•Œ๋ฌธ์— ์–ด๋Š ์Šค๋ ˆ๋“œ๋‚˜ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‹คํ–‰์ค‘์ด๋˜ ๋™์ผํ•œ ์œ„์น˜์— ์žˆ์Œ
  • ์ปค๋„์€ userpage & kernel page์— ๋ชจ๋‘ ์ ‘๊ทผ ๊ฐ€๋Šฅ but user process๋Š” ์ž์‹ ์˜ userpage์—๋งŒ ์ ‘๊ทผ๊ฐ€๋Šฅ
2. Frames
  • Frame (aka. physical frame, page frame)์€ 4096๋ฐ”์ดํŠธ ํฌ๊ธฐ์˜ page-aligned๋œ ๋ฌผ๋ฆฌ ๋ฉ”๋ชจ๋ฆฌ ์ƒ์˜ ์—ฐ์†์ ์ธ ๊ณต๊ฐ„
  • 64bit ๋ฌผ๋ฆฌ ์ฃผ์†Œ๋Š” frame number + frame offset์œผ๋กœ ๊ตฌ์„ฑ๋จ
  • ๐Ÿ™…โ€โ™€๏ธx86-64 ์‹œ์Šคํ…œ์€ ๋ฌผ๋ฆฌ์ฃผ์†Œ์— ์ง์ ‘์ ‘๊ทผ ๋ถˆ๊ฐ€
  • ๐Ÿ™†โ€โ™‚๏ธPintos๋Š” kernel vm์„ ๋ฌผ๋ฆฌ ๋ฉ”๋ชจ๋ฆฌ๋กœ ์ง์ ‘ ๋งคํ•‘ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ†ตํ•ด ํ•ด๊ฒฐ
    • kernel vm์€ ๋ฌผ๋ฆฌ๋ฉ”๋ชจ๋ฆฌ์™€ 1:1 ๋งคํ•‘ ๋˜์–ด ์žˆ์Œ
    • kernel vm์„ ํ†ตํ•ด frame ์ ‘๊ทผ ๊ฐ€๋Šฅ
    • ์˜ˆ์‹œ
      • virtual address > KERN_BASE == physical address 0
      • virtual address KERN_BASE + 0x1234 == physical address 0x1234
    • ํ•€ํ† ์Šค์—๋Š” ์ด๋ฅผ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋Š” ํ•จ์ˆ˜๋“ค๋„ ์นœ์ ˆํ•˜๊ฒŒ ์ œ๊ณตํ•ด์ค€๋‹ค.
    // 0 ~ ๋ฌผ๋ฆฌ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์ด์˜ ๋ฐ”์ดํŠธ ์ค‘ kernel va ์— ๋Œ€์‘ํ•˜๋Š” pa ๋ฐ˜ํ™˜
    #define ptov(paddr) { /* Omit details */ }
    //va์— ๋Œ€์‘ํ•˜๋Š” ๋ฌผ๋ฆฌ๋ฉ”๋ชจ๋ฆฌ(์ด๋ฉด์„œ kernel va) ๋ฐ˜ํ™˜
    #define vtop(vaddr) { /* Omit details */ }
3. Page Tables
  • CPU๊ฐ€ va๋ฅผ ๋ฌผ๋ฆฌ์ฃผ์†Œ๋กœ ๋ณ€ํ™˜ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” ์ž๋ฃŒ๊ตฌ์กฐ
  • page โžก๏ธ frame
4. Swap Slots
  • swap partition ๋‚ด์˜ ๋””์Šคํฌ ๊ณต๊ฐ„์— ์žˆ๋Š” ํŽ˜์ด์ง€ ํฌ๊ธฐ์˜ ์˜์—ญ
    • ํ˜„์žฌ running ์ค‘์ธ process๊ฐ€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ฉ”๋ชจ๋ฆฌ ํŽ˜์ด์ง€๋“ค์„ ์ €์žฅํ•  ๋”ฐ๋กœ ์ง€์ •๋œ ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ.
    • process๊ฐ€ ํ˜„์žฌ memory์— ์—†๋Š” ํŽ˜์ด์ง€์— ์ ‘๊ทผํ•˜๋ ค๊ณ  ํ• ๋•Œ OS๊ฐ€ swap file์—์„œ main memory๋กœ file์„ ์ด๋™ ์‹œํ‚จ ํ›„, process์˜ va๋กœ ํŽ˜์ด์ง€๋ฅผ ๋งคํ•‘ํ•ด์คŒ
  • OS๊ฐ€ ๋” ํšจ์œจ์ ์œผ๋กœ ๋ฌผ๋ฆฌ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•จ.
    • ๋ฌผ๋ฆฌ ๋ฉ”๋ชจ๋ฆฌ์™€ swapfile ๊ฐ„์— page๋“ค์„ ์ด๋™์‹œ์ผœ์ฃผ๋ฉด์„œ running ์ค‘์ธ process์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ชจ๋‘ ์ €์žฅํ•  ๋ถ€๋‹ด์„ ์ค„์ž„ (๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉโฌ‡๏ธ)
profile
https://pyotato-dev.tistory.com/ ๋กœ ์ด์‚ฌ์ค‘ ๐Ÿšš๐Ÿ’จ๐Ÿš›๐Ÿ’จ๐Ÿšš๐Ÿ’จ

0๊ฐœ์˜ ๋Œ“๊ธ€