Lecture 18 Reminder: Homework 4 due Wednesday Questions? Monday, February 20

advertisement

Lecture 18

Reminder: Homework 4 due Wednesday

Questions?

Monday, February 20 CS 470 Operating Systems - Lecture 18 1

Outline

Memory management

Storage organization issues

Storage management issues

Memory addressing

Static, complete, contiguous storage organization

Fragmentation

Monday, February 20 CS 470 Operating Systems - Lecture 18 2

Memory Management

Chapter 7 ended the section on processes and

CPU management. Chapter 8 starts a new section on memory management.

Memory management deals with two separate, but related, topics:

Storage organization - how memory is used

Storage management - how/when programs get put into or taken out of memory

Monday, February 20 CS 470 Operating Systems - Lecture 18 3

Storage Organization Issues

The issues in storage organization include providing support for:

 single vs. multiple processes complete vs. partial allocation fixed-size vs. variable-size allocation contiguous vs. fragmented allocation static vs. dynamic allocation of partitions

Different choices for each of these issues results in a different storage organization.

Monday, February 20 CS 470 Operating Systems - Lecture 18 4

Storage Management Issues

The issues in storage management include:

How does memory get associated with a process?

Where do new programs go in memory?

For partial, dynamic allocation schemes, when is memory reallocated to another process?

These issues deal with the allocation policies of memory as a resource.

5 Monday, February 20 CS 470 Operating Systems - Lecture 18

Memory Addressing

(Cache)

RAM

Disk

Storage in a computer system is a hierarchy.

Usually, a program resides on disk as a binary image file. A program needs to be in main memory (RAM) in order to execute.

The OS loads the binary image into memory and attaches it to a process. In most systems, processes can be located almost anywhere in physical memory.

Monday, February 20 CS 470 Operating Systems - Lecture 18 6

Memory Addressing

In the program source, memory locations are addressed symbolically . The actual physical address can be bound to a particular symbolic location at different times:

Compile-time: absolute address must be known.

Recompile if it changes

Load-time: addresses are relative to some base address. Bind the base address before run-time.

Run-time: for most modern OS's, memory is virtual and the logical to physical mapping happens as the program runs. Use special hardware to make this work.

Monday, February 20 CS 470 Operating Systems - Lecture 18 7

Early Storage Organizations

Simplest organization is a single process in memory at a time with absolute addressing.

What is the main limitation of this scheme with respect to running a single program?

Monday, February 20 CS 470 Operating Systems - Lecture 18 8

Early Storage Organizations

Techniques for allowing larger programs

Dynamic loading : load only those parts being used, starting with main( ). Keep track of starting address of each module.

Overlay : sometimes different parts of a program are used at different times. Set up system to load all the common parts, and share the rest of memory between overlays.

Dynamic linking : usually everything a program needs is statically linked into the binary image. This scheme shares images of libraries (mostly for multiprogramming systems).

Monday, February 20 CS 470 Operating Systems - Lecture 18 9

Early Storage Organizations

The problem with these techniques is that they require the programmer to set up the memory.

This can be complex and requires detailed knowledge of the program and the hardware.

Want the OS to take care of managing the memory so that programs of all sizes and types can run efficiently.

10 Monday, February 20 CS 470 Operating Systems - Lecture 18

Address Translation

Most modern OS's use virtual memory . The

CPU/user process generates logical addresses based in a virtual address space. The actual location mapped to a logical address is its physical address and is obtained using the memory management unit (MMU) of the hardware.

CPU

(user pgm) logical addr

MMU

physical addr

Main Memory

Monday, February 20 CS 470 Operating Systems - Lecture 18 11

Static, Complete, Contiguous Organization

Single process systems are not interesting, so we will assume a multi-programmed system.

Start with static , complete , contiguous storage organization. That is, when a program is to be run, it is allocated all its memory space in a contiguous area of memory at load-time .

The base address of this area is loaded into a relocation register of the MMU, and the MMU simply adds the base address to every logical address and does a limit check.

Monday, February 20 CS 470 Operating Systems - Lecture 18 12

Static, Complete, Contiguous Organization

346

MMU: main mem

reloc. reg. 14346

CPU 14000

(user pgm) logical + physical

14346

addr limit chk addr

Note that the CPU/user process never sees the physical address, so the program can be loaded anywhere in memory.

Monday, February 20 CS 470 Operating Systems - Lecture 18 13

Fixed-Size Partitions

If all programs are allocated the same size piece of memory (i.e., fixed-size partitions), the multi-programming is easy to provide.

On admittance, the OS loads program into one of the partitions and stores the base address in the PCB. On a context switch, the base address from the PCB is loaded into the MMU relocation register. The limit check is whatever the size of a partition is.

Monday, February 20 CS 470 Operating Systems - Lecture 18 14

Monday, February 20

P

7

P

2

P

3

P

6

P

5

Fixed-Size Partitions

OS determines when a process can be loaded.

If there is an available partition, admit.

If no available partition, wait.

Release partition on termination.

Still limits size of program.

CS 470 Operating Systems - Lecture 18 15

Variable-Size Partitions

Could also have variable-size partitions. Add a limit register to the MMU and a limit field in the PCB to be used in the limit check.

Also need more management. A (very) small example: Physical memory addresses 0-2560K

(2MB), OS takes 400K at the low end, leaving

2160K for users.

As with process management, give a scenario

(on the next slide)

Monday, February 20 CS 470 Operating Systems - Lecture 18 16

Variable-Size Partitions

P

3

P

4

P

5

P

1

P

2

Memory request CPU burst time (ms)

600K 10

1000K

300K

700K

500K

5

20

8

15

The processes arrive at time 0 in the order specified.

Monday, February 20 CS 470 Operating Systems - Lecture 18 17

Variable-Size Partitions

Only processes in memory can compete for the CPU. Assuming an

RR scheduler, OS can only load P

1

, P

2

, and P

3 into the first 1900K

(600K+1000K+300K) of memory, leaving a 260K

(2160K-1900K) hole of unallocated memory.

Monday, February 20 CS 470 Operating Systems - Lecture 18

OS - 400K

P

1

P

2

- 600K

- 1000K

P

3

- 300K

Hole - 260K

18

Variable-Size Partitions

If q = 1, then P

2

terminates at t = 14, leaving a 1000K hole. This is enough to load

P

4

, leaving a 300K hole.

P

1

terminates at t = 28, and

OS allocates P

5

100K hole.

, leaving a

OS - 400K

P

5

- 500K

Hole - 100K

P

4

- 700K

Hole - 300K

P

3

- 300K

Hole - 260K

Monday, February 20 CS 470 Operating Systems - Lecture 18 19

Variable-Size Partitions

In this scheme, releasing is easy, just add hole to the head of a linked list.

Allocation is much harder - if more than one hole is big enough, which hole?

First fit

Best fit

Worst fit ??

Monday, February 20 CS 470 Operating Systems - Lecture 18 20

Fragmentation

Both schemes suffer from fragmentation , that is, memory space that is unused due to the memory organization.

Variable-size partition organization causes external fragmentation. That is, the unused memory is outside of any allocation. In particular, eventually all the holes will be small, so while there may be enough total free space to run another program, there is not enough contiguous memory to do so.

Monday, February 20 CS 470 Operating Systems - Lecture 18 21

Fragmentation

Fixed-size partition organization causes internal fragmentation. That is, a process has been allocated more memory than it needs to run. On average, a partition will be only half filled. Thus even when all of the memory is allocated, the system could have run more programs had the partitions been smaller.

22 Monday, February 20 CS 470 Operating Systems - Lecture 18

Fragmentation

Since fixed-size partitions are determined by the memory architecture, there is not much that can be done about internal fragmentation.

But we can and should do something about external fragmentation when using variable-size partitions. E.g., in the earlier scenario, when P

1 terminates, it releases 1000K of which P

700K, leaving a 300K hole. If this free space were added to the other 260K hole, 560K would be large enough to hold P

4

took

5

as well.

Monday, February 20 CS 470 Operating Systems - Lecture 18 23

Fragmentation

A simple technique to handle fragmentation is to coalesce holes that are next to each other forming one larger hole of contiguous memory.

This can be done just after a process terminates, but would not handle our scenario.

24 Monday, February 20 CS 470 Operating Systems - Lecture 18

Fragmentation

A better technique is to do compaction . That is, put all the free space together by moving processes. E.g.,

Slide all process towards one end

Move processes from one end to the other

Move processes in the middle to the ends

Deallocation becomes more difficult.

Monday, February 20 CS 470 Operating Systems - Lecture 18 25

Static, Complete, Contiguous Organization

Generally, fixed-size partitions are favored over variable-size partitions. They are faster to allocate and deallocate, and are simpler to manage. Just need to make sure the partition size is big enough, but not too big.

Next class start looking at non-contiguous storage techniques.

Monday, February 20 CS 470 Operating Systems - Lecture 18 26

Download