Chapter 4 Storage Management (Memory Management).

22
Chapter 4 Storage Management (Memory Management)

Transcript of Chapter 4 Storage Management (Memory Management).

Page 1: Chapter 4 Storage Management (Memory Management).

Chapter 4

Storage Management

(Memory Management)

Page 2: Chapter 4 Storage Management (Memory Management).

2

Chapter Objectives

This chapter will provide you: How data are map from storage

device to Memory? What is Logical Address and

Physical Address? What is a role of MMU? Process of Memory management?

Page 3: Chapter 4 Storage Management (Memory Management).

3

Introduction The main purpose of a computer system is to

execute programs.

These programs, together with the data they access, must be in main memory (at least partially) during execution.

To improve both the utilization of the CPU and the speed of its response to users, the computer must keep several processes in memory.

Page 4: Chapter 4 Storage Management (Memory Management).

4

Since main memory is usually too small to accommodate all the data and programs permanently, the computer system must provide secondary storage to back up main memory.

The file system provides the mechanism for on-line storage of and access to both data and programs residing on the disks.

A file is a collection of related information defined by its creator. The files are mapped by the operating system onto physical devices. Files are normally organized into directories to ease their use.

Page 5: Chapter 4 Storage Management (Memory Management).

5

Binding of Instructions and Data to Memory Usually, a program resides on a disk as a

binary executable file. The program must be brought into memory and placed within a process for it to be executed.

Depending on the memory management in use, the process may be moved between disk and memory during its execution.

The collection of processes on the disk that is waiting to be brought into memory for execution forms the input queue.

Page 6: Chapter 4 Storage Management (Memory Management).

6

Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes.

Load time: Must generate relocatable code if memory location is not known at compile time.

Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers).

Address binding of instructions and data to memory addresses canhappen at three different stages.

Page 7: Chapter 4 Storage Management (Memory Management).

7

Multistep Processing of a User Program

Page 8: Chapter 4 Storage Management (Memory Management).

8

Logical vs. Physical Address Space

The concept of a logical address space that is bound to a separate physical address space is central to proper memory management.

Logical address – generated by the CPU; also referred to as virtual address.

Physical address – address seen by the memory unit.

The compile-time and load-time address-binding methods generate identical logical and physical addresses. However, the execution-time addresses binding scheme results in differing logical and physical addresses.

Page 9: Chapter 4 Storage Management (Memory Management).

9

Memory-Management Unit (MMU) The run-time mapping from virtual to physical

addresses is done by a hardware device called the (MMU)

Hardware device that maps virtual to physical address.

In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory.

The user program deals with logical addresses; it never sees the real physical addresses.

Page 10: Chapter 4 Storage Management (Memory Management).

10

Dynamic relocation using a relocation register

Page 11: Chapter 4 Storage Management (Memory Management).

11

Dynamic Loading Routine is not loaded until it is called Better memory-space utilization;

unused routine is never loaded. No special support from the operating

system is required implemented through program design.

Page 12: Chapter 4 Storage Management (Memory Management).

12

Swapping A process can be swapped temporarily out of memory to a

backing store, and then brought back into memory for continued execution.

Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images.

Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed.

Modified versions of swapping are found on many systems, i.e., UNIX, Linux, and Windows.

Page 13: Chapter 4 Storage Management (Memory Management).

13

Schematic View of Swapping

Page 14: Chapter 4 Storage Management (Memory Management).

14

Memory Protection Before discussing memory allocation, we must

discuss the issue of memory protection protecting the operating system from user processes, and protecting user processes from one another.

Valid-invalid bit attached to each entry in the page table: “valid” indicates that the associated page is in

the process’ logical address space, and is thus a legal page.

“invalid” indicates that the page is not in the process’ logical address space.

Page 15: Chapter 4 Storage Management (Memory Management).

15

Memory protection process

Page 16: Chapter 4 Storage Management (Memory Management).

16

Memory Allocation One of the simplest methods for

memory allocation is to divide memory into several fixed-sized partitions.

Each partition may contain exactly one process.

Main memory usually into two partitions: Resident operating system, usually held in

low memory with interrupt vector. User processes then held in high memory.

Page 17: Chapter 4 Storage Management (Memory Management).

17

Segmentation Segmentation is a memory-management scheme

that supports this user view of memory.

A logical-address space is a collection of segments. Each segment has a name and a length.

The user's view of memory is not the same as the actual physical memory. The user's view is mapped onto physical memory.

For simplicity of implementation, segments are numbered and are referred to by a segment number, rather than by a segment name.

Page 18: Chapter 4 Storage Management (Memory Management).

18

User’s View of a Program

Page 19: Chapter 4 Storage Management (Memory Management).

19

Logical View of Segmentation

1

3

2

4

1

4

2

3

user space physical memory space

Page 20: Chapter 4 Storage Management (Memory Management).

20

Example of Segmentation

Page 21: Chapter 4 Storage Management (Memory Management).

21

Virtual memory separation of user logical memory from

physical memory. Only part of the program needs to be in

memory for execution. Logical address space can therefore be

much larger than physical address space. Allows for more efficient process creation.

Page 22: Chapter 4 Storage Management (Memory Management).

22

Transfer of a Paged Memory to Contiguous Disk Space