What is the purpose of memory management?

INTRODUCTION

TO

Lecture 10: MEMORY MANAGEMENT (1)

CHRIS STAFF
Dept. of Computer Science and Artificial Intelligence
University of Malta

Next Lecture: Memory Management (2)

Lecture Outline

Aims and Objectives
Issues
Objectives of a Memory Management (MM) System
Virtual Memory
Address Translation Mechanism

Aims and Objectives

  • Issues

  • Objectives

  • Virtual Memory

  • Converting Virtual Memory Addresses into Physical Addresses

Issues

  • Function of Layer 3, in hierarchical model of OS

  • Processes and data need to be in Primary Memory (PM) in order to be operated on, so processes compete for this resource.

  • PM is finite, but must be available for the best runnable process

  • Poor usage of PM can detrimentally effect usage of other resources and user response times

  • In a multiprogramming environment, many processes and their data can be simultaneously co-resident in PM. Need to protect them from each other

Objectives of a Memory Management (MM) System

Relocation

  • Relocatability - the ability to move process around in memory without it affecting its execution

  • OS manages memory, not programmer, and processes may be moved around in memory

  • MM must convert program's logical addresses into physical addresses

  • Process's first address is stored as virtual address 0

  • Static Relocation - Program must be relocated before or during loading of process into memory. Program must always be loaded into same address space in memory, or relocator must be run again.

  • Dynamic Relocation - Process can be freely moved around in memory. Virtual-to-physical address space mapping is done at run-time.

Protection

  • Write Protection - to prevent data & instructions from being over-written.

  • Read Protection - To ensure privacy of data & instructions.

  • OS needs to be protected from user processes, and user processes need to be protected from each other.

  • Memory protection (to prevent memory overlaps) is usually supported by the hardware (limit registers), because most languages allow memory addresses to be computed at run-time.

Sharing

  • Sometimes distinct processes may need to execute the same process (e.g., many users executing same editor), or even the same data (when one process prepares data for another process).

  • When different processes signal or wait the same semaphore, they need to access the same memory address.

  • OS has to allow sharing, while at the same time ensure protection.

Logical Organisation of Memory

  • Uni-dimensional address space

  • If memory was segmented then it would be possible to code programs and sub-routines separately, each with its own degree of protection.

  • The MM would manage inter-segment references at run-time, and could allow a segment to be accessed by many different processes.

    Physical Organisation of Memory

  • PM is expensive, so tends to be limited - but the amount of PM helps to determine the degree of multiprogramming (the number of runnable processes that can be simultaneously maintained)

  • A two-level storage scheme (one RAM, the other slower secondary disk) can be used to virtually increase the overall amount of PM.

  • Processes can be kept in secondary storage and only brought into PM when needed. MM and OS have to manage operation of moving processes between the two levels.

Virtual Memory

  • OS manages the location of processes in memory. Programmer does not need to know where process is - Virtual Machine.

  • Compiler / Interpreter calculates program addresses in relation to the virtual address 0 (first instruction).

  • Dynamic Address Translation Mechanism - transforms virtual addresses into physical addresses. Virtual address space can be smaller or same size as PM.

Address Translation Mechanism

  • DAT mechanism must maintain address translation maps, to indicate where in PM are the virtual storage locations

  • Organisation of Virtual Memory and PM can be completely different

  • Blocks of addresses are mapped, because of overhead of mapping invididual addresses - the block mapping system

  • The larger the block, the smaller the address map, but the fewer the number of processes that can be resident in PM (one process to a block, but many blocks to a process)

  • If all blocks are the same size, then the block is called a Page

  • If blocks can be different sizes, then each block is called a segment

  • A segment can be composed of pages - this is called a Paging/Segmentation System

Addressing in a block mapping system

  • Relocation can be provided by putting the base address of the process into the base register after a context switch

  • Protection of memory space is provided by adding a limit register which contains the length of the address space available to the process.

  • This scheme allows for processes (and all of a process) to be resident in PM

  • only one block of instructions of the current process are required to be in memory. If only these were in PM, with the rest occupying the slower Virtual Memory extension in secondary storage, then more PM space would be available for other processes

  • Address map now has to say where in secondary storage the block containing the address can be found if it is not in PM.

Next Lecture...

Memory Management (2)

What is the purpose of memory management 10 points?

The memory management function keeps track of the status of each memory location, either allocated or free. It determines how memory is allocated among competing processes, deciding which gets memory, when they receive it, and how much they are allowed.

What is the main purpose of the main memory management unit?

A memory management unit (MMU) is a computer hardware component that handles all memory and caching operations associated with the processor. In other words, the MMU is responsible for all aspects of memory management.

What are the three main objectives of memory management?

Objectives of a Memory Management (MM) System Program must always be loaded into same address space in memory, or relocator must be run again. Dynamic Relocation - Process can be freely moved around in memory. Virtual-to-physical address space mapping is done at run-time.

Why is memory management important in C?

Memory management requires that the programmer provides ways to dynamically allocate portions of memory to programs, when requested, and free it for reuse when it is no longer needed. In any advanced computer system, where more than a single process might be running at any given point in time, this is critical.

Bài Viết Liên Quan

Chủ đề