Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some...

57
1

Transcript of Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some...

Page 1: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

1

Page 2: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

Where are we?

2

Page 3: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

3

Software CategoriesApplication software

Software written to address specific needs—to solve problems in the real world

System software

Software that manages a computer system at a fundamental level

Can you name examples of each?

Page 4: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

4

Roles of an Operating System

Operating system = System software that– manages computer resources, such as

memory and input/output devices– provides an interface through which a human

can interact with the computer– allows an application program to interact

with the other computer resources

Page 5: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

5

Roles of an Operating System

Figure 10.1 An operating system interacts with many aspects of a computer system.

What application software have

you used?

What hardware have we encountered in this

class?

What systems software have we encountered

in this class?

Page 6: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

6

Roles of an Operating System

The various roles of an OS generally revolve around the idea of “sharing nicely”

An OS manages resources, and these resources are often shared in one way or another among programs that want to use them

Page 7: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

7

Batch ProcessingThe first OS was a human operator, who organized the various jobs from multiple users into batches of jobs that needed the same resources.

Page 8: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

8

Resource ManagementMultiprogramming

The technique of keeping multiple programs that compete for access to the CPU in main memory at the same time so that they can execute

Memory management

The process of keeping track of what programs are in memory and where in memory they reside

Page 9: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

9

Resource ManagementProcess = A program in execution

Process management = The act of carefully tracking the progress of a process and all of its intermediate states

CPU scheduling = Determining which process in memory is executed by the CPU at any given time

Page 10: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

10

TimesharingTimesharing system = A system that allows multiple users to interact with a computer at the same time

Virtual machine = The illusion created by a time-sharing system that each user has his/her own machine

As computer speed increased, the human operator became the bottleneck

Page 11: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

QUIZ

Compare and contrast multiprgrammingand timesharing!

11

Page 12: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

12

10.2 Memory Management (MM)An OS must employ techniques to

– Track where each program resides in memory– Convert logical addresses into actual, physical addresses

Logical addressReference to a stored value relative to the program making the reference

Physical addressActual address in main memory

Page 13: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

Why does a computer need logical addresses?

13

AssemblyMachine code

Page 14: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

14

Remember from Ch.6

Loader

Program in memory,

a.k.a. process

Execute

Page 15: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

15

Remember from Ch.6

Loader

Program in memory,

a.k.a. process

Execute

Problem: There are many programs (multiprogramming), not just one!(The OS itself is one of them!)

Page 16: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

Visualizing processes in MS Windows

16

CTRL+SHIFT+ ESC

Page 17: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

17

Binding

Figure 10.3 Memory is a continuous set of bits referenced by specific addresses

Program 1:sum is assigned memorylocation 23, a locationrelative to the beginning ofthe process

Logical address for sum (23) is bound to a physical address in memory (20347) beforethe program runs.

Page 18: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

18

A. Single Contiguous MM

There are only two programs in memory:

The operating systemThe application program

Figure 10.4 Main memory divided into two sections

Page 19: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

19

Single Contiguous MM

Figure 10.5 Binding a logical address to a physical one

If A is address 100, and sum has logicaladdress 23, then sumis stored at physicaladdress 123.

Page 20: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

20

Single Contiguous MM recap:

A logical address is simply an integer value relative to the starting point of the program.

A physical address is the logical address plusthe starting location of the program.

Page 21: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

QUIZ: Question 48

21

Page 22: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

Solution

22

Page 23: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

QUIZ: Question 49

23

a. 9223b. 2302c. 7044

Page 24: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

Solution

24

Page 25: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

QUIZ

25

Assuming that the OS is using single, contiguous MM,

and that the program starts at physical address

0x2D7F000, what is the logical address of the object

above?

Page 26: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

26

B. Partitioned MMPartition MM has the OS and any number of other programs in memory simultaneously.There are two schemes for dividing up memory for programs:

– B1. Fixed partitions Main memory is divided into a fixed number of partitions into which programs can be loaded.

– B2. Dynamic partitions Partitions are created as needed to fit the programs waiting to be loaded.

Page 27: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

27

Partitioned MMMemory is divided into a set of partitions (fixed or dynamic), some empty and some allocated to programs

Base register = A register that holds the beginning address of the current partition (the one that is running)

Bounds register = A register that holds the length of the current partition

Page 28: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

28

Partitioned MM example

Figure 10.6 Address resolution in partition memory management

Why check?

Process 3 is currently being executed

Page 29: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

29

Partition Selection AlgorithmsWhich of several empty partitions should the OS allocate to a new program? (B1. Fixed partitions only!)

• First fit Allocate program to the first partition big enough to hold it

• Best fit Allocated program to the smallest partition big enough to hold it

• Worst fit Allocate program to the largest partition big enough to hold it

Why would anyone want to do this?Hint: Think of dynamic partitions

Page 30: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

30

QUIZ: Partition Selection Algorithms

Page 31: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

31

QUIZ An OS is using the fixed partition shown. Requests come in this order for blocks of sizes: P1:900, P2: 50, P3: 730, P4: 1600, and P5: 325

What block will be assigned to each request if the algorithm used is:

• first-fit?• best-fit algorithm is used?• worst-fit algorithm is used?

Page 32: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

32

The Nemesis of all Partition Selection Algorithms: FRAGMENTATION

Source: http://www.technologyuk.net/computing/operating_systems/memory_management.shtml

Page 33: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

33

The Nemesis of all Partition Selection Algorithms: FRAGMENTATION

Page 34: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

34

Solution: Memory compaction

Source: http://www.technologyuk.net/computing/operating_systems/memory_management.shtml

Problem: When moving the process to a different memory space, all its physical addresses need to be re-bound. This slows down all other processes, b/c the OS needs CPU time to do it!

Page 35: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

35

C. Paged MMPaged memory management Processes are divided into fixed-size pages and stored in memory frames when loaded.FrameA fixed-size portion of main memory that holds a process pagePageA fixed-size portion of a process that is stored into a memory frame

We assume that a frame and a page are the same size!

Page 36: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

36

The binding mechanism in

Paged MM

Assume that the page size is 1024 Bytes.If P1 is running and it needs logical address 2566,how is the physical address calculated?

Page 37: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

37

Integer logical address is mapped into an

intermediate logical address of the form

<page number, offset>

Page numberAddress divided by the page size,1024, Use integer division!

2566 DIV 1024 = 2

OffsetThe remainder of the address divided by the page size

2566 MOD 1024 = 518

Intermediate logical address ==> <2, 518>

Now what?

Paged MM example

Page 38: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

38

This intermediate logical address is mapped to a physical address with the help of a page-map table (PMT)

The OS maintains a PMT for every process.

What is the physical address of <2, 518> in P1?

PMT = Paged Map Table

Page 39: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

39

What is the physical address of <2, 518> in P1?

PMT = Paged Map Table

P1 PMT: 2 -> 1515x1024 + 518 = 15,878

Page 40: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

40

What is the physical address of logical address 3100 in P2?

Quick work for next time

Page 41: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

41

What is the physical address of logical address 3100 in P2?

Solution

3100 / 1024 = 33100 % 1024 = 28P2 PMT: 3 -> 1111x1024 + 28 = 11,292

Page 42: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

42

Read the remainder of Section 10.2 (pp.351-2) and take notes:

Define these terms:

– Demand paging – Page swap – Virtual memory– Thrashing

Page 43: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

43

10.3 Process Management

Process management = Mgmt. of the use of the CPU by individual processesProcess = program in execution

A process goes through multiple stages in order to execute

Page 44: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

44

The Process States flowchart

Figure 10.8 The process life cycle

What events can cause a process to move from Running to Waiting state?

• Waiting for user input from KBD• Waiting for a page swap to complete

Page 45: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

45

Process Control Block (PCB)

The PCB is data structure used by the OS to manage information about a process, including

– current value of the program counter– values of all CPU registers for the process– base and bound register values (or PMTs)– accounting information

Each state is represented by a list of PCBs, one for each process in that state

Page 46: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

46

Context SwitchThere is only one CPU and therefore only one set of CPU registers, which contain the values for the currently executing process.

Each time a process is moved to the Running state:– Register values for the currently running process

are stored into its PCB– Its PCB is moved to the list of the state into which it goes– Register values of the new process moving into the

running state are loaded into the CPU– This exchange of register info. is called a context switch

Page 47: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

SKIP 10.4 CPU Scheduling

47

Page 48: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

48

Who am I?

I will always beassociated with PCs, a garage and a fruit.

Page 49: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

49

Read and take notes: Ethical IssuesMedical Privacy - HIPAA

What is HIPAA?

Explain HIPAA privacy rule(s).

Do you think privacy protection is needed? Why or why not?

Page 50: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

Practice/review problems for ch.10:

• 1 through 12

• 27 through 35

• 42, 43, 51, 54, 56, 58, 59, 60, 63, 64, 66

• Extra questions on the following slides …

50

Not a homework, do not turn in!

Page 51: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

QUIZ

51

Why do we need logical addresses? Couldn’t

we compile the programs directly with the

physical addresses?

Page 52: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

Solution

52

Why do we need logical addresses? Couldn’t we

compile the programs directly with the physical

addresses?

A: No, modern computers run multiple programs

simultaneously (multiprogramming!), so they cannot

all start at address zero in the main memory.

Page 53: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

QUIZ:

53

What does contiguous mean in Single, contiguous

memory management?

Page 54: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

Solution

54

What does contiguous mean in Single, contiguous

memory management?

A: The one (single) application program is loaded

into one uninterrupted (continguous!) chunk of MM.

Page 55: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

QUIZ: Fill in the blanks

55

• Single, contiguous memory management is

used when the MM of the computer contains

___________________________________.

• Partition memory management is used when

the MM of the computer contains ________

___________________________________.

Page 56: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

56

Chapter review questions

• Describe the two main responsibilities of an operating system

• Define memory and process management• Explain how timesharing creates the virtual

machine illusion• Explain the relationship between logical and

physical addresses• Compare and contrast the three memory

management techniques presented

Page 57: Where are we?Memory is divided into a set of . partitions (fixed or dynamic), some empty and some allocated to programs. Base register = A register that holds the . beginning address.

57

• Distinguish between fixed and dynamic partitions

• Define and apply partition selection algorithms

• Explain how demand paging creates the virtual memory illusion

• Explain the stages and transitions of the process life cycle

• Explain the operation of the 3 CPU scheduling algorithms presented

Chapter review questions