Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Memory

Management
Frame A fi xed- l engt h bl ock of mai n memor y.
A fi xed- l engt h bl ock of dat a t hat r esi des i n secondar y memor y
Page ( such as di sk) . A page of dat a may t empor ar i l y be copi ed i nt o a
f r ame of mai n memor y.
A var i abl e- l engt h bl ock of dat a t hat r esi des i n secondar y memor y.
An ent i r e segment may t empor ar i l y be copi ed i nt o an avai l abl e
Segment r egi on of mai n memor y ( segment at i on) or t he segment may be di vi ded
i nt o pages whi ch can be i ndi vi dual l y copi ed i nt o mai n memor y
( combi ned segment at i on and pagi ng) .

Memory Management Terms


Memory Management
Requirements
 Memory management is intended to
satisfy the following requirements:
 Relocation
 Protection
 Sharing
 Logical organization
 Physical organization
Relocation
 Programmers typically do not know in advance which other
programs will be resident in main memory at the time of
execution of their program
 Active processes need to be able to be swapped in and out
of main memory in order to maximize processor utilization
 Specifying that a process must be placed in the same
memory region when it is swapped back in would be
limiting
 may need to relocate the process to a different area
of memory
Process control
ProcessControl Block
information Entry point
to program
Branch
Program instruction

Increasing
address
values
Reference
to data

Data

Current top
of stack
Stack

Figure7.1 AddressingRequirements for a Process


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
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
 Memory is organized as linear

 Segmentation is the tool that most readily satisfies


requirements
Physical Organization
Memory Partitioning
Technique Description Strengths Weaknesses

Main memory is divided into a Inefficient use of


number of static partitions at memory due to internal
Simple to implement;
Fixed Partitioning system generation time. A process little operating system fragmentation;
maximum number of
may be loaded into a partition of overhead.
equal or greater size. active processes is
fixed.

Inefficient use of
Partitions are created dynamically, No internal
processor due to the

Memory
so that each process is loaded into a fragmentation; more
Dynamic Partitioning need for compaction to
partition of exactly the same size as efficient use of main
that process. memory. counter external
fragmentation.

Main memory is divided into a


number of equal-size frames. Each
process is divided into a number of
Management
No external A small amount of

Techniques
SimplePaging equal-size pages of the same length
as frames. A process is loaded by fragmentation. internal fragmentation.
loading all of its pages into
available, not necessarily
contiguous, frames.

Each process is divided into a No internal


fragmentation; improved
number of segments. A process is
memory utilization and
SimpleSegmentation loaded by loading all of its External fragmentation.
segments into dynamic partitions reduced overhead
that need not be contiguous. compared to dynamic
partitioning.

No external
As with simple paging, except that
it is not necessary to load all of the fragmentation; higher
Virtual Memory degree of Overhead of complex
pages of a process. Nonresident
Paging pages that are needed are brought in multiprogramming; memory management.
later automatically. large virtual address
space.

No internal
As with simple segmentation,
fragmentation, higher
except that it is not necessary to
degree of
Virtual Memory load all of the segments of a Overhead of complex
multiprogramming;
Segmentation process. Nonresident segments that large virtual address memory management.
are needed are brought in later
space; protection and
automatically.
sharing support.
OperatingSystem OperatingSystem
8M 8M

2M
8M 4M

6M
8M

8M

8M

8M

8M

12M
8M

8M

16M

8M

(a) Equal-sizepartitions (b) Unequal-sizepartitions

Figure7.2 Exampleof Fixed Partitioningof a 64-MbyteMemory


 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
Operating Operating
System System

New New
Processes Processes

(a) Oneprocess queueper partition (b) Singlequeue

Figure7.3 Memory Assignment for Fixed Partitioning


 Thenumber 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 IBM’s mainframe
operating system, OS/MVT
Dynamic Partitioning
OS (8M)

 External Fragmentation
P2
P1
(14M)
(20M)
 Memory external to all processes is
fragmented
Empty (6M)

Empty
P4(8M)
P2
 Can resolve using compaction
(56M)
(14M)  OS moves processes so that they are
Empty (6M)
contiguous
 Time consuming and wastes CPU
P3 time
(18M)

Empty (4M)
Traditional UNIX Systems
 Were developed at Bell Labs and became operational on a PDP-7 in
1970

 Incorporated many ideas from Multics

 PDP-11was a milestone because it first showed that UNIX would be an


OS for all computers

 Next milestone was rewriting UNIX in the programming language C

 demonstrated the advantages of using a high-level language for


system code

 First widely available version outside Bell Labs was Version 6 in


1976

 Version 7, released in 1978 is the ancestor of most modern UNIX


systems

 Most important of the non-AT&T systems was UNIX BSD (Berkeley


Software Distribution)
Operating Operating Operating Operating
System 8M System System System

Process 1 20M Process 1 20M Process 1 20M

56M Process 2 14M Process 2 14M

36M
Process 3 18M
22M

4M

(a) (b) (c) (d)

Operating Operating Operating Operating


System System System System

Process 2 14M
Process 1 20M Process 1 20M 20M

6M
Process 4 8M Process 4 8M Process 4 8M
14M
6M 6M 6M

Process 3 18M Process 3 18M Process 3 18M Process 3 18M

4M 4M 4M 4M

(e) (f) (g) (h)

Figure7.4 TheEffect of Dynamic Partitioning


Dynamic Partitioning
Placement Algorithms
8M 8M

12M 12M
First Fit

22M
6M
Best Fit
Last 18M
allocated 2M
block (14M)

8M 8M

6M 6M
Allocated block

Free block

14M Possible new allocation 14M

Next Fit

36M
20 M

(a) Before (b) After

Figure7.5 ExampleMemory Configuration before


and after Allocation of 16-MbyteBlock
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
1 Mbyteblock 1M

Request 100 K A =128K 128K 256K 512K

Request 240 K A =128K 128K B =256K 512K

Request 64 K A =128K C =64K 64K B =256K 512K

Request 256 K A =128K C =64K 64K B =256K D =256K 256K

ReleaseB A =128K C =64K 64K 256K D =256K 256K

ReleaseA 128K C =64K 64K 256K D =256K 256K

Request 75 K E =128K C =64K 64K 256K D =256K 256K

ReleaseC E =128K 128K 256K D =256K 256K

ReleaseE 512K D =256K 256K

ReleaseD 1M

Figure7.6 Exampleof Buddy System


Addresses
Relativeaddress

Process Control Block


BaseRegister

Adder Program

Absolute
address

Bounds Register Comparator

Data
Interrupt to
operatingsystem

Stack

Process imagein
main memory

Figure7.8 HardwareSupport for Relocation


 Partition memory into equal fixed-size chunks
that are relatively small
 Process is also divided into small fixed-size
chunks of the same size
Frame Main memory Main memory Main memory
number
0 0 A.0 0 A.0
1 1 A.1 1 A.1
2 2 A.2 2 A.2
3 3 A.3 3 A.3
4 4 4 B.0
5 5 5 B.1
6 6 6 B.2
7 7 7
8 8 8
9 9 9
10 10 10
11 11 11
12 12 12
13 13 13
14 14 14

(a) Fifteen Available Frames (b) Load Process A (c) Load Process B

Main memory Main memory Main memory


0 A.0 0 A.0 0 A.0
1 A.1 1 A.1 1 A.1
2 A.2 2 A.2 2 A.2
3 A.3 3 A.3 3 A.3
4 B.0 4 4 D.0
5 B.1 5 5 D.1
6 B.2 6 6 D.2
7 C.0 7 C.0 7 C.0
8 C.1 8 C.1 8 C.1
9 C.2 9 C.2 9 C.2
10 C.3 10 C.3 10 C.3
11 11 11 D.3
12 12 12 D.4
13 13 13
14 14 14

(d) Load Process C (e) Swap out B (f) Load Process D

Figure7.9 Assignment of Process Pages to FreeFrames


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
PAGING MODEL OF LOGICAL AND PHYSICAL
MEMORY
PAGING HARDWARE
PAGING EXAMPLE

32-byte memory and 4-byte pages


16-bit logical address
6-bit page# 10-bit offset

0000010111011110

16-bit logical address


6-bit page# 10-bit01offs et
000101
000110
2 011001
Process
0 0 0 0 0 1 0 1 1 1 0pag1 1110
etable

0001100111011110
16-bit physical address
(a) Paging

16-bit logical address


0 000101
4-bit segment # 12-bit offset
1 000110
0001 20 011001
01011110000
Process
pagetable
Length Base
0 001011101110 0000010000000000
1 011110011110 0010000000100000 +
0001100111011110
Process segment table

16-bit
0010001 1 0 0 phys
0 1 0ical
0 0 addre
0 ss
(a) Paging 16-bit physical address
(b) Segmentation

Figical
16-bit log ure7.12 Exam
addre ssplesof Logical-to-Physical AddressTranslation
4-bit segment #
Segmentation
A program can be subdivided into
segments
 may vary in length
 there is a maximum length
 Addressing consists of two parts:
 segment number
 an offset
 Similar to dynamic partitioning
 Eliminates internal fragmentation
Segmentation
 Usually visible
 Provided as a convenience for organizing
programs and data
 Typically the programmer will assign programs
and data to different segments
 For purposes of modular programming the
program or data may be further broken down
into multiple segments
 the principal inconvenience of this service is that the
programmer must be aware of the maximum segment
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
USER’S VIEW OF A PROGRAM
LOGICAL VIEW OF
SEGMENTATION
1

4
1

3 2
4

user space physical memory space


EXAMPLE OF SEGMENTATION
SEGMENTATION HARDWARE
Address Translation in a Segmentation
System
Address Translation in combined Segmentation/Paging
Comparison of Paging and
Segmentation

A. Frank - P. Weisberg

You might also like