You are on page 1of 46

Operating Systems: Internals and Design Principles

Chapter 7 Memory Management


Seventh Edition William Stallings

Memory Management Terms


Table 7.1 Memory Management Terms

Term Frame

Description Fixed-length block of main memory.

Page

Fixed-length block of data in secondary memory (e.g. on disk). Variable-length block of data that resides in secondary memory.

Segment

7.1 Memory Management Requirements




Memory management is intended to satisfy the following requirements:


    

Relocation Protection Sharing Logical organization Physical organization

Relocation

Protection


Processes need to acquire permission to reference memory locations for reading or writing purposes Location of a program in main memory is unpredictable Memory references generated by a process must be checked at run time Mechanisms that support relocation also support protection

  

Base and Limit Registers




A pair of base and limit registers define the logical address space

HW address protection with base and limit registers

Sharing


Advantageous to allow each process access to the same copy of the program rather than have their own separate copy Memory management must allow controlled access to shared areas of memory without compromising protection Mechanisms used to support relocation support sharing capabilities

Shared Library

Logical Organization


Memory is organized as linear

Segmentation is the tool that most readily satisfies requirements

Requirements: Physical Organization


At two levels of memory: main memory and secondary memory. Cannot leave the programmer with the responsibility to move information between the two levels. Memory available for a program plus its data may be insufficient Programmer does not know how much space will be available

7.2 Memory Partitioning




Memory management brings processes into main memory for execution by the processor  involves virtual memory  based on segmentation and paging Partitioning  used in several variations in some now-obsolete operating systems  does not involve virtual memory

Fixed Partitioning


Equal-size partitions  any process whose size is less than or equal to the partition size can be loaded into an available partition The operating system can swap out a process if all partitions are full and no process is in the Ready or Running state
When we set the upper limit of PC-DOS at 640K, we thought nobody would ever need that much memory. William Gates, chairman of Microsoft, April 29, 1985 issue of InfoWorld.

A program may be too big to fit in a partition  program needs to be designed with the use of overlays Main memory utilization is inefficient  any program, regardless of size, occupies an entire partition  internal fragmentation  wasted space due to the block of data loaded being smaller than the partition

Unequal Size Partitions




Using unequal size partitions helps lessen the problems  programs up to 16M can be accommodated without overlays


partitions smaller than 8M allow smaller programs to be accommodated with less internal fragmentation

The use of fixed partitioning is almost unknown today. One example of a successful operating system that did use this technique was an early IBM mainframe operating system, OS/ MFT ( Multiprogramming with a Fixed Number of Tasks).

Memory Assignment
Discussions: 1. Waste of memory for one Q per Par 2. For single Q, when it comes to decide which Par to swap out, what would be your choice?

The number of partitions specified at system generation time limits the number of active processes in the system Small jobs will not utilize partition space efficiently

 

Partitions are of variable length and number Process is allocated exactly as much memory as it requires This technique was used by IBMs mainframe operating system, OS/MVT (Multiprogramming with a
Variable Number of Tasks).

Effect of Dynamic Partitioning

swaps out process 2

swaps process 1 out

Dynamic Partitioning

Placement Algorithms
If there is more than one free block of memory of sufficient size, then the operating system must decide which free block to allocate.

Memory Configuration Example


The first-fit algorithm is not only the simplest but usually the best and fastest as well.

next request is 16MB

Buddy System
 Comprised

of fixed and dynamic partitioning

schemes
 Space

available for allocation is treated as a single block

 Memory
 

blocks are available of size 2K words, L K U, where


2L = smallest size block that is allocated 2U = largest size block that is allocated; generally 2U is the size of the entire memory available for allocation

Buddy System Example

T r e e

R e p r e s e

n t a t i o n

If two buddies are leaf nodes, then at least one must be allocated; otherwise they would be fused into a larger block

A modified form of the buddy system is used for UNIX kernel memory

Addresses

The resulting address is compared to the value in the bounds register. If the address is within bounds, then the instruction execution may proceed. Otherwise, an interrupt is generated to the operating system, which must respond to the error in some fashion.

Partition memory into equal fixed-size chunks that are relatively small Process is also divided into small fixed-size chunks of the same size

Assignment of Process to Free Frames

Page Table
   

Maintained by operating system for each process Contains the frame location for each page in the process Processor must know how to access for the current process Used by processor to produce a physical address

Data Structures

Logical Addresses

1502-750=752 1502 1024 = 478

Logical-toLogical-to-Physical Address Translation - Paging

Paging Hardware

Paging Model of Logical and Physical Memory

Segmentation
A

program can be subdivided into segments  may vary in length  there is a maximum length consists of two parts:
 segment number  an offset

 Addressing

 Similar

to dynamic partitioning fragmentation

 Eliminates internal

Segmentation
 Memory-management scheme that supports user view of memory  A program is a collection of segments. A segment is a logical unit such as:

main program, procedure, function, method, object, local variables, global variables, common block, stack, symbol table, arrays

Operating System Concepts 7th Edition, Feb 22, 2005

8.39

Silberschatz, Galvin and Gagne 2005

Users View of a Program

Operating System Concepts 7th Edition, Feb 22, 2005

8.40

Silberschatz, Galvin and Gagne 2005

Example of Segmentation

Operating System Concepts 7th Edition, Feb 22, 2005

8.41

Silberschatz, Galvin and Gagne 2005

Base

0010000000100000 Offset 001011110000 ================== 0010001100010000

42

Security Issues

Buffer Overflow Attacks


  

Security threat related to memory management Also known as a buffer overrun Can occur when a process attempts to store data beyond the limits of a fixed-sized buffer One of the most prevalent and dangerous types of security attacks

Defending Against Buffer Overflows


 

Detecting and aborting Countermeasure categories:

Run-time defense can be deployed in OS together with HW.

Summary


Memory Management


one of the most important and complex tasks of an operating system needs to be treated as a resource to be allocated to and shared among a number of active processes desirable to maintain as many processes in main memory as possible desirable to free programmers from size restriction in program development basic tools are paging and segmentation (possible to combine)
 

paging small fixed-sized pages segmentation pieces of varying size

You might also like