ch7. memory management.1 #์šด์˜์ฒด์ œOS #๋ฉ”๋ชจ๋ฆฌ๊ด€๋ฆฌ

2022. 12. 14. 20:52ใ†_Study/OperationSystem

728x90

memory management  ๐Ÿ‡¸.•*¨*•¸.•*¨*•¸.•*¨*•¸.•*¨*•

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


์šด์˜์ฒด์ œ(OS)๋Š” ๋‹ค์–‘ํ•œ ๋งค๋‹ˆ์ €๊ฐ€(manager)์žˆ๋‹ค. ์ด๋ฒˆ์—๋Š” ๋ฉ”๋ชจ๋ฆฌ ๋งค๋‹ˆ์ €๊ฐ€ ์–ด๋–ค ์—ญํ• ์„ ํ•˜๊ณ  ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€ ์•Œ์•„๋ณธ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ ๋งค๋‹ˆ์ €๊ฐ€ ํ•˜๋Š” ์ผ๋กœ๋Š” physical ํ•˜๋“œ์›จ์–ด๊ฐ€ ์ž˜ ์ž‘๋™ํ•˜๋„๋ก ์ถ”์ƒํ™”๋ฅผ ์ œ๊ณต(API system call)์„ ํ•œ๋‹ค.

 

Memory Management Requirements : ์š”๊ตฌ ์‚ฌํ•ญ

- Relocation : ์žฌ๋ฐฐ์น˜, ์ž ๊น ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•˜๊ฑฐ๋‚˜, ์˜ค๋ž˜ ๊ธฐ๋‹ค๋ ค์„œ ๋””์Šคํฌ๋กœ ์˜ฎ๊ฒผ์„ ๋•Œ ๋‹ค์‹œ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋”ฉํ•˜๋Š” ๊ฒฝ์šฐ

- Protection : ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค ์˜์—ญ๊ณผ ์„ž์ด๋ฉด ์•ˆ๋œ๋‹ค.

- Sharing : shared ๊ณต์œ ๋ฅผ ํ•˜๋Š” ๋งค์ปค๋‹ˆ์ฆ˜๋„ ์ œ๊ณตํ•ด์•ผ ํ•œ๋‹ค.

- Logical organization : ๋‚ด๋ถ€์ ์ธ ๊ตฌ์กฐ

- Physical organization : ๋ฌผ๋ฆฌ์ ์ธ ๊ตฌ์กฐ

 

Memory Partitioning : ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋‚˜๋ˆ„๋Š” ๊ธฐ๋ฒ•

 

- Paging 

- Segmentation

 

 

- minimize executable memory access time : ๋ฉ”๋ชจ๋ฆฌ ์ ‘๊ทผ ์‹œ๊ฐ„์„ ์ตœ์†Œํ™”ํ•ด์„œ ์†๋„๋ฅผ ๋†’์ธ๋‹ค.

- maximize executable memory size : ์‚ฌ์ด์ฆˆ๋Š” ์ตœ๋Œ€๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

- Executable memory must be cost-effective : ๋น„์šฉ์€ ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค. 

 

maps process address space to primary memory : mapping์„ ์œ„ํ•ด ๋ฉ”๋ชจ๋ฆฌ์˜ ์ฃผ์†Œ๋ฅผ ํ• ๋‹นํ•œ๋‹ค.

๋ฉ”๋ชจ๋ฆฌ๋„ I/O๋ฅผ ํ•ด์•ผํ•œ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ์™€ CPU์˜ ์†๋„์ฐจ์ด์— ์˜ํ•ด ๋Œ€๋ถ€๋ถ„์˜ ์‹œ๊ฐ„์„ ๊ธฐ๋‹ค๋ฆฌ๋Š”๋ฐ ์‚ฌ์šฉํ•œ๋‹ค. ๋”ฐ๋ผ์„œ memory manager์€ ๋˜๋„๋ก CPU๊ฐ€ ์•ˆ ๋†€๋„๋ก (์ตœ๋Œ€ํ•œ ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋„๋ก) ๋„์™€์•ผํ•˜๋Š”๋ฐ ์ถฉ๋ถ„ํ•œ ์ˆ˜์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ํ• ๋‹นํ•˜๋Š” ๊ฒƒ์€ ๋ฉ”๋ชจ๋ฆฌ ๋งค๋‹ˆ์ €์˜ ์—ญํ• ์ด๋‹ค.

 

 

Relocation : ์žฌ๋ฐฐ์น˜

In a multiprogramming system, the availale main memory is generally shared among a number of processes

Active processes need to be able to be swapped in and out of main memory

 

when it is swapped back, palcing in the same main memory region as before??

Instead, we may need to relocate the process to a different area of memory

๋””์Šคํฌ๋กœ ์ž ๊น ๋บ๋‹ค๊ฐ€ ๋กœ๋”ฉํ•˜๋ ค๋ฉด ๋ฐฐ์น˜๋ฅผ ์–ด๋–ป๊ฒŒ / ๋ณดํ˜ธ๊ฐ€ ํ•„์š” (๊ฒน์น˜์ง€ ์•Š๊ฒŒ)

 

Process Addressing

3๊ฐ€์ง€ ํ•„์š”ํ•˜๋‹ค.

- PCB ์‹œ์ž‘์œ„์น˜

- ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘์œ„์น˜

-  stack call ์œ„์น˜

 

์ปดํŒŒ์ผํ•˜๋ฉด ์žฌ๋ฐฐ์น˜๊ฐ€ ๊ฐ€๋Šฅํ•œ relocation ์˜ค๋ธŒ์ ํŠธ ํŒŒ์ผ๋กœ ๋งŒ๋“ ๋‹ค.

 

์ด๋ฅผ Linking : ์ฃผ์†Œ๋ฅผ ์—ฐ๊ฒฐ

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์—†์œผ๋ฉด linking error ๋ฐœ์ƒ

 

์‹คํ–‰ํŒŒ์ผ์ด ํ•˜๋“œ๋””์Šคํฌ์— ์ €์žฅ๋œ๋‹ค. Absolute program ์ƒ๊น€

 

Loader์„ ์ด์šฉ

 

- allrocate primary memory

- adjust addreses in address space

- Copy address space form secondary to primary memory 

 

์ƒ๋Œ€์ฃผ์†Œ๋ฅผ ํ• ๋‹น๋ฐ›์œผ๋ฉด ๊ทธ๋งŒํผ ์ฃผ์†Œ๊ฐ€ ๋Š˜์–ด๋‚œ๋‹ค.

relocatable object.o ์—์„œ๋Š” ๋‹ค๋ฅธ ๋ชจ๋“ˆ์— ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•จ์ˆ˜ put_record ์˜€์ง€๋งŒ. ์œ„์น˜๋ฅผ ๋„ฃ๊ธฐ ์œ„ํ•ด ์ฃผ์„์€ ๋‚จ๊ฒจ๋‘”๋‹ค. linking์ž‘์—…์„ ์‹œํ–‰ํ•˜๋ฉด ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ํ•˜๋‚˜๋กœ ๋ฌถ์–ด ํ•˜๋‚˜์˜ image๋กœ ๋งŒ๋“ค๊ธฐ ๋•Œ๋ฌธ์— ์šฉ๋Ÿ‰์ด ํฌ๊ฒŒ ๋Š˜์–ด๋‚œ๋‹ค. (์ฃผ์†Œ๋„ ์—ญ์‹œ ๋ฐ”๋€๋‹ค.)

 

์œ— ๊ทธ๋ฆผ์—๋Š” 1000๋ฒˆ์„ ํ• ๋‹น๋ฐ›์•„ code Segment๊ฐ€ 1000์”ฉ๋ฐ€๋ ธ์œผ๋ฉฐ, Data segement๋Š” 100์„ ํ• ๋‹น๋ฐ›์•„ 0136์œผ๋กœ ๋ฐ”๋€Œ์—ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํ•ด๋‹น ๋ณ€์ˆ˜์˜ ์œ„์น˜์— ๋งž๊ฒŒ ๋‚ด๋ถ€์ฝ”๋“œ๋„ ์ˆ˜์ •ํ•ด์•ผํ•œ๋‹ค. ์ปดํŒŒ์ผ ์‹œ์—๋Š” call '์ฃผ์„' ์ด์—ˆ์ง€๋งŒ ๋‹ค๋ฅธ ๋ชจ๋“ˆ์—์„œ ์ฃผ์†Œ๋ฅผ ํ• ๋‹น๋ฐ›์•˜๊ธฐ ๋•Œ๋ฌธ์— call ๋กœ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

 

 

 

4000์„ ํ• ๋‹น๋ฐ›์•„ ์ž๋ฆฌ ์žก์•˜๋‹ค๋ฉด, 4000์”ฉ ๋”ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

segement๋Š” ์„œ๋กœ์„œ๋กœ ์—ฐ๊ฒฐ๋˜์–ด code(์•„๋ž˜) - data(์œ„,์•ˆ์— global ๋ณ€์ˆ˜) ์ˆœ์œผ๋กœ ์ž๋ฆฌ์žก๋Š”๋‹ค.

 

 

 

 

Protection : ๋ณด์•ˆ / ๋ณดํ˜ธ 

Each process should be protected against unwaited interfernce by other processes

๊ฐ ํ”„๋กœ์„ธ์Šค๋Š” ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๋กœ ๋ถ€ํ„ฐ ์›์น˜์•Š๋Š” ๊ฐ„์„ญ์—์„œ ๋ณดํ˜ธ๋ฐ›์•„์•ผํ•œ๋‹ค.

Processes need to acquire permission to reference memory locations for reading or writing purposes.

์ฐธ์กฐ ๊ถŒํ•œ์„ ๋”ฐ๋กœ ์ค„ ์ˆ˜ ์žˆ๋‹ค.

Location of a program in main memory is unpredictable.

์˜ˆ์ธก ๋ถˆ๊ฐ€๋Šฅํ•œ ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. (์ปดํŒŒ์ผ ์‹œ์—๋Š” ์ฃผ์†Œ๋ฅผ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ, python์€ ๋™์  ๋ฐ”์ธ๋”ฉ)

Memory refernces generated by a process must be checked at run time.

Mechanisms that support relocation also support protection

 

Memory Protection requirement must be satisfied by the CPU(HW) (rather than the OS(SW))

์—‰๋šฑํ•œ ๊ณณ์„ ์ฐธ์กฐํ•˜๋ฉด interrput๋ฅผ ๋ฐœ์ƒํ•˜๋“ฏ์ด ์กฐ์น˜๋ฅผ ์ทจํ•œ๋‹ค. CPU์˜ ๋„์›€์ด ํ•„์š”ํ•˜๋‹ค.

 

 

 

Dynamic Address Relocation

Relocation Register : memory entry ์ฃผ์†Œ

Relative Address : ์ƒ๋Œ€ ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉ + ์‹ค์ œ entry์— ๋”ํ•จ : ๊ณ ์ •์„ ์‹œ์ผœ๋†“์„ ์ˆ˜๊ฐ€ ์—†๋‹ค.

์ฆ‰ 0์—์„œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ ์ฃผ์†Œ์ด๋‹ค.

 

 

Multiple Segment Relocation Registers

Segment : segment๋งˆ๋‹ค ๋‹ค๋ฅธ ๊ณณ์— ์œ„์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ๋ชจ๋‘ ํ•ฉํ•ด์„œ ์ฃผ์†Œ๋ฅผ ๋งŒ๋“ค์–ด ๋‚ผ ์ˆ˜๋„ ์žˆ๋‹ค.

 

 

 

 

 

 

 

Runtime Bound Checking

์ฃผ์†Œ๊ฐ€ ๋„˜์–ด๊ฐ€๋Š”์ง€ ์•ˆ๋„˜์–ด๊ฐ€๋Š”์ง€ ์ฒดํฌํ•œ๋‹ค. ์ฐธ์กฐํ•˜๊ธฐ์ „์— Relative address + Relocation Register =์‹ค์ œ์ฃผ์†Œ๊ฐ€ limit register ๋ณด๋‹ค ํฌ๋ฉด interrupt๋ฅผ ๋ฐœ์ƒํ•œ๋‹ค.

 

 

 

Sharing

If proceeses execute the same program?

- advantageous to allow each process access to the same copy of the program

๊ฐ™์€ ํ”„๋กœ๊ทธ๋žจ์„ ์—ฌ๋Ÿฌ๋ฒˆ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ code ์˜์—ญ์€ ๋™์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”๋ชจ๋ฆฌ ์ด์ ์„ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

Any protection must have the flexibility

- to allow processes to access the same portion of main memory

Memory management must allow controlled access to shared areas of memeory

- without compromising protection

 

Mechnaisms used to supprot relocation supprot sharing capabilities

 

 

Logical Oranization ๋…ผ๋ฆฌ์  ๊ตฌ์„ฑ

Memory is organized as linear.

Most programs are organized into modules

- modules can be written and compiled independently

- Different degrees of protection can be given to diffrent modules (read only, execute only)

- It is possible to introduce mechanisms by which modules can be shared among processes

๋ชจ๋“ˆ๋„ ๊ฐ์ž ๋‹ค๋ฅด๊ฒŒ ์‹คํ–‰๋œ๋‹ค. ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค์—๋„ ํ•˜๋‚˜์˜ ๋ชจ๋“ˆ์„ ๊ฐ™์ด ๊ณต์œ  ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

How OS can effectively deal with these?

-> Segmentation ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ ๊ธฐ์ˆ ์ค‘ ํ•˜๋‚˜, ์‚ฌ์ด์ฆˆ๋ฅผ ๊ฐœ๋ณ„ ์„ค์ • ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

Physical Organization ๋ฌผ๋ฆฌ์  ๊ตฌ์„ฑ

The organization of the flow of information between main and secondary memory is a major system concern:

Storage Hierarchies (๋ฉ”๋ชจ๋ฆฌ ๊ณ„์ธต ๊ตฌ์กฐ)

 

Place frequently-used info high, infrequnently- used info low in the hierarchy

Reconfigure as process changes phases

๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์ด์— ๋™๊ธฐํ™”๊ฐ€ ์ž˜๋˜์–ด์•ผํ•œ๋‹ค.

 

Upward moves are copy operations

Update are first applied to upper memroy

Downward move is desructive

- Destory image in upper memory

- update image in lower memory

 

 

๊ณ„์ธต๊ฐ„์˜ ๋ฐ์ดํ„ฐ ํ๋ฆ„์„ ๋ณด์•˜์„ ๋•Œ, ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ๊ณ  ์‹ถ์œผ๋ฉด cache memory ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์•„๋ž˜๋กœ ๋‚ด๋ ค๊ฐ„๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ๊ฐ’์„ ์ฐพ์œผ๋ฉด copyํ•ด์„œ ์˜ฌ๋ผ์˜ค๋ฉด์„œ ๊ฐ€์ ธ์™€์•ผ ํ•œ๋‹ค. ์ฆ‰, ์ฐพ์„ ๋ฐ์ดํ„ฐ๊ฐ€ ํ•˜์œ„ ๋ฉ”๋ชจ๋ฆฌ์—๋Š” ์žˆ์–ด์•ผํ•œ๋‹ค. ๋งŒ์•ฝ, ๋””์Šคํฌ์— ์žˆ๋Š” ๊ฒƒ์„ ์‚ญ์ œํ•˜์˜€์„๋•Œ๋Š” ์ƒ์œ„๋ฉ”๋ชจ๋ฆฌ์—์„œ๋„ ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ญ์ œ๋˜์–ด์•ผ ํ•œ๋‹ค.

 

 

Memory Partitioning : ๋ฉ”๋ชจ๋ฆฌ ๋ถ„ํ• , ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์–ด๋–ป๊ฒŒ ๋‚˜๋ˆŒ ๊ฒƒ์ธ๊ฐ€

The principal operation of memory management is to bfings processes into main memory

-for execution by the CPU

In almost all modern multiprogramming system this involves virtual memory

 

an early method of managing memory

- uses in several variations in some now-obsolete OS

-Virtual memory has evolved from the partitioning methods

 

OS๋„ ํ”„๋กœ๊ทธ๋žจ์ด๋ผ ์ฐจ์ง€ํ•จ

 

gray๋Š” ๋นˆ๊ณต๊ฐ„์ธ๋ฐ Pi๋ฅผ ์–ด๋–ป๊ฒŒ ๋„ฃ์„ ๊ฒƒ์ธ๊ฐ€?

 

 

Fixed Partitioning - Equal size

๊ฐ™์€ ์‚ฌ์ด์ฆˆ๋กœ ๋ถ„ํ• ํ–ˆ๋‹ค.

๋ฌธ์ œ 1 : ๋งŒ์•ฝ ํ”„๋กœ๊ทธ๋žจ์ด ํŒŒํ‹ฐ์…˜ ๋ณด๋‹ค ํฌ๋ฉด ํ• ๋‹น์„ ๋ชปํ•œ๋‹ค.

๋ฌธ์ œ 2 : ๋„ˆ๋ฌด ์ž‘์€ ํ”„๋กœ๊ทธ๋žจ๋„ ํ•œ ๋ธ”๋Ÿญ์„ ์ฐจ์ง€ํ•ด์„œ ๋นˆ ๊ณต๊ฐ„์ด ๋‚ญ๋น„๋  ์ˆ˜ ์žˆ๋‹ค.

 

Fixed Partitoning - Unequal size

๋‹ค์–‘ํ•œ ์‚ฌ์ด์ฆˆ๋กœ ์ชผ๊ฐœ์—ˆ๋‹ค.

๋ฌธ์ œ 1: ๊ทธ๋ž˜๋„ ์•ˆ์— ๋นˆ ๊ณต๊ฐ„์ด ์ƒ๊ธด๋‹ค.

 

Fixed Partition Memory Mechanism

N2์— ๋ฐฐ์น˜ํ•˜๊ณ  ๋‚จ๋Š” ๊ณต๊ฐ„์€? -> ๋‚ด๋ถ€ ๋‹จํŽธํ™” internal Fragmentation : ๊ณ ์ •๋œ ํฌ๊ธฐ๊ฐ€ ์žˆ์„๋•Œ ํ• ๋‹นํ•˜๊ณ  ๋‚จ๋Š” ์‚ฌ์šฉ์•ˆํ•˜๋Š” ๋ถ€๋ถ„

region : ์ด๋ฏธ ๋‚˜๋‰˜์–ด์ง„ ๊ณต๊ฐ„

 

Pi๊ฐ€ ์–ด๋””์— ์ ํ•ฉํ• ์ง€ ์ฐพ๋Š” ๊ฒƒ์„ Placement algorithm ์ด๋ผ๊ณ  ํ•œ๋‹ค.

 

 

 

 

ready queue๋ฅผ ๊ฐ๊ฐ ๋งŒ๋“ค์–ด์„œ ์„ ํƒ์„ ํ•ด์„œ ์ €์žฅํ•œ ํ›„ ์šฉ๋Ÿ‰์— ๋งž๋Š” ํŒŒํ‹ฐ์…˜์„ ์„ ํƒํ•œ๋‹ค.

์žฅ์  : ํ”„๋กœ์„ธ์Šค๋“ค์ด ๊ฐ€์žฅ ์ ํ•ฉํ•œ ๊ณณ์— ํ• ๋‹น์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ๋‚ด๋ถ€ ๋‹จํŽธํ™”๊ฐ€ ๊ฐ€์žฅ ์ ๋‹ค.

๋‹จ์ : ์‹œ์Šคํ…œ ์ „์ฒด์ ์œผ๋กœ ๋ดค์„๋•Œ๋Š” ๋น„ํšจ์œจ์ ์ด๋‹ค. ( 5MB ํŠน์ •ํ•œ ๋ฉ”๋ชจ๋ฆฌ๋งŒ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ํ•œ ๊ณณ๋งŒ ์ค„ ์„ค ์ˆ˜ ์žˆ๋‹ค.)

-> single queue ๋ฅผ ๋งŒ๋“ค์–ด์„œ load ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

 

Fixed Partitioning ์˜ ๋‹จ์ 

์žฅ์  : ๊ฐ„๋‹จํ•ด์„œ ๊ตฌํ˜„ํ•˜๊ธฐ๊ฐ€ ์‰ฝ๋‹ค. ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ๋ฐœ์ƒํ•˜๋Š” overhead๋ฅผ ์ตœ์†Œํ™” ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋‹จ์  : ์‹œ์Šคํ…œ์„ ์ƒ์„ฑํ•  ๋•Œ ๋ฏธ๋ฆฌ ์ •ํ•ด์ง„ ํŒŒํ‹ฐ์…˜ ์ˆ˜ ์ž์ฒด๊ฐ€ ๋ฉ€ํ‹ฐํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์ˆ˜์ค€์ด๊ธฐ ๋•Œ๋ฌธ์— ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ช‡ ๊ฐœ ๊นŒ์ง€ ์šด์˜ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ•œ๊ณ„๊ฐ€ ์ƒ๊ธด๋‹ค. ๋˜ํ•œ ์•„์ฃผ ์ž‘์€ ํ”„๋กœ์„ธ์Šค๋‚˜ ๋งค์šฐ ํฐ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์–ผ๋งˆ๋‚˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ• ์ง€๋ฅผ ๋ชจ๋ฅธ๋‹ค.

 

 

-> Dynamic Partitioning 

๊ธธ์ด๋‚˜ ์ˆ˜๋ฅผ ๊ทธ๋•Œ๊ทธ๋•Œ ํŒ๋‹จํ•ด์„œ ํ• ๋‹นํ•œ๋‹ค.

์žฅ์  : ํ”„๋กœ์„ธ์Šค๊ฐ€ ํ•„์š”ํ•œ ๋งŒํผ ์ •ํ™•ํ•˜๊ฒŒ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์‹œ์ž‘ํ–ˆ์„ ๋•Œ๋Š” ๋”ฑ๋งž๊ฒŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. P4๋ฅผ ์‹คํ–‰ํ•  ๋•Œ P2๋ฅผ swap outํ•˜๊ณ  P4๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  P2๋ฅผ ๋‹ค์‹œ ์‹คํ–‰ํ•œ๋‹ค๊ณ  ํ–ˆ์„ ๋•Œ P1์„ swap outํ•˜๊ณ  P2๋ฅผ ์‹คํ–‰ํ–ˆ๋‹ค๊ณ  ํ•˜์ž. ์ด๋•Œ ์ค‘๊ฐ„์— empty๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ์ด๋Š” ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด ์ง€๋‚  ์ˆ˜๋ก ๋” ์‹ฌ๊ฐํ•ด์ง€๋Š”๋ฐ ๋‚˜์ค‘์—” ์ด ๋นˆ ๊ณต๊ฐ„๋•Œ๋ฌธ์— ๋ฉ”๋ชจ๋ฆฌ ์ด์šฉ๋ฅ ์ด ๊ฐ์†Œํ•˜๊ฒŒ ๋œ๋‹ค.

 

External Fragmentation : ์™ธ๋ถ€ ๋‹จํŽธํ™”: ๋‚ด๊ฐ€ ํ• ๋‹นํ•˜๊ณ  ๋‚จ์€ ๋ฐ”๊นฅ์ชฝ์— ์ƒ๊ธฐ๋Š” ๋นˆ ๊ณต๊ฐ„ (๋‚ด๋ถ€ ๋‹จํŽธํ™”๊ฐ€ ๋‹ค๋ฅธ ์ ์€ Fixed partitioning์ด๋ผ์„œ ๋‚ด๋ถ€ region์— ๋นˆ ๊ณต๊ฐ„์ด ์ƒ๊ธด๋‹ค.)

 

๋‘˜์„ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋นˆ ๊ณต๊ฐ„์„ ์••์ถ•ํ•˜๋ฉด ๋œ๋‹ค.

Compaction : OS shifts processes so that they are contiguous.

- CPU ์‹œ๊ฐ„์ด ๋‚ญ๋น„๋œ๋‹ค.

- ๊ทธ๋ ‡์ง€๋งŒ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

- dynamic relocation ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•˜๋‹ค.

- ์‹คํ–‰์ค‘์ธ ํ”„๋กœ์„ธ์Šค์—๊ฒŒ ์˜ํ–ฅ์„ ์ฃผ๋ฉด ์•ˆ๋œ๋‹ค.

 

์ฃผ์†Œ๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ์ž˜ ์—ฐ๊ฒฐ๋งŒ ํ•˜๋ฉด ๋ ๊นŒ?

loader : run time image๊ฐ€ ์•„๋‹ˆ๋ผ absolute program์„ ์‹คํ–‰ํ•ด์„œ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฌ๋Š” ์—ญํ• , image๊ฐ€ ๋‹ค์‹œ ์‹œ์ž‘ํ• ๋•Œ, ์‹คํ–‰ ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค ๋•Œ flag๋ฅผ ์˜ฎ๊ธด๋‹ค. address space ๋ฅผ ํ†ตํ•œ ์ด๋™์—์„œ ์‚ฌ๋ผ์ง€์ง€ ์•Š๊ฒŒ Binding ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ์˜ฎ๊ธด๋‹ค.

compile , linker : ์‰ฝ๊ฒŒ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋„๋ก flag๋ฅผ ์ถ”๊ฐ€

 

dynamic์—์„œ ๋ฐฐ์น˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜

- ์ฒ˜์Œ ๋ฐฐ์น˜ํ•  ๋•Œ ์ž˜ ์ƒ๊ฐํ•ด์•ผํ•˜๋Š”๋ฐ ์–ด๋–ป๊ฒŒ? ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ 3๊ฐ€์ง€๋ฅผ ์„ค๋ช…ํ•œ๋‹ค.

  • First-fit :  scans memory from the beginning and chooses the first available block.
    • ์ฒ˜์Œ๋ถ€ํ„ฐ ์Šค์บ”ํ–ˆ์„ ๋•Œ ๋‚˜์˜ค๋Š” ๊ณต๊ฐ„์— ํ• ๋‹นํ•œ๋‹ค.
    • ๊ฐ€์žฅ ๊ฐ„๋‹จํ•˜๊ณ , ๋น ๋ฅด๋‹ค
    • ๋‹จ์  : ์ง„ํ–‰์‹œ ์™ธ๋ถ€๋‹จํŽธํ™”๊ฐ€ ์ƒ๊ธฐ๋Š”๋ฐ,  ์•ž๋ถ€๋ถ„ํ„ฐ ์ง‘์–ด ๋„ฃ๊ธฐ ๋•Œ๋ฌธ์— hole์ด ๋Œ€๋ถ€๋ถ„ ๋งŽ์ด ์ƒ๊ธด๋‹ค.
  • Next-fit : Scans memory from the location of the last placement, and chooses the next available block 
    • ํ• ๋‹น๋œ ๋‹ค์Œ๋ถ€ํ„ฐ ์ฐพ์ž
    • ๋‹จ์  : ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„ ๋์— ๋งŽ์ด ๋ฐฐ์น˜๊ฐ€ ๋œ๋‹ค. ํฐ ๊ณต๊ฐ„์ด ์ ์  ์ข์•„์ง„๋‹ค. ์™ธ๋ถ€๋‹จํŽธํ™”๊ฐ€ ๊ฐ€์žฅ ๋นจ๋ฆฌ ์ผ์–ด๋‚œ๋‹ค.
    • ์••์ถ•์ด ์ž์ฃผ ์ผ์–ด๋‚œ๋‹ค.
  • Best-fit : Chooses the block that is closest in size to the request
    • ๊ฐ€์žฅ ์ ํ•ฉํ•œ ํฌ๊ธฐ์˜ block์„ ์ฐพ๋Š”๋‹ค.
    • ์žฅ์  : ์™ธ๋ถ€๋‹จํŽธํ™” ํ˜„์ƒ์ด ๊ฐ€์žฅ ์ ๊ฒŒ ์ผ์–ด๋‚œ๋‹ค.
    • ๋‹จ์  : ์„ฑ๋Šฅ ์ž์ฒด๋Š” ๊ฐ€์žฅ ์•ˆ์ข‹๊ฒŒ ๋‚˜์˜จ๋‹ค. (์ฐพ๋Š๋ผ...), ์—ฌ๊ธฐ์ €๊ธฐ hole์„ ๋งŒ๋“ค์–ด์„œ ๊ฐ€์žฅ ์••์ถ•(compaction)์„ ๋”๋” ์ž์ฃผ ๋งŽ์ด ํ•˜๊ฒŒ ๋œ๋‹ค.

 

 

 

Buddy System

Both fixed and dynamic partitioning schemes have draebacks

fixed : ์ˆ˜๊ฐ€ ์ •ํ•ด์ง€๊ณ , ๊ณต๊ฐ„์ด ์ •ํ•ด์ ธ ์žˆ์Œ

dynamic : ์œ ์ง€ํ•˜๊ธฐ๊ฐ€ ํž˜๋“ค๊ณ , compaction ๋ฐœ์ƒ์‹œ overhead๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

 

์ด ๋‘˜์˜ ์ ˆ์ถฉ์•ˆ์ด buddy system

 

The entire space available for allocation is treated as a single block of size 2u

 

๋ฐ˜ํ‹ˆ ๋‚˜๋ˆ ์„œ ์ฒดํฌํ•˜๋ฉด์„œ

ํ• ๋‹น๋œ ๊ฐ€์žฅ ์ž‘์€ํฌ๊ธฐ์˜ ๋ธ”๋Ÿญ < ์ด ์‚ฌ์ด๋ฅผ ์ฐพ๋Š”๋‹ค. < ๊ฐ€์žฅ ํฐ ํฌ๊ธฐ์˜ ๋ธ”๋Ÿญ

 

์˜ˆ์‹œ๋ฅผ ๋ณด๋Š”๊ฒŒ ๋” ๊ฐ„๋‹จํ•˜๋‹ค.

 

๊ฐ€์žฅ ์ ํ•ฉํ•œ ๋ธ”๋Ÿญ์ด ๋‚˜์˜ฌ ๋•Œ ๊นŒ์ง€ ๋ฐ˜์œผ๋กœ ์ชผ๊ฐœ์–ด ํ• ๋‹นํ•˜๊ณ  ํ• ๋‹น์ด ๋๋‚˜๋ฉด ํฐ ๋ฉ์–ด๋ฆฌ๋กœ ๋Œ๋ ค ๋†“๋Š”๋‹ค.

 

๋‹จํŽธํ™”๊ฐ€ ์กฐ๊ธˆ ์ƒ๊ธฐ๋”๋ผ๋„ ์˜ค๋ž˜๊ฐ€์ง€ ์•Š๊ณ  ํ•ฉ์น˜๊ธฐ ๋•Œ๋ฌธ์— ์ถฉ๋ถ„ํ•œ ๊ณต๊ฐ„์ด ์ƒ๊ธด๋‹ค.

 

 

 

 

 

 ์ด์ง„ ํŠธ๋ฆฌ ๊ตฌ์กฐ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค.

 

๋ง๋‹จ ๋…ธ๋“œ๋งŒ ๋ณด๋ฉด ํ˜„์žฌ ๋ฉ”๋ชจ๋ฆฌ์˜ ์ƒํƒœ๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

๋ณ‘๋ ฌ ์‹œ์Šคํ…œ์— ๋” ์ž์ฃผ ์‚ฌ์šฉ๋˜๋ฉฐ ํ˜„๋Œ€์˜ ์šด์˜์ฒด์ œ๋Š” paging ใ„ฑ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค.

 

๋น ๋ฅธ ํ• ๋‹น๊ณผ ํ•ด์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

 

 

 

Relocation : ์žฌ๋ฐฐ์น˜

A process may occupy different partitions during the course of its life.

- process may be swapped out; when it is subsequently swapped back in,

it may be assigined to a different partition.

The same is true for dynamic partitioning and compaction.

 

fixed partition์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ํŠน์ • ํ”„๋กœ์„ธ์Šค๋Š” ๊ฐ™์€ ํŒŒํ‹ฐ์…˜์— ๋‹ค์‹œ ํ• ๋‹น๋  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์•˜๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ dynamic์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์œ„์น˜๊ฐ€ ๋ฐ”๋€” ๊ฐ€๋Šฅ์„ฑ์ด ํฌ๋‹ค. compaction๋„ ์ผ์–ด๋‚˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์œผ๋‹ˆ ๋ฐ์ดํ„ฐ์˜ ์œ„์น˜๋Š” ๊ณ ์ •์ด ์•„๋‹ˆ๋‹ค.

 

๋”ฐ๋ผ์„œ ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ relocation์„ ์‚ฌ์šฉํ•˜๊ณ  ๋ฉ”๋ชจ๋ฆฌ ๋งค๋‹ˆ์ €๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ address๋Š” ์„ธ๊ฐ€์ง€ ์ •๋ณด๋ฅผ ๋‹ด๊ณ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

 

Address Types

 ๋ณ€๊ฒฝ(๊ณ„์‚ฐ)์‹œ ํ•˜๋“œ์›จ์–ด์˜ ๋„์›€์ด ํ•„์š”ํ•˜๋‹ค.

  • Physical (absolute)
    • Actual location in main memory : ๋ฉ”๋ชจ๋ฆฌ์˜ ์‹ค์ œ ์œ„์น˜
  • Logical
    • Referece to a memory location independent of the current assignment of data to memory; 
    • ์™„์ „ํžˆ ๋…๋ฆฝ์ ์œผ๋กœ ์ฐธ์กฐ ์œ„์น˜, ์–ด๋””์— ์ฐธ์กฐํ•˜๋ฉด ๋˜๋Š”์ง€
  •  Relative -> physical๋กœ ๋ฐ”๊พธ๊ธฐ(0์—์„œ ์‹œ์ž‘)
    •  a particular example of logical address, ์ƒ๋Œ€์ ์ธ ์œ„์น˜
    • CPU๋ฅผ ํ†ตํ•ด ๊ณ„์‚ฐํ•œ ์ƒ๋Œ€์ ์ธ ์œ„์น˜ -> ์‹ค์ œ ๋ฉ”๋ชจ๋ฆฌ ์œ„์น˜

 

Address Translation HW

 

register๊ฐ€ ๋‘ ์ข…๋ฅ˜๊ฐ€ ์žˆ๋‹ค.

 

Base register : loaded with the starting physical address of the process

Bounds register : loaded with the process's ending physical address

 

Relative address๊ฐ€ ๋“ค์–ด์˜ค๋ฉด absolute address ๊ณ„์‚ฐ์„ ํ•œ๋‹ค. base ์™€ bound๋ฅผ ํ†ตํ•ด ๊ณ„์‚ฐ์„ ํ•ด์„œ ๋ฒ—์–ด๋‚˜๋ฉด interrupt๋ฅผ ๋ฐœ์ƒํ•œ๋‹ค.

๋‚ด๋ถ€์— ์žˆ์œผ๋ฉด ์‹คํ–‰ํ•œ๋‹ค.