0% found this document useful (0 votes)
6 views

Mod-1.2

Chapter 2 of 'Understanding Operating Systems' discusses memory management, focusing on four memory allocation schemes: single-user, fixed partitions, dynamic partitions, and relocatable dynamic partitions. It covers allocation methods such as best-fit and first-fit, the importance of memory deallocation, and the role of compaction in improving memory efficiency. The chapter emphasizes that effective memory management is crucial for system performance.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Mod-1.2

Chapter 2 of 'Understanding Operating Systems' discusses memory management, focusing on four memory allocation schemes: single-user, fixed partitions, dynamic partitions, and relocatable dynamic partitions. It covers allocation methods such as best-fit and first-fit, the importance of memory deallocation, and the role of compaction in improving memory efficiency. The chapter emphasizes that effective memory management is crucial for system performance.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 60

Understanding Operating Systems

Seventh Edition

Chapter 2
Memory Management:
Simple Systems
Learning Objectives

After completing this chapter, you should be able to


describe:
• The basic functionality of the four memory
allocation schemes presented in this chapter:
single user, fixed partitions, dynamic partitions, and
relocatable dynamic partitions
• Best-fit memory allocation as well as first-fit
memory allocation
• How a memory list keeps track of available
memory

Understanding Operating Systems, 7e 2


Learning Objectives (cont'd.)
• The importance of memory deallocation
• The importance of the bounds register in memory
allocation schemes
• The role of compaction and how it can improve
memory allocation efficiency

Understanding Operating Systems, 7e 3


Introduction
• Main memory management is critical
• Entire system performance is dependent on two
items:
– Amount of memory available
– Optimization of memory during job processing

Understanding Operating
Understanding Operating Systems,
Systems, 7e 7e 4
Introduction (cont’d.)
• This chapter introduces:
– Role of main memory (RAM)
– Four types: memory allocation schemes
• Single-user systems
• Fixed partitions
• Dynamic partitions
• Relocatable dynamic partitions

Understanding Operating
Understanding Operating Systems,
Systems, 7e 7e 5
Single-User Contiguous Scheme
• Entire program: loaded into memory
• Contiguous memory space: allocated as needed
• Jobs: processed sequentially
• Memory Manager: performs minimal work
1. Evaluates incoming process size: loads if small
enough to fit; otherwise, rejects and evaluates next
incoming process
2. Monitors occupied memory space; when process
ends, makes entire memory space available and
returns to Step 1

Understanding Operating Systems, 7e 6


Single-User Contiguous Scheme
(cont'd.)
• Disadvantages
– Multiprogramming or networking not supported
– Not cost effective: unsuitable for business when
introduced in late 1940s and early 1950s

Understanding Operating Systems, 7e 7


Fixed Partitions
• Permits multiprogramming
• Main memory: partitioned
– Each partition: one job
– Static: reconfiguration requires system shut down
• Responsibilities
– Protecting each job’s memory space
– Matching job size with partition size

Understanding Operating Systems, 7e 8


Fixed Partitions (cont'd.)
• Memory Manager: allocates memory space to jobs
– Information: stored in a table

(table 2.1)
A simplified fixed-partition memory table with the free partition shaded.
© Cengage Learning 2014

Understanding Operating Systems, 7e 9


(figure 2.2)
As the jobs listed in Table 2.1 are loaded into the four fixed partitions,
Job 3 must wait even though Partition 1 has 70K of available memory. Jobs are
allocated space on the basis of “first available partition of required size.”
© Cengage Learning 2014

Understanding Operating Systems, 7e 10


Fixed Partitions (cont'd.)
• Characteristics
– Requires contiguous loading of entire program
– Job allocation method
• First available partition with required size
– To work well:
• All jobs have similar size and memory size known
ahead of time
– Arbitrary partition size leads to undesired results
• Partition too small
– Large jobs have longer turnaround time
• Partition too large
– Memory waste: internal fragmentation

Understanding Operating Systems, 7e 11


Dynamic Partitions
• Main memory: partitioned
– Jobs: given requested memory when loaded
– One contiguous partition per job
• Job allocation method
– First come, first serve
– Memory waste: comparatively small within partitions
• Disadvantages
– Full memory utilization: only when first jobs loaded
– Subsequent allocation: memory waste
• External fragmentation: fragments between blocks

Understanding Operating Systems, 7e 12


(figure 2.3)
Main memory use during
dynamic partition
allocation. Five snapshots
(a-e) of main memory as
eight jobs are submitted
for processing and
allocated space on the
basis of “first come, first
served.” Job 8 has to wait
(e) even though there’s
enough free memory
between partitions to
accommodate it.
© Cengage Learning 2014

Understanding Operating Systems, 7e 13 13


Dynamic Partitions (Class Exercise)
• Suppose you have 8 jobs that need to be executed
• Job 1 = 10K
• Operating System
Job 2 = 15K
• Job 3 = 20K
• Partition 1 = 10K
Job 4 = 50K
Partition 2 = 15K
• Job 5 = 5K
• Job 6 = 30K Partition 3 = 20K
• Job 7 = 10K
Partition 4 = 50K
• Job 8 = 30K

Understanding Operating Systems, 7e 14 14


Dynamic Partitions (Class Exercise)
• Suppose you have 8 jobs that need to be executed
• Job 1 and Job 4 end
• Job 3 ends Operating System

Partition 1 = 10K
Partition 2 = 15K

Partition 3 = 20K

Partition 4 = 50K

Understanding Operating Systems, 7e 15 15


Best-Fit and First-Fit Allocation
• Two methods for free space allocation
– First-fit memory allocation
• Memory Manager: free/busy lists organized by
memory locations (low- to high-order memory)
• Job: assigned first partition large enough
• Fast allocation
– Best-fit memory allocation
• Memory Manager: free/busy lists ordered by size
(smallest to largest)
• Job: assigned smallest partition large enough
• Least wasted space; internal fragmentation reduced

Understanding Operating Systems, 7e 16 16


Best-Fit and First-Fit Allocation
(cont'd.)
• Fixed and dynamic memory allocation schemes:
use both methods
• First-fit memory allocation
– Advantage: faster allocation
– Disadvantage: memory waste
• Best-fit memory allocation
– Advantage: best use of memory space
– Disadvantage: slower allocation

Understanding Operating Systems, 7e 17 17


(figure 2.5)
Using a first-fit scheme, Job 1 claims the first available space. Job 2 then claims the
first partition large enough to accommodate it, but by doing so it takes the last block
large enough to accommodate Job 3. Therefore, Job 3 (indicated by the asterisk)
must wait until a large block becomes available, even though there’s 75K of unused
memory space (internal fragmentation). Notice that the memory list is ordered
according to memory location.
© Cengage Learning 2014

Understanding Operating Systems, 7e 18 18


(figure 2.6)
Best-fit free scheme. Job 1 is allocated to the closest-fitting free partition, as are Job 2
and Job 3. Job 4 is allocated to the only available partition although it isn’t the best-
fitting one. In this scheme, all four jobs are served without waiting. Notice that
the memory list is ordered according to memory size. This scheme uses memory
more efficiently but it’s slower to implement.
© Cengage Learning 2014

Understanding Operating Systems, 7e 19 19


Best-Fit and First-Fit Allocation
(cont'd.)
• First-fit algorithm
– Memory Manager: keeps two lists
• One for free memory
• One for busy memory blocks
– Loop: compares job size to each memory block size
• Until large enough block found: fits the job
– Job: stored into that memory block
– Memory Manager: moves out of the loop
• Fetches next job: entry queue

Understanding Operating Systems, 7e 20


Best-Fit and First-Fit Allocation
(cont'd.)
• First-fit algorithm (cont'd.)
– If entire list searched: no memory block large
enough
• Job: placed into waiting queue
• Memory Manager: fetches next job
– Process repeats

Understanding Operating Systems, 7e 21 21


(table 2.2)
These two snapshots of memory show the status of each memory block before
and after 200 spaces are allocated at address 6785, using the first-fit algorithm.
(Note: All values are in decimal notation unless otherwise indicated.)
© Cengage Learning 2014

Understanding Operating Systems, 7e 22 22


Best-Fit Versus First-Fit Allocation
(cont'd.)
• Best-fit algorithm
– Goal: find smallest memory block where job fits
– Entire table searched before allocation

Understanding Operating Systems, 7e 23 23


(table 2.3)
These two snapshots of memory show the status of each memory block before
and after 200 spaces are allocated at address 7600, using the best-fit algorithm.
© Cengage Learning 2014

Understanding Operating Systems, 7e 24 24


Best-Fit Versus First-Fit Allocation
(cont'd.)
• Hypothetical allocation schemes
– Next-fit: starts searching from last allocated block for
next available block
– Worst-fit: allocates largest free available block
• Opposite of best-fit
• Good way to explore theory of memory allocation
• Not best choice for an actual system

Understanding Operating Systems, 7e 25 25


Deallocation
• Deallocation: releasing allocated memory space
• For fixed-partition system:
– Straightforward process
– Memory Manager: resets the job’s memory block
status to “free” upon job completion
– Any code may be used: e.g., 0 = free and 1 = busy

Understanding Operating Systems, 7e 26 26


Case 1: Joining Two Free Blocks
(cont'd.)
(table 2.4)
This is the original free list
before deallocation for
Case 1. The asterisk
indicates the free memory
block (of size 5) that’s
adjacent to the soon-to-be-
free memory block (of size
200) that’s shaded.
© Cengage Learning 2014

Understanding Operating Systems, 7e 27 27


Deallocation (cont'd.)
• For dynamic-partition system:
– Algorithm: tries to combine free areas of memory
– More complex
• Three dynamic partition system cases: depending
on position of block to be deallocated
– Case 1: adjacent to another free block
– Case 2: between two free blocks
– Case 3: isolated from other free blocks

Understanding Operating Systems, 7e 28 28


Case 1: Joining Two Free Blocks
• Adjacent blocks
• List changes: reflect starting address of the new
free block
– Example: 7600 - address of the first instruction of the
job that just released this block
• Memory block size changes: shows new size for
the new free space
– Combined total: two free partitions
– Example: (200 + 5)

Understanding Operating Systems, 7e 29 29


Case 1: Joining Two Free Blocks
(cont'd.)
(table 2.5)
Case 1. This is the free list
after deallocation. The
shading indicates the
location where changes
were made to indicate the
free memory block (of size
205).
© Cengage Learning 2014

Understanding Operating Systems, 7e 30 30


Case 2: Joining Three Free Blocks
• Deallocated memory space
– Between two free memory blocks
• List changes: reflect starting address of new free
block
– Example: smallest beginning address (7560)
• Three free partitions’ sizes: combined
– Example: (20 + 20 + 205)
• Total size: stored with smallest beginning address
• Last partition: assigned null entry status

Understanding Operating Systems, 7e 31 31


Case 2: Joining Three Free Blocks
(cont'd.)
(table 2.6)
Case 2. This is the Free
List before deallocation.
The asterisks indicate
the two free memory
blocks that are adjacent
to the soon-to-be-free
memory block.
© Cengage Learning 2014

Understanding Operating Systems, 7e 32 32


Case 2: Joining Three Free Blocks
(cont'd.)
(table 2.7)
Case 2. The free
list after a job has
released memory.
The revised entry
is shaded.
© Cengage Learning
2014

Understanding Operating Systems, 7e 33 33


Case 3: Deallocating an Isolated Block
• Deallocated memory space
– Isolated from other free areas
• System: determines released memory block status
– Not adjacent to any free memory blocks
– Between two other busy areas
• System: searches table for a null entry
– Memory block between two other busy memory
blocks: returned to the free list

Understanding Operating Systems, 7e 34 34


Case 3: Deallocating an Isolated Block
(cont'd.)

(table 2.8)
Case 3. Original
free list before
deallocation. The
soon-to-be-free
memory block (at
location 8805) is
not adjacent to
any blocks that
are already free.
© Cengage Learning
2014

Understanding Operating Systems, 7e 35 35


Case 3: Deallocating an Isolated Block
(cont'd.)

(table 2.9)
Case 3. Busy memory list before deallocation. The job to be deallocated is
of size 445 and begins at location 8805. The asterisk indicates the soon-to-
be-free memory block.
© Cengage Learning 2014

Understanding Operating Systems, 7e 36 36


Case 3: Deallocating an Isolated Block
(cont'd.)

(table 2.10)
Case 3. This is the busy list after the job has released its memory. The
asterisk indicates the new null entry in the busy list.
© Cengage Learning 2014

Understanding Operating Systems, 7e 37 37


Case 3: Deallocating an Isolated Block
(cont'd.)
(table 2.11)
Case 3. This is the free
list after the job has
released its memory.
The asterisk indicates
the new free block entry
replacing the null entry.
© Cengage Learning 2014

Understanding Operating Systems, 7e 38 38


Relocatable Dynamic Partitions
• Memory Manager: relocates programs
– All empty blocks: gathered together
• Empty blocks: compacted
– Make one memory block: large enough to
accommodate some or all waiting jobs

Understanding Operating Systems, 7e 39 39


Relocatable Dynamic Partitions
(cont'd.)
• Compaction (memory defragmentation): operating
system reclaims fragmented memory space
sections
– Most or all programs in memory: relocated
• Contiguous arrangement
– Operating system: distinguishes between addresses
and data values
• Every address and address reference: adjusted to
match the program’s new memory location
• Data values: left alone

Understanding Operating Systems, 7e 40 40


(figure 2.7)
An assembly language program that performs a simple incremental operation.
This is what the programmer submits to the assembler. The commands are
shown on the left and the comments explaining each command are shown on
the right after the semicolons.
© Cengage Learning 2014

Understanding Operating Systems, 7e 41 41


(figure 2.8)
The original assembly language program after it has been processed by the
assembler, shown on the right (a). To run the program, the assembler translates
it into machine readable code (b) with all addresses marked by a special symbol
(shown here as an apostrophe) to distinguish addresses from data values. All
addresses (and no data values) must be adjusted after relocation.
© Cengage Learning 2014

Understanding Operating Systems, 7e 42 42


(figure 2.9)
Three snapshots of memory before and after compaction with the operating
system occupying the first 10K of memory. When Job 6 arrives requiring 84K, the
initial memory layout in (a) shows external fragmentation totaling 96K of space.
Immediately after compaction (b), external fragmentation has been eliminated,
making room for Job 6 which, after loading, is shown in (c).
© Cengage Learning 2014

Understanding Operating Systems, 7e 43 43


(figure 2.11)
Contents of the relocation register for Job 4 before the job’s relocation and
compaction (a) and after (b).
© Cengage Learning 2014

Understanding Operating Systems, 7e 44 44


Relocatable Dynamic Partitions
(cont'd.)
• Compaction issues
– What goes on behind the scenes when relocation
and compaction take place?
– What keeps track of how far each job has moved
from its original storage area?
– What lists have to be updated?

Understanding Operating Systems, 7e 45 45


Relocatable Dynamic Partitions
(cont'd.)
• What lists have to be updated?
– Free list
• Showing the partition for the new block of free
memory
– Busy list
• Showing the new locations: all relocated jobs already
in process
– Each job: assigned new address
• Exceptions: those already at the lowest memory
locations

Understanding Operating Systems, 7e 46 46


Relocatable Dynamic Partitions
(cont'd.)
• Special-purpose registers: help with relocation
– Bounds register
• Stores highest location accessible by each program
– Relocation register
• Contains adjustment value: added to each address
referenced in the program; “zero” value, if program
not relocated

Understanding Operating Systems, 7e 47 47


Relocatable Dynamic Partitions
(cont'd.)
• Compacting and relocating: optimizes memory use
– Improves throughput
• Compaction: overhead
• Compaction timing options
– When a certain memory percentage is busy
– When there are waiting jobs
– After a prescribed time period has elapsed
• Goal: optimize processing time and memory use;
keep overhead as low as possible

Understanding Operating Systems, 7e 48 48


Simplified Fixed Partition Memory Table

Partition Partition Memory Access Partition


Number Size address Status
1 100K 200K Job 1 busy

2 25K 300K Job 4 busy

3 25K 325K free

4 50K 350K Job 2 busy


Fixed partition example
Original state
200k

Partition 1 100K Job list:


J1 30K
J2 50K
300k
Partition 2 25K
J3 30K
325k
J4 25K
Partition 3 25K
350k

Partition 4 50K
400k
20 Feb. 2007 OPS110S 50
Job list: Fixed partition example
J1 30K Original state After Job Entry
J2 50K 200k
J3 30K
J4 25K Job 1 (30K)

Partition 1 100K Partition 1

300k
Partition 2 25K Job 4 (25K) Partition 2
325k
Partition 3 25K Partition 3
350k

Partition 4 50K Job 2 (50K) Partition 4


400k
20 Feb. 2007 OPS110S 51
Main memory use and fragmentation
during dynamic partition allocation

Example Job list:


J110K J5 5K
J215K J6 30K
J320K J7 10K
J450K J8 30K

20 Feb. 2007 OPS110S 52


Initial Job Entry After Job 1 and Job 4
Memory Allocation have finished
Operating System Operating System
10K 10K
Job 1 (10K) 10K free
20K 20K
Job 2 (15K) Job 2 (15K)
Job 1 ends Job 5 (5K)
35K 35K arrives
Job 3 (20K) Job 4 ends Job 3 (20K) Job 6 (30K)
arrives
55K 55K

Job 4 (50K) 50K free

105K 105K
After Job 5 and Job 6 After Job 3
have entered has finished
Operating System Operating System
10K 10K
Job 5 (5K) Job 5 (5K)
15K 15K
5K free 5K free
20K 20K
Job 2 (15K) Job 2 (15K)
Job 3 ends Job 7 (10K)
35K 35K arrives
Job 3 (20K) 20K free Job 8 (30K)
arrives
55K 55K
Job 6 (30K) Job 6 (30K)
85K 85K
20K free 20K free
105K 105K
After Job 7
has entered

Operating System
Job 5 (5K) 10K
15K Job 8 has to wait,
5K free
20K even though there
Job 2 (15K) is 35K free memory.
Job 7 (10K) arrives
35K The problem is that
Job 8 (30K) arrives Job 7 (10K) Job 8 must be loaded
45K contiguously, but the
10K free
55K free memory is
Job 6 (30K) fragmented
85K
20K free
105K
Fixed Partition - First-fit Free List
Job 2 claimed the first partition large enough to
accommodate it, but by doing so it took the last
block large enough to accommodate Job 3, so Job
3 must wait, even though there is 75K of unused
memory space
Memory Partition Job Job size Status Fragment.
Job List: location Size Number
J1: 10K 10K 30K J1 10K busy 20K
J2: 20K
J3: 30K 40K 15K J4 10K busy 5K
J4: 10K
55K 50K J2 20K busy 30K

105K 20K free

Total available: 115K Total used: 40K


Fixed Partition - First-fit Free List
(Notice that the following list is ordered according to
memory location)

Memory Partition Job Job size Status Fragment.


Job list: location Size Number
J1: 10K 10K 30K free
J2: 20K
J3: 30K 40K 15K free
J4: 10K 55K 50K free

105K 20K free

Total available: 115K Total used: 0K


Initial memory Memory layout Memory layout
layout after compaction after Job 6 loaded
OS OS OS
10K 10K 10K
Job 1 (8K) Job 1 (8K) Job 1 (8K)
18K 18K 18K
30K Job 4 (32K) Job 4 (32K)
Job 4 (32K) 50K 50K
62K Job 2 (16K) Job 2 (16K)
66K 66K
92K Job 5 (48K) Job 5 (48K)
Job 2 (16K)
108K 114K 114K
Job 5 (48K)
156K Job 6 (84K)

210K 210K 210K


Conclusion
• Four memory management techniques
– Single-user systems, fixed partitions, dynamic
partitions, and relocatable dynamic partitions
• Common to all four techniques
– Entire program: 1) loaded into memory; 2) stored
contiguously; 3) resides in memory until completed
• All schemes
– Place severe restrictions on job size: limited by the
largest petition
– Groundwork for more complex memory
management
Understanding Operating Systems, 7e 59 59
Summary (cont'd.)
• New modern memory management trends in late
1960s and early 1970s
– Discussed in next chapter
– Common characteristics of memory schemes
• Programs are not stored in contiguous memory
• Not all segments reside in memory during job execution

Understanding Operating Systems, 7e 60 60

You might also like