๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โญ Group_Study/Operating System

[6์ฃผ์ฐจ] Virtual Memory: Paging system

by ํฌ์ŠคํŠธ์‰์ดํฌ 2023. 1. 11.

Virtual Memory: Paging system

Paging System

null

โœ” ํ”„๋กœ๊ทธ๋žจ์„ ๊ฐ™์€ ํฌ๊ธฐ์˜ ๋ธ”๋ก์œผ๋กœ ๋ถ„ํ• (Pages)

โœ” Terminologies

  • Page: ํ”„๋กœ๊ทธ๋žจ์˜ ๋ถ„ํ• ๋œ block
  • Page frame: ๋ฉ”๋ชจ๋ฆฌ์˜ ๋ถ„ํ•  ์˜์—ญ(Page์™€ ๊ฐ™์€ ํฌ๊ธฐ๋กœ ๋ถ„ํ• )

ํŠน์ง•

โœ” ๋…ผ๋ฆฌ์  ๋ถ„ํ• ์ด ์•„๋‹˜(ํฌ๊ธฐ์— ๋”ฐ๋ฅธ ๋ถ„ํ• )

  • Page ๊ณต์œ (sharing) ๋ฐ ๋ณดํ˜ธ(protection) ๊ณผ์ •์ด ๋น„๊ต์  ๋ณต์žก

โœ” Simple and Efficient

  • Segmentation ๋Œ€๋น„

โœ” No external fragmentation

  • Internal fragmentation ๋ฐœ์ƒ ๊ฐ€๋Šฅ

Address Mapping

โœ” Virtual address: v = (p, d)

  • p: page number
  • d: displacement(offset)

โœ” Address mapping

  • PMT(Page Map Table)

โœ” Address mapping mechanism

  • Direct mapping(์ง์ ‘ ์‚ฌ์ƒ)
  • ASsociative mapping(์—ฐ๊ด€ ์‚ฌ์ƒ)
    • TLB(Translation Look-aside Buffer)
  • Hybrid direct/associative mapping

Page Map Table(PMT)

null

โœ” secondary storage address: swap device ์ƒ์— ์ €์žฅ๋œ ์œ„์น˜

Direct Mapping

โœ” Block mapping๊ณผ ์œ ์‚ฌ
โœ” ๊ฐ€์ •

  • PMT๋ฅผ ์ปค๋„ ์•ˆ์— ์ €์žฅ
  • PMT entry size = entrySize
  • Page size = pageSize
null
null

โœ” Residence bit = 0์ธ ๊ฒฝ์šฐ page fault ๋ฐœ์ƒ -> ํ•ด๋‹น page ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌ

Page Fault

null

โœ” swap device -> ๋ฉ”๋ชจ๋ฆฌ ์ ์žฌ๋Š” ์ผ์ข…์˜ disk I/O๊ณผ์ •

โœ” I/O: running -> asleep/block -> ready

  • Context switching ๋ฐœ์ƒ

๋ฌธ์ œ์ ๊ณผ ํ•ด๊ฒฐ๋ฐฉ์•ˆ

โœ” ๋ฌธ์ œ์ 

  • ๋ฉ”๋ชจ๋ฆฌ ์ ‘๊ทผ ํšŸ์ˆ˜๊ฐ€ 2๋ฐฐ (์„ฑ๋Šฅ ์ €ํ•˜)
  • PMT๋ฅผ ์œ„ํ•œ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„ ํ•„์š”

โœ” ํ•ด๊ฒฐ๋ฐฉ์•ˆ

  • Associative mapping(TLB)
  • PMT๋ฅผ ์œ„ํ•œ ์ „์šฉ ๊ธฐ์–ต์žฅ์น˜(๊ณต๊ฐ„) ์‚ฌ์šฉ
    • Dedicated register of cache memory
  • Hierarchical paging
  • Hashed page table
  • Inverted page table

Associatice Mapping

null

โœ” TLB(Translation Look-aside Buffer)์— PMT ์ ์žฌ

  • Associative high-speed memory

โœ” PMT๋ฅผ ๋ณ‘๋ ฌ ํƒ์ƒ‰

โœ” Low overhead, high speed

โœ” Expensive hardware

  • ํฐ PMT ๋‹ค๋ฃจ๊ธฐ ์–ด๋ ค์›€

Hybrid Direct/Associative Mapping

โœ” ๋‘ ๊ธฐ๋ฒ•์„ ํ˜ผํ•ฉํ•˜์—ฌ ์‚ฌ์šฉ

  • HW ๋น„์šฉ์€ ์ค„์ด๊ณ , Associative Mapping์˜ ์žฅ์  ํ™œ์šฉ

โœ” ์ž‘์€ ํฌ๊ธฐ์˜ TLB ์‚ฌ์šฉ

  • PMT: ๋ฉ”๋ชจ๋ฆฌ(์ปค๋„ ๊ณต๊ฐ„)์— ์ €์žฅ
  • TLB: PMT์— ์ผ๋ถ€ entry๋“ค์„ ์ ์žฌ
    • ์ตœ๊ทผ์— ์‚ฌ์šฉ๋œ page๋“ค์— ๋Œ€ํ•œ ์ €์žฅ

โœ” Locality(์ง€์—ญ์„ฑ) ํ™œ์šฉ

์ž‘๋™ ์›๋ฆฌ

null
null

Memory Management

โœ” Page์™€ ๊ฐ™์€ ํฌ๊ธฐ๋กœ ๋ฏธ๋ฆฌ ๋ถ„ํ• ํ•˜์—ฌ ๊ด€๋ฆฌ/์‚ฌ์šฉ

  • Page frame
  • FPM ๊ธฐ๋ฒ•๊ณผ ์œ ์‚ฌ

Frame table

null

โœ” Page frame๋‹น ํ•˜๋‚˜์˜ entry

โœ” ๊ตฌ์„ฑ

  • Allocated/available field
  • PID field
  • Link field: for free list(์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ fp๋“ค์„ ์—ฐ๊ฒฐ)
  • AV: Free list header(free list์˜ ์‹œ์ž‘ ์ง€์ )

โœ” ์ผ์ข…์˜ linked-list

Page Sharing

โœ” ์—ฌ๋Ÿฌ ํ”„๋กœ์„ธ์Šค๊ฐ€ ํŠน์ • page๋ฅผ ๊ณต์œ  ๊ฐ€๋Šฅ

  • Non-continuous allocation

โœ” ๊ณต์œ  ๊ฐ€๋Šฅ page

  1. Procedure pages
    • Pure code (reenter code)
  2. Data page
    • Read-only data
    • Read-write data (๋ณ‘ํ–‰์„ฑ(concurrency) ์ œ์–ด ๊ธฐ๋ฒ• ๊ด€๋ฆฌ ํ•˜์—์„œ๋งŒ ๊ฐ€๋Šฅ)

์˜ˆ์‹œ

null

โœ” Editor ํ”„๋กœ๊ทธ๋žจ์„ 3๋ช…์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ

โœ” editor program(code)๋Š” ํ•˜๋‚˜์˜ page๋งŒ ์˜ฌ๋ ค๋‘๊ณ  ๊ณต์œ 

โœ” ์ž‘์„ฑํ•˜๋Š” data๋งŒ ๋‹ค๋ฅธ ๊ณณ์— ์ €์žฅ

Data Page Sharing

null

โœ” ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๊ฐ์ž PMT์—์„œ ๊ณต์œ ํ•˜๊ณ ์ž ํ•  data์— ๋Œ€ํ•ด ๊ฐ™์€ page frame number ํ™œ์šฉ

Procedure Page Sharing(Problem)

null

โœ” ๋ฉ”๋ชจ๋ฆฌ ์ƒ์˜ ๊ฐ™์€ ๊ณต๊ฐ„์„ ๋‹ค๋ฅธ page number๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ๋‹ค

solution

null

โœ” ํ”„๋กœ์„ธ์Šค๋“ค์ด shared page์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ PMT์˜ ๊ฐ™์€ entry์— ์ €์žฅํ•˜๋„๋ก ํ•œ๋‹ค (๊ฐ™์€ ์ด๋ฆ„)

Page Protection

null

โœ” ์—ฌ๋Ÿฌ ํ”„๋กœ์„ธ์Šค๊ฐ€ page๋ฅผ ๊ณต์œ  ํ•  ๋•Œ

  • Protection bit ์‚ฌ์šฉ
  • ํ”„๋กœ์„ธ์Šค์˜ ์ ‘๊ทผ ๊ถŒํ•œ์„ bit๋กœ ํ‘œํ˜„

Summary

โœ” ํ”„๋กœ๊ทธ๋žจ์„ ๊ณ ์ •๋œ ํฌ๊ธฐ์˜ block์œผ๋กœ ๋ถ„ํ• (page) / ๋ฉ”๋ชจ๋ฆฌ๋ฅผ block size๋กœ ๋ฏธ๋ฆฌ ๋ถ„ํ• (page frame)

  • ์™ธ๋ถ€ ๋‹จํŽธํ™” ๋ฌธ์ œ ์—†์Œ
  • ๋ฉ”๋ชจ๋ฆฌ ํ†ตํ•ฉ / ์••์ถ• ๋ถˆํ•„์š”
  • ํ”„๋กœ๊ทธ๋žจ์˜ ๋…ผ๋ฆฌ์  ๊ตฌ์กฐ ๊ณ ๋ ค x (page sharing/protection ๋ณต์žก)

โœ” ํ•„์š”ํ•œ page๋งŒ page frame์— ์ ์žฌํ•˜์—ฌ ์‚ฌ์šฉ

  • ๋ฉ”๋ชจ๋ฆฌ์˜ ํšจ์œจ์  ํ™œ์šฉ

โœ” Page mapping overhead

  • ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„ ๋ฐ ์ถ”๊ฐ€์ ์ธ ๋ฉ”๋ชจ๋ฆฌ ์ ‘๊ทผ ํ•„์š”
  • ์ „์šฉ HW ํ™œ์šฉ์œผ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ(๋น„์šฉ ๊ณ ๋ ค)

๋Œ“๊ธ€