ch8 virtual memory(VM) #์šด์˜์ฒด์ œOS #๊ฐ€์ƒ๋ฉ”๋ชจ๋ฆฌ

2022. 12. 15. 03:47ใ†_Study/OperationSystem

728x90

Virtual Memory ๐Ÿ‡¸.•*¨*•¸.•*¨*•¸.•*¨*•¸.•*¨*•

ํ•ด๋‹น ์ž๋ฃŒ๋Š” ๊ฐ•์˜ ํ•™์Šต์ž๋ฃŒ์ž…๋‹ˆ๋‹ค.'

https://www.youtube.com/watch?v=YCfP9I4K-8Y ๋ฅผ ์ฐธ๊ณ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.


๊ธฐ๋ณธ์ ์œผ๋กœ swap in, out์œผ๋กœ ํ•˜๋“œ๋””์Šคํฌ๋ฅผ ์‹ค์ œ ๋ฉ”๋ชจ๋ฆฌ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. overhead๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ํšจ์œจ์ ์ด์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋Š”๋ฐ ์ง€์—ญ์„ฑ(locality)๋ฅผ ์ด์šฉํ•˜์—ฌ ์„ฑ๋Šฅ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.

 

 

Hardware and Control Structures

Paging & Segmentation

Memory management

1) All memory references within a process are logical addresses :

๋ชจ๋“  ๋ฉ”๋ชจ๋ฆฌ์˜ ์ฐธ์กฐ๋Š” ๋…ผ๋ฆฌ ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. (๋ณ€ํ™˜)

- process may be swapped in and out of main memory. : ๋‹ค๋ฅธ ์œ„์น˜์— ๋กœ๋”ฉ์ด ๋  ์ˆ˜๋„ ์žˆ๋‹ค.

2) A process may be broken up into a number of pieces : ํ•œ ํ”„๋กœ์„ธ์Šค๋ฅผ ์—ฌ๋Ÿฌ ๋ธ”๋ก์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค.

- Process don't need to be contiguously located in main memory.

๊ผญ ๋ฐ˜๋“œ์‹œ ์—ฐ์†์ ์œผ๋กœ ์œ„์น˜ํ•  ํ•„์š”๋Š” ์—†๋‹ค.

 

It is not necessary that all of the pages or segments of a process be in main memory during execution.

์‹คํ–‰์— ํ•„์š”ํ•œ ๋ธ”๋Ÿญ๋งŒ ๋ฉ”์ธ ๋ฉ”๋ชจ๋ฆฌ์— ๊ฐ€์ ธ์˜ค์ž.

 

If the piece that holds the next instruction to be fetches and the piece that holds the next data location to be accessed are in main memory,

- then at least for a time execution may proceed

 

OS begins by bringing only one or a few pieces : ์‹œ์ž‘ํ•  ๋•Œ ๋ช‡๊ฐœ์˜ ๋ธ”๋ก๋งŒ ํ• ๋‹นํ•œ๋‹ค. ํ•œ๋™์•ˆ์€ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๋‹ค.

To include the initial program piece and the initial data piece

Resident set : Portion of process that is in main memory : ์ด๋ฏธ ์‹œ์ ์— ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋”ฉ๋˜์–ด ์žˆ๋Š” ๋ถ€๋ถ„

 

when address is needed that is not in main memory : ์ฐธ์กฐํ•ด์•ผํ•˜๋Š” ์ฃผ์†Œ๊ฐ€ resident set์— ์—†๋‹ค๋ฉด?

-> interrupt ๋ฐœ์ƒ

 

OS puts the interrupted process in a blocking state : ์ผ๋‹จ ๋ธ”๋ก (์‹คํ–‰ํ•  ์ˆ˜๊ฐ€ ์—†์Œ)

OS issues a disk I/O Read request

 

which causes the OS to place the affected process in the ready state

- when it runs again, required data is in memory.

 

๊ณ„์† interrupt๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”๋ฐ ํšจ์œจ์ ์ผ๊นŒ? 

-> ๋” ๋งŽ์€ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ฉ”์ธ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆด ์ˆ˜ ์žˆ์–ด ํ™œ์šฉ๋„๋ฅผ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.

-> main memory ๋ณด๋‹ค ํฐ ํ”„๋กœ์„ธ์Šค๋„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

Partial Loading

main memory may be full : ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๊ฐ€๋“ ์ฐฌ ๊ฒฝ์šฐ

when ths OS brings one piece in, it must swap one piece out

swap out์„ ์ง„ํ–‰ํ•ด์•ผ ํ•˜์ง€๋งŒ, ๋ฐฉ๊ธˆ ๋ง‰ ๋“ค์–ด์˜จ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ out ์‹œํ‚ค๋Š” ๊ฒฝ์šฐ?

thrashing : a state in which the processor spends most of its time swapping pieces rather than executing user instruction CPU ๊ฐ€ ๋ช…๋ น์–ด ์ˆ˜ํ–‰ํ•˜์ง€ ๋ชปํ•˜๊ณ  swapping ํ•˜๋Š”๋ฐ๋งŒ ์‹œ๊ฐ„์„ ๋” ์“ฐ๋Š” ๊ฒฝ์šฐ

 

 

 

Principle of Locality

page ์ฐธ์กฐ๋ฅผ ์˜ˆ์ธกํ•  ์ˆ˜ ์žˆ์–ด VM ํšจ์œจ์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค. swap out ์„ ์–ด๋–ค ๊ฒƒ์„ ํ•ด์•ผํ• ์ง€ ์˜ˆ์ธกํ•˜์—ฌ ์–ด๋–ค ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋ถ€๋ถ„์ ์œผ๋กœ ๋กœ๋”ฉํ• ์ง€ ์„ ํƒํ•  ์ˆ˜ ์žˆ์–ด์„œ interrupt ๋‚˜ I/O ์š”๊ตฌ๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๊ธฐ์— VM ํšจ์œจ์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.

 

 

 

Paging

Page :

 

 

page table์„ ๋งŒ๋“ค์–ด ์ •๋ฆฌํ•œ๋‹ค.

page number + offset ์™ธ์—๋„ ๋“ค์–ด์˜ค๋Š” ์ •๋ณด ์ค‘ 4๊ฐ€์ง€๋Š”

 

- Present Bit : ๋ฉ”์ธ ๋ฉ”๋ชจ๋ฆฌ์— ํ˜„์žฌ ์žˆ๋Š”์ง€?

- Modify Bit : ๋‚ด์šฉ์ด ์ˆ˜์ •๋˜์—ˆ๋Š”์ง€?

- Other Control Bits : Shared? protect?

- Frame number

 

 

 

 

 

 

 

๋ณ€ํ™˜ ๊ณผ์ •

1. virutal address๊ฐ€ ๋“ค์–ด์˜ค๋ฉด ํŽ˜์ด์ง€ ๋„˜๋ฒ„์™€ ์˜คํ”„์…‹์ด ์žˆ๋‹ค.

 

2. ํŽ˜์ด์ง€ ๋„˜๋ฒ„๋ฅผ ์ด์šฉํ•ด ํŽ˜์ด์ง€ ํ…Œ์ด๋ธ”์˜ index๋ฅผ ์ฐพ๋Š”๋‹ค.

 

3. Frame number๊ฐ€ ๋’ค์— ์žˆ๋Š” ๋ฐ ์ด๋ฅผ + offset์ด๋ž‘ ํ•ฉ์ณ ๊ณ„์‚ฐํ•˜์—ฌ ์‹ค์ œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ฐพ์•„๋‚ธ๋‹ค.

 

 

 

 

 

 

 

 

Page Table Size : ๋‚ด๊ฐ€ ๋ช‡ ๊ฐœ๋‚˜ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ์„๊นŒ? ์–ผ๋งˆ๋‚˜ ํฌ๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋‚˜?

Tha amount of memory devoted to page tables

- could be unacceptably high example :

 Each process can have up to 2^31bytes(2GB) of virtual memory // ์ตœ๋Œ€ 2๊ธฐ๊ฐ€ 

Using 2^9bytes(=512B) page: // ํŽ˜์ด์ง€ ํฌ๊ธฐ

2^22 page table entries are required per process // ๋‚˜๋ˆˆ 2์˜ 22๊ฐœ์˜ page table์ด ์ด์šฉ ๊ฐ€๋Šฅ

 

To overcome this problem

- Most virtual memory schemes store page tables in virtual memory rather than real memory(n>m)

- when process is running, part of its page table is in main memory // ๋ถ€์กฑํ•ด์„œ ๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ์— ์ด๋ฅผ ์ €์žฅํ•ด์•ผํ•˜๋‚˜?

 

Page table sturcture (ํ™•์žฅ๋œ ๊ตฌ์กฐ)

  • Hierarchical page scheme : 2๋‹จ ๊ณ„์ธต๊ตฌ์กฐ : ์ผ์ข…์˜ directory๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉด ๋˜์–ด ๋” ํฐ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค.
    • 1st level root page table : main memory
    • 2nd level table : virtual memory
  • ์—†์œผ๋ฉด page fault(context switching)ํ•˜๊ณ  ๊ฐ€์ ธ์™€์•ผํ•œ๋‹ค. 

 

  • - Hash / Inverted page tables : Hash ๊ฐ’์„ ์‚ฌ์šฉํ•œ ๊ตฌ์กฐ

 

  • Inverted Page Table
    • Page# of a virtual address ia mapped into a hash value
    • - Hash value points to inverted page table
    • Hash Function

 

 

 

 

 

 

 

 

 

Translation Lookaside Buffer (TLB)

Each virtual memory refenrnce -> two physical memory accesses

ํ•ญ์ƒ ๋ฌผ๋ฆฌ ๋ฉ”๋ชจ๋ฆฌ์— ๋‘ ๋ฒˆ ์ ‘๊ทผํ•˜๋Š”๋ฐ 

1) page table

2) real data

- doubling the memory access time

 

To overocme the memory access time

- uses special high-speed cache called a translation lookaside buffer (TLB); // ํŠน๋ณ„ํ•œ cache๋ฅผ ์‚ฌ์šฉ

- contains those page table entries that have been most recently used.

๊ฐ€์žฅ ์ตœ๊ทผ์— ์ฐธ์กฐ๋œ table ํ•ญ๋ชฉ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

 

TLB๋ฅผ ๋จผ์ € ํ™•์ธํ•ด์„œ

์žˆ์œผ๋ฉด -> ๋ฐ”๋กœ ์‚ฌ์šฉ

์—†์œผ๋ฉด page table๋กœ ๋„˜์–ด๊ฐ

 

page table์—์„œ

์žˆ์œผ๋ฉด -> TLB ์—…๋ฐ์ดํŠธ

์—†์œผ๋ฉด -> page fault

context switching

 

 

 

 

 

 

TLB : Associative mapping

Processor is equipped with HW

That allows it to interrogate simultaneously a number of TLB entries to determine if there is a match on page number.

์—ฌ๋Ÿฌ๊ฐœ์˜ TLB๋ฅผ ๋™์‹œ์— ํ™•์ธํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ?

 

TLB์— ํŽ˜์ด์ง€ ๋„˜๋ฒ„์™€ ํ•จ๊ป˜ frame ๋ฒˆํ˜ธ๊นŒ์ง€ ๋“ค๊ณ  ์žˆ์„ ์ˆ˜ ์žˆ์–ด์„œ ๋™์‹œ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค. TLB์™€ Cache๊ฐ€ ๊ฐ™์ด ์ƒํ˜ธ์ž‘์šฉํ•˜๋Š” ์˜ˆ์‹œ๊ฐ€ ์œ— ๊ทธ๋ฆผ์ธ๋ฐ, TLB์— hit ํ•˜๋ฉด ๋ฐ”๋กœ ์•„๋ž˜๋กœ ๋‚ด๋ ค์™€ Real address์— ์ ‘๊ทผ๊ฐ€๋Šฅํ•˜๋‹ค. TLB์— ์—†๋Š” ๊ฒฝ์šฐ miss๋กœ page table ์—์„œ ๊ฐ’์„ ์ฐพ์•„์˜ค๊ฒŒ ๋œ๋‹ค. ๊ทธ ์ดํ›„ cache operation์ด ์ง„ํ–‰ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ cache์—๋„ ๊ฐ’์ด ์žˆ๋‹ค๋ฉด ๊ฐ’์„ ๋ฐ”๋กœ ์‚ฌ์šฉํ•˜์ง€๋งŒ ์—†๋Š” ๊ฒฝ์šฐ๋Š” ์ด๋ฅผ update ํ•˜๊ฒŒ ๋œ๋‹ค.

 

 

Page Size

smaller the page size

// page size๊ฐ€ ์ž‘์„ ์ˆ˜๋ก

 

- Lesser internal fragmentation // ๋‚ด๋ถ€ ๋‹จํŽธํ™”๊ฐ€ ์ค„์–ด๋“ญ๋‹ˆ๋‹ค. (paging๊ธฐ๋ฒ•)

- but more pages are required per process // ํŽ˜์ด์ง€๊ฐ€ ๋” ๋งŽ์ด ํ•„์š”๋กœ ํ•œ๋‹ค.

- More pages are process means larger page tables // page tables์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋Š˜์–ด๋‚˜ ๊ฐ€์ƒ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ด์šฉํ•ด์•ผ ํ• ์ง€๋„ ๋ชจ๋ฅธ๋‹ค.

page table , page์— ์—†์œผ๋ฉด ๋‘ ๋ฒˆ falut๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

 

๊ฐ ํ”„๋กœ์„ธ์Šค์— ํ• ๋‹น๋œ ๋ฉ”๋ชจ๋ฆฌ์–‘ -> ํ•˜๋“œ์›จ์–ด๋ฅผ ์„ค๊ณ„ํ• ๋•Œ ๊ฒฐ์ •๋˜๋Š” page์˜ ํฌ๊ธฐ์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์งˆ ์ˆ˜๋„ ์žˆ๋‹ค.

 

Large Program์„ ์‹คํ–‰ํ• ๋•Œ :

์ฐธ์กฐ ์ง€์—ญ์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. -> (๋ฉ€ํ‹ฐ์Šค๋ ˆ๋“œ)์—ฌ๋Ÿฌ ์ฃผ์†Œ๋ฅผ ๋›ฐ์–ด๋„˜์„ ์šฐ๋ ค๊ฐ€ ์žˆ๋‹ค.

๋”ฐ๋ผ์„œ ์ปดํ“จํ„ฐ๋งˆ๋‹ค page size๊ฐ€ ๋‹ค๋ฅธ๋ฐ, ์œ ์—ฐ์„ฑ์„ ๊ฐ€์ง€๊ฒŒ ์„ค๊ณ„ํ•˜์˜€๋‹ค.

์ ์€ ์ˆ˜์˜ page์— mapping์ด ๋œ๋‹ค๋ฉด, graph์— ๋”ฐ๋ผ์„œ page size๋ฅผ ์„ค์ •ํ•˜๋ฉด ๋œ๋‹ค.

thread stack๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ page size๋ฅผ ์ž‘๊ฒŒํ•˜๋ฉด์„œ, ์—ฌ๋Ÿฌ๊ฐœ์˜ page๋ฅผ ์ฐธ์กฐํ•˜๋Š”๊ฒŒ ์œ ๋ฆฌํ•˜๋‹ค: ๋‹ค์–‘ํ•œ ์ฐธ์กฐ ๋ถ€๋ถ„ ๊ฐ€์ ธ์˜ค๊ธฐ

์šด์˜์ฒด์ œ๋Š” ํ•˜๋‚˜๋งŒ ์ง€์›ํ•˜์ง€๋งŒ, ํ•˜๋“œ์›จ์–ด๋Š” ์—ฌ๋Ÿฌ ์‚ฌ์ด์ฆˆ๋ฅผ ์ง€์›ํ•œ๋‹ค.

 

 

Thrashing Diagram

If a process does not have 'enough' pages, the page-fault rate is very high

// ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด page๊ฐ€ ์ถฉ๋ถ„ํ•ด์•ผํ•œ๋‹ค. ์•„๋‹ˆ๋ฉด page-fault๊ฐ€ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๋‹ค.

-> Low CPU utilization

-> OS thinks that it needs to increase the degree of multiprogramming

-> another process added to the system.

CPU ์‚ฌ์šฉ๋ฅ ์ด ์ฆ๊ฐ€ํ•˜๋‹ค๊ฐ€ ๋ฉ€ํ‹ฐํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด ํ•œ๊ณ„์— ๋„๋‹ฌํ•˜๋ฉด?

memory ๋ถ€์กฑ ๋” ๋งŽ์€ ํ”„๋กœ๊ทธ๋žจ -> page ๊ฐœ์ˆ˜๊ฐ€ ์ค„์–ด๋“ฌ -> ํ•„์š”ํ•œ ๋ถ€๋ถ„์ด main memory ์— ์—†์Œ ->page fault ๋ฐœ์ƒ -> disk I/O๋ฅผ ์š”์ฒญ

 

page fault ๋ฐœ์ƒ์‹œ disk I/O๋ฅผ ์š”์ฒญ

๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ „์ฒด์ ์œผ๋กœ CPU ์‚ฌ์šฉ๋ฅ ์ด ๋š ๋–จ์–ด์ง„๋‹ค.

-> ๋‹ค์Œ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋” ์‹คํ–‰

-> I/O ์š”์ฒญ, ๋” ๋–จ์–ด์ง„๋‹ค.

 

 

-> thrashing ๋ฐœ์ƒ

:memory๊ฐ€ ๋ถ€์กฑํ•˜์—ฌ swap in out์„ ๊ณ„์† ๋ฐ˜๋ณตํ•˜์—ฌ ์—ฐ์‚ฐ์„ ํ•˜์ง€ ์•Š๋Š” ์ƒํƒœ

 

์ง€์—ญ์„ฑ ๋ชจ๋ธ์„ ๊ธฐ๋ฐ˜์œผ๋กœ paging์ด ๋™์ž‘ํ•˜๋Š”๋ฐ, ํ”„๋กœ์„ธ์Šค๋Š” ๋‹ค๋ฅธ ์ง€์—ญ์œผ๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๊ณ  ๊ฒน์ณ์งˆ ์ˆ˜๋„ ์žˆ๋‹ค.

thrashing์˜ ๋ฐœ์ƒ ์›์ธ : ๋‚ด๊ฐ€ ์ฐธ์กฐํ•  ํ•„์š”ํ•œ size๊ฐ€ memory size๋ณด๋‹ค ํฐ ๊ฒฝ์šฐ

 

 

 

 

Segmentation

address space์˜ ๋ถ€๋ถ„์„ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๋Ÿฌ๊ฐœ์˜ segments๋กœ ๋‚˜๋ˆ„๋Š”๋ฐ ์‚ฌ์ด์ฆˆ๊ฐ€ ๋‹ค์–‘ํ•˜๋‹ค.

 

- simplifies handling of growing data structures

์žฅ์  : ๋ฉ์–ด๋ฆฌ์ฑ„๋กœ ์“ฐ๋Š” ๊ฒƒ์ด ์•„๋‹Œ ๊ณต๊ฐ„์„ ๋ถ„ํ• ํ•ด์„œ ์‚ฌ์šฉํ•œ๋‹ค. / / ํฐ ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ฐœ๋ฐœ์ž๊ฐ€ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์„ค๊ณ„ํ•˜๋Š”๋ฐ ํŠน์ • segment๋ฅผ ๋ฐฐ์ •ํ•œ๋‹ค๊ฑฐ๋‚˜, ์šด์˜์ฒด์ œ๊ฐ€ ์ด segment๋ฅผ ํ•„์š”ํ•˜๋ฉด ๋” ๋Š˜๋ฆฌ๊ณ , ๋” ์ค„์ด๋Š” ๊ฒฝ์šฐ๊ฐ€ ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•œ๋‹ค.

 

์ „์ฒด ํ”„๋กœ๊ทธ๋žจ์˜ ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๊ณ  segment๋งŒ ๋Š˜๋ฆฌ๋ฉด ๋œ๋‹ค.

์ธ์ ‘ ๊ณต๊ฐ„์ด ์—†๋‹ค๋ฉด, ๋” ํฐ ๊ณต๊ฐ„์œผ๋กœ ์ด๋™ํ•˜๊ธฐ๋„ ํ•œ๋‹ค. swap out

 

- allows programs to be altherd and recomplied independtly

๋ถ€๋ถ„๋งŒ ์ปดํŒŒ์ผ์„ ๋‹ค์‹œํ•  ์ˆ˜ ์žˆ๋‹ค.

- lends itself to sharing data among processes

ํ”„๋กœ์„ธ์Šค ๊ฐ„์— segment๋ฅผ ๊ณต์œ ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

-lends itself to protection

๋ณดํ˜ธ ๋น„ํŠธ๋ฅผ ์„ค์ •ํ•ด์„œ ๋ณดํ˜ธํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

 

 

Segment Organization

paging๊ณผ ๋‹ค๋ฅด๊ฒŒ length๊ฐ€ ์ถ”๊ฐ€ ๋˜์—ˆ๋‹ค.

 

paging : external fragmentation ์ด ์—†์Œ (์™ธ๋ถ€๋‹จํŽธํ™”), ๋‚ด๋ถ€ ๋‹จํŽธํ™”๊ฐ€ ์žˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ณ ์ • ํฌ๊ธฐ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ์•Œ ์ˆ˜ ์—†์ง€๋งŒ ํˆฌ๋ช…ํ•˜๊ฒŒ paging ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค.

 

segment : internal fragmentation

ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ์‚ฌ์šฉํ•˜๊ธฐ์—” ์ง๊ด€์ ์ด๋‹ค. ํ™•์žฅ์„ฑ๋„ ์ข‹์œผ๋ฉฐ ๋ชจ๋“ˆํ™”๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

Combined Paging & Segments

 

address space

 

main memory (frame) ์˜ ํฌ๊ธฐ์™€ ๋˜‘๊ฐ™์€ page ํฌ๊ธฐ๋กœ ๋‚˜๋ˆˆ๋‹ค. (segment) ํฌ๊ธฐ๋Š” page๋ณด๋‹ค ์ปค์„œ ์—ฌ๋Ÿฌ page๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค. segment๋„ page๋ฅผ ํ• ๋‹น ๋ฐ›์•„ ์ชผ๊ฐœ์ง„๋‹ค.

 

๊ฐœ๋ฐœ์ž ์ž…์žฅ์—์„œ ๋ณด๋Š” ์ฃผ์†Œ์™€ system์—์„œ ๋ณด๋Š” ์ฃผ์†Œ๊ฐ€ ๋‹ค๋ฅด๋‹ค.

ํ”„๋กœ๊ทธ๋ž˜๋จธ ์ž…์žฅ์—์„œ logical address๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณด์ด๋‚˜๋ฉด

system ๊ด€์ ์—์„œ ๋ณด๋Š” segment 

segment ๋งˆ๋‹ค page table ์ด ์žˆ๋‹ค.

 

 

 

Protection and Sharing : Segment ์˜ ์ด์ 

 

 

 

Operating System Software

Policies for Virtual Memory : minimize page faults.

๋‹จ๊ณ„๋ณ„๋กœ ์–ด๋–ค ์ •์ฑ…์„ ์“ฐ๋Š”์ง€

 

๋ฉ”๋ชจ๋ฆฌ ๋งค๋‹ˆ์ €

 

Policy for virtual memory (fetch, placement, replacement)

1. fetch Policy : ์–ธ์ œ main memory๋กœ loading ํ• ์ง€ ๊ฒฐ์ •

- demand paging : ์š”์ฒญ์ด ์˜ค๋ฉด fetching : page fault ๊ฐ€ ์ผ์–ด๋‚˜์„œ ์ ์  ๋” ๋งŽ์€ page๋“ค์ด fetch๋˜์–ด ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด ์•ˆ์ •ํ™”๊ฐ€ ๋œ๋‹ค.

- prepaging : ํ•˜๋“œ๋””์Šคํฌ์˜ ๋ฌผ๋ฆฌ์ ์ธ ํŠน์ง•์— ๋Œ€ํ•ด์„œ ๊ธฐ๊ตฌ์ ์œผ๋กœ ์‹œ๊ฐ„์ด ์˜ค๋ž˜๊ฑธ๋ฆฌ๋Š” ํ•˜๋“œ๋””์Šคํฌ, ๋ฏธ๋ฆฌ ๊ฐ€์ ธ๋‹ค ๋†“๊ณ  ์ฒ˜๋ฆฌํ•˜๊ธฐ,

ineffective if extra pages are not referenced

๊ฐ€์ ธ๋‹ค ๋†“๊ณ  ์ฐธ์กฐ ์•ˆํ•˜๋ฉด ๋ฌด์šฉ์ง€๋ฌผ. ์ง€์—ญ์„ฑ ๊ธฐ๋ฐ˜ + ๋””์Šคํฌ์˜ ํŠน์„ฑ

 

2. Placement Policy ์–ด๋Š ์œ„์น˜์— ๋ฐฐ์น˜๋ฅผ ํ•  ๊ฒƒ์ธ์ง€ : segment ์—์„  ์ค‘์š”ํ•˜๋‹ค. / ๋ถ„์‚ฐ์‹œ์Šคํ…œ, ๋ฉ€ํ‹ฐํ”„๋กœ๊ทธ๋ž˜๋ฐ / ์ฐธ์กฐํ•  ๋•Œ ๊ฑฐ๋ฆฌ๊ฐ€ ๋‹ฌ๋ผ์ง€๊ธฐ ๋•Œ๋ฌธ์—

 

paging ๊ธฐ๋ฒ•์—์„œ๋Š” ๊ทธ๋ ‡๊ฒŒ ์ค‘์š”ํ•˜์ง€ ์•Š๋‹ค. ๋ฉ”๋ชจ๋ฆฌ์— ์ ‘๊ทผํ•˜๋Š” ํ•˜๋“œ์›จ์–ด์˜ ๊ธฐ๋Šฅ, ์–ด๋””์— ๋ฐฐ์น˜๋ฅผ ํ•˜๋˜ ์ƒ๊ด€์ด ์—†๋‹ค.

 

3. replacement policy : ์‹œ๊ฐ„ ์ฐจ์ด๊ฐ€ ๋งŽ์ด ๋‚  ์ˆ˜ ์žˆ๋‹ค. / ๊ฐ€์žฅ ๋œ ์“ธ ๊ฑฐ ๊ฐ™์€ page๋ฅผ ์ œ๊ฑฐํ•œ๋‹ค.

 

 

static paging algorithms

- Random Replacement : random

- Optimal : ์ตœ์  / ๊ตฌํ˜„ ๋ถˆ๊ฐ€๋Šฅ

- Least Recently Used (LRU) : tag์‚ฌ์šฉ ์˜ค๋ž˜๋œ ๊ฒƒ์„ ๋ฐ”๊ฟˆ

- Least Frequently Used (LFU) : ๊ฐ€์žฅ ์ ๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๋ฐ”๊ฟˆ

- First In First Out (FIFO) : ์ˆœํ™˜ ํ•ด์„œ ๋ฐ”๊ฟˆ

 

Dynamic paging algorithm

- working Set model

 

 

- Random Replacement : random

 

 

stream ์ •๋ณด๊ฐ€ ์ „ํ˜€ ์„ฑ๋Šฅ์— ์˜ํ–ฅ์„ ๋ผ์น˜์ง€ ์•Š์Œ.

๊ฒฐ๊ณผ๊ฐ€ ๋งค๋ฒˆ ๋ฐ”๋€” ์ˆ˜๋„ ์žˆ๋‹ค.

 

 

 

 

 

 

 

 

 

- Optimal (Belady's Optimal Algorithm)

 

๊ฐ€์žฅ ๋ฏธ๋ž˜์— ๋ฉ€๋ฆฌ ์žˆ๋Š” page๋ฅผ ๊ต์ฒดํ•œ๋‹ค.

 

๊ฐ€์žฅ page fault๊ฐ€ ์ ์ง€๋งŒ

์šด์˜์ฒด์ œ๊ฐ€ ๋ฏธ๋ž˜์˜ ์ƒํ™ฉ์„ ์•Œ์ง€ ๋ชปํ•˜๋ฏ€๋กœ ๊ตฌํ˜„์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. ๋”ฐ๋ผ์„œ ํ‰๊ฐ€ ๊ธฐ์ค€์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค. (์ตœ์ ์˜ ์ƒํ™ฉ)

FWD(forward distance): ์•ž ๊ฑฐ๋ฆฌ

 

 

 

 

 

 

  

 

 

 

 

 

 

 

 

- Least Recently Used (LRU) :

๊ฐ€์žฅ ์˜ค๋žซ๋™์•ˆ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋˜ page๋ฅผ ๊ต์ฒดํ•œ๋‹ค.

๊ฐ€์žฅ ์˜ค๋ž˜์ „์— ์ฐธ์กฐํ–ˆ๋˜ page๋ฅผ ๊ธฐ์–ต (์‹œ๊ฐ„)

 

์ง€์—ญ์„ฑ์˜ ์›๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. -> tag(์ตœ์ข… ์ฐธ์กฐ์‹œ๊ฐ„)

BKWD(t) = ์ง€๋‚œ ๊ฑฐ๋ฆฌ

 

tag ๋ฅผ ๋งค๋ฒˆ ์—…๋ฐ์ดํŠธ ํ•˜๋ฉด ํ•˜๋“œ์›จ์–ด์— overhead๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

 

Frame์„ ํ•˜๋‚˜๋งŒ ๋Š˜๋ ค๋„ ์„ฑ๋Šฅ์ด ๋งค์šฐ ์ข‹์•„์ง„๋‹ค.

 

 

 

- Least Frequently Used (LFU)

์ ๊ฒŒ ์ฐธ์กฐ๋œ ๊ฒƒ์„ ์„ ํƒ

๊ฐ™์œผ๋ฉด Random์œผ๋กœ ์„ ํƒ

FREQ(x)

 

 

 

 

 

 

 

 

 

 

- First In First Out (FIFO) : ์ˆœํ™˜ ๋ฒ„ํผ์ฒ˜๋Ÿผ ๋‹ค๋ฃฌ๋‹ค. (์ œ์ผ ์‰ฌ์šด ๋ฐฉ๋ฒ• Round Robin)

- ์—ฐ๊ฒฐํ•œ ํฌ์ธํ„ฐ๋งŒ ์žˆ์œผ๋ฉด ์‰ฝ๊ฒŒ ๊ฐ€๋Šฅํ•˜๋‹ค.

- ๊ตฌํ˜„์ด ์‰ฝ๋‹ค.

- ๊ฐ€์žฅ ์˜ค๋ž˜์ „์— ์„ ํƒ๋œ ํŽ˜์ด์ง€๋ฅผ ์„ ํƒํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ˆœํ™˜ buffer์„ ์‚ฌ์šฉํ•œ๋‹ค.

- AGE(x)

 

 

 

 

 

 

 

 

 

 

 

๋ฒจ๋ผ๋””์˜ ์—ญ์„ค : Frame ๊ฐœ์ˆ˜๋ฅผ ๋Š˜๋ ธ๋Š”๋ฐ ์„ฑ๋Šฅ์ด ์ข‹์•„์ง€์ง€ ์•Š๋Š”๋‹ค.

 

stack alogorithms : frame์„ ๋Š˜๋ ธ์„ ๋•Œ ํฌํ•จ๊ด€๊ณ„๊ฐ€ ์„ฑ๋ฆฝํ•œ๋‹ค. -> ๋ฒจ๋ผ๋””์˜ ์—ญ์„ค์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๊ณ  frame์„ ๋Š˜๋ฆฌ๋ฉด ์„ฑ๋Šฅ์ด ์ข‹์•„์ง„๋‹ค.

 

LRU : stack

FIFO : ์•„๋‹˜

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Clock Policy ( overhead ๊ฐ€ ์ ์€ LRU๋Š”์—†์„๊นŒ?)

Sets of frames is considered to be a circular buffer

each frame has use bit

The use bit is set to 1 -> page fault ๊ฐ€ ๋ฐœ์ƒ

use bit์ด 0์ธ ํ”„๋ ˆ์ž„์„ ์ฒดํฌํ•œ๋‹ค.

-> (fetch๋จ)1์„ 0์œผ๋กœ ๋ณ€๊ฒฝ

-> 0์„ ์ฐพ์œผ๋ฉด ๊ทธ๋‹ค์Œ์— ํฌ์ธํ„ฐ ์—ฐ๊ฒฐ

 

ํ•œ๋ฐ”ํ€ด ๋„๋Š” ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐํ•ด์•ผํ•œ๋‹ค.

 

 

 

 

๊ฒฐ๊ตญ frame ์ˆ˜๋ฅผ ๋งŽ์ด ๋Š˜๋ฆฌ๋ฉด ์„ฑ๋Šฅ์€ ์ข‹์•„์ง„๋‹ค.

์—„์ฒญ๋‚œ ๋น„์šฉ์ด ์†Œ์š”๋œ๋‹ค.

 

 

 

 

 

 

 

 

 

Page buffering

 

page fault๊ฐ€ ๋ฐœ์ƒ์‹œ list๋ฅผ ๊ฒ€์‚ฌ๋ฅผ ํ•œ๋‹ค.

-> ํ•„์š”ํ•œ page๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์— ์žˆ๋‹ค๋ฉด page table์—์„œ p bit์„ set์„ ํ•œ๋‹ค.

-> ํ•„์š”ํ•œ page๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์— ์—†๋‹ค๋ฉด, Free page list์— ๋ฎ์–ด์“ด๋‹ค. (buffer)

 

๋”ฐ๋ผ์„œ ๋ฐ”๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ด€๋ฆฌ๋ฅผ ํ•œ๋‹ค. ๋‘ ๋ฆฌ์ŠคํŠธ๊ฐ€ ์žˆ๋Š”๋ฐ

Free page list : ํŽ˜์ด์ง€๋ฅผ ์ถ”๊ฐ€ (ํฌ์ธํ„ฐ๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ)

Modified page list : ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ถ”๊ฐ€

 

Note that the page is not physically moved about in main memory

๋…ผ๋ฆฌ์ ์œผ๋กœ ์›€์ง์ด๋Š” ๊ฒƒ์ด ์•„๋‹Œ ํฌ์ธํ„ฐ๊ฐ€ ์›€์ง์ธ๋‹ค.

 

๋‚ด๊ฐ€ ๊ฐ€์ ธ์˜จ page์— ์žˆ๋Š” ๋‚ด์šฉ์ด๋ผ๋ฉด ์‚ฌ์šฉํ•œ๋‹ค.

page table์—์„œ๋งŒ ํฌ์ธํ„ฐ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ , bit=0, free list์— ์—ฐ๊ฒฐ.

 

์žฅ์ : ๋น„์šฉ์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.

 

Dynamic Page Frames Allocation

๋‹จ์ : ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์–ผ๋งˆ๋‚˜ ํ• ๋‹น ๋ฐ›์•˜๋Š๋ƒ์— ๋”ฐ๋ผ fault๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค. -> ์˜ˆ์ƒ๋ณด๋‹จ fault์ด ์ค„์ง€๋Š” ์•Š๋Š”๋‹ค. -> dynamic page frame์ ์šฉ

static paging -> number of required page is fixed, no adjusting the allocation.

Thrashing : ๋„ˆ๋ฌด ๋งŽ์€ page fault๋กœ ์ธํ•ด ๋ฐœ์ƒํ•œ๋‹ค. (๊ณ„์† ๊ต์ฒด)

 

ํ•„์š”ํ•œ ๋งŒํผ frame์„ ํ• ๋‹นํ•œ๋‹ค.

 

working set algorithm (๊ฐ€์žฅ ํ˜„๋Œ€์ ์ธ ๋ชจ๋ธ)

fault๊ฐ€ ์ˆ˜์šฉ ๊ฐ€๋Šฅํ•œ ์ •๋„๋ฅผ ๊ฐ์•ˆํ•œ๋‹ค.

window of time : ์ผ์ •๊ธฐ๊ฐ„์— ์‚ฌ์šฉํ•˜๋Š” page, ๊ณ„์† ๋ฐ”๋€๋‹ค.

 

 

window ํฌ๊ธฐ(์ตœ๋Œ€ ํ”„๋ ˆ์ž„ ์ˆ˜)๋งŒ ๊ณ ๋ คํ•˜๋ฉด ๋˜์–ด LRU ๋ณด๋‹ค overhead ๊ฐ€ ์ ๋‹ค.

 

 

 

 

 

 

 

 

๊ทธ๋ ‡๋‹ค๋ฉด ์–ธ์ œ modified page์˜ ์ˆ˜์ •์‚ฌํ•ญ์„ disk์— ์ ์šฉํ• ๊นŒ?

Cleaning Policy

์–ธ์ œ swap out์„ ํ• ๊นŒ?

Demand cleaning : ์š”์ฒญ์ด ์˜ค๋ฉด, fetch๊ฐ€ ๋จผ์ € ์ผ์–ด๋‚˜๊ณ , modified page๋ฅผ ์ ๋Š”๋‹ค.

2๋ฒˆ ์ฒ˜๋ฆฌํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— CPU ์‚ฌ์šฉ๋Ÿ‰์ด ์ข‹์ง€๋Š” ์•Š๋‹ค.

 

Precleaning : ์š”์ฒญ๋˜๊ธฐ ์ „์— batch์— ํ•œ ๋ฒˆ์— ์“ด๋‹ค.

 

page buffering์„ ์ ์šฉํ•˜๋ฉด ๋” ํšจ์œจ์ ์ด๋‹ค.

๊ต์ฒด๋˜๋Š” ํŽ˜์ด์ง€๋„ free์™€ modified(ํ•œ๋ฒˆ์— ์ผ๊ด„์ฒ˜๋ฆฌ) ๋กœ ๋‚˜๋ˆˆ๋‹ค.

free list๋ฅผ ๊ณ„์† ์žฌํ™œ์šฉ ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํšจ์œจ์ ์ด๋‹ค. disk ๊นŒ์ง€ ๊ฐˆ ํ•„์š”๊ฐ€ ์—†๋‹ค.

 

 

Load Control : determines the number of processes : ํ”„๋กœ์„ธ์Šค์˜ ๊ฐœ์ˆ˜๋ฅผ ์ •ํ•œ๋‹ค.

๋„ˆ๋ฌด ์ ์€ ํ”„๋กœ์„ธ์Šค : swapping์— ์‹œ๊ฐ„์ด ๋„ˆ๋ฌด ๋งŽ์ด ์‚ฌ์šฉ

๋„ˆ๋ฌด ๋งŽ์€ ํ”„๋กœ์„ธ์Šค : thrashing์ด ๋ฐœ์ƒ

 

๋ชจ๋‹ˆํ„ฐ๋ง์„ ํ•˜๊ณ  ์žˆ๋‹ค๊ฐ€ use bit๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์€ 1์ด ๋‚˜์™€ page fault ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด : page๋ฅผ ๋Š˜๋ฆฐ๋‹ค.

use bit๊ฐ€ 0์ธ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” page๊ฐ€ ๋งŽ์ด ๋ฐœ์ƒํ•˜๋ฉด page๋ฅผ ์ค„์ธ๋‹ค.

 

 

L = S ๊ฐ’์ด ๊ฐ™๋„๋ก ์กฐ์ ˆํ•˜์—ฌ ํ”„๋กœ์„ธ์„œ์˜ ์‚ฌ์šฉ์„ ์ตœ๋Œ€ํ™” ํ•œ๋‹ค.

L = page fault meat time

S = time to process a page fault

 

 

 

- ๋‚ฎ์€ ์šฐ์„ ์ˆœ์œ„

- fault๊ฐ€ ๋ฐœ์ƒํ•œ ํ”„๋กœ์„ธ์Šค

- ๊ฐ€์žฅ ์ตœ๊ทผ์— activated : working set์ด ์ž‘์•„ loading ํ•œ ์ •๋„๊ฐ€ ์ ๋‹ค.

- ๊ฐ€์žฅ ์ž‘์€ resident set : ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋”ฉ๋œ ์ •๋„๊ฐ€ ๊ฐ€์žฅ ์ ๋‹ค. // ์ง€์—ญ์„ฑ ์‚ฌ์šฉ์‹œ ๋ถˆ๋ฆฌ

- Largest Process : ๊ณผ๋„ํ•œ ๋ฉ”๋ชจ๋ฆฌ๋Š” ์ œ๊ฑฐํ•˜๋ฉด ํšจ์œจ์ ์ด๋‹ค.

- Process with the largest remaining execution window : ๋‚จ์€ window๊ฐ€ ๋งŽ์€ ๊ฒƒ