12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy...

14
03/17/22 1 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC http://www.cs.illinois.edu/cl ass/cs423/ Based on slides by Roy Campbell, Sam King, and Andrew S Tanenbaum

Transcript of 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy...

Page 1: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

04/18/23 1

Operating Systems Design (CS 423)

Elsa L Gunter

2112 SC, UIUC

http://www.cs.illinois.edu/class/cs423/

Based on slides by Roy Campbell, Sam King, and Andrew S Tanenbaum

Page 2: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Address Spaces and Memory

Process = one or more threads in an address space

Thread: stream of execution Unit of concurrency

Address space: memory space that threads use Unit of data

04/18/23 2

Page 3: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Address Space Abstrac2on

Address space: all the memory data Program code, stack, data segment

Hardware interface (physical reality) One memory, small, shared

Application interface (illusion) Each process has own memory, large

04/18/23 3

Page 4: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Illusions Provided by Address Apace

Address independence Same address in different processes not

conflicting with each other Eg Same address for stack

Protection One process cannot access the data of

another Secret data, protected code

Virtual memory 64 bit address space, memory many 4 G

04/18/23 4

Page 5: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Uni‐programming

One process runs at a time

Always load process into the same spot

How do you switch processes?

What abstractions does this provide? Problems?

04/18/23 5

Operating System ROM

Operating System ROM

User MemoryUser Memory

Page 6: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Multi‐programming

Multi‐programming: more than one process in memory at a time

Need address translation Need protection

Address translation Avoid conflicting addresses Static: before you execute Dynamic: during execution, could change

04/18/23 6

Page 7: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Dynamic translation

Translate every memory reference from virtual address to physical address

Virtual address: an address used by the user process to reference a location in memory

Physical address: an address used by the physical memory

04/18/23 7

Page 8: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Dynamic Address Translation

Translation enforces protection One process can’t even refer to another process’s address

space Translation enables virtual memory

A virtual address only needs to be in physical memory when it is being accessed

Change translations on the fly as different virtual addresses occupy physical memory

Do you need hardware support?

04/18/23 8

User ProcessUser Process

Translator (MMU)Translator (MMU)

PhysicalMemoryPhysicalMemory

Virtual Add Physical Add

Page 9: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Address translation

Lots of ways to implement, remember the big picture

Tradeoffs: Flexibility (e.g., sharing, growth, virtual

memory) Size of translation data Speed of translation

04/18/23 9

User ProcessUser Process

Translator (MMU)Translator (MMU)

PhysicalMemoryPhysicalMemory

Virtual Add Physical Add

Page 10: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Base and Limit

Load each process into contiguous regions of physical memory

If(virt addr > bound){

trap to kern

} else {

phys addr =

virt addr + base

}

04/18/23 10

0

0

0

lim2

lim1 base1

base2

base1 + lim1

base2 + lim2

virtual mem

virtual mem physical

mem

Page 11: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Base and limit

What must change during a context switch?

Can a process change its own base and limit?

Can you share memory with another process?

How does the kernel handle the address space growing You are the OS designer, come up with an

algorithm for allowing processes to grow

04/18/23 11

Page 12: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Memory Allocation in the small

04/18/23 12

virtual mem

virtual mem physical

mem

virtual mem

physical mem

virtual mem

physical mem

virtual mem ?

Page 13: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Memory Management w/ Linked Lists

04/18/23 13

AA BB DD EE FFCC

8 16 24 32

Info for each holeBoth ends:

Size of hole Bit saying free or allocatedTogether

Next and Previous pointers to other holesInfo for each allocated “chunk:

Size and allocation bit, together, on each end

Page 14: 12/5/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC  Based on slides by Roy Campbell, Sam King,

Memory Allocation Algorithms

04/18/23 14

AA BB DD EE FFCC

8 16 24 32

Allocated 2 units:First fit

AA BB DD EE FFCC

8 16 24 32

AA BB DD EE FFCC

8 16 24 32

GG

GG

AA BB DD EE FFCC

8 16 24 32

GG

Best fit

Worst fit