SlideShare a Scribd company logo
Chapter 2
Memory Management:
Early Systems
Understanding Operating Systems, Fourth Edition
Understanding Operating Systems, Fourth Edition 2
Objectives
You will be able to describe:
 The basic functionality of the three memory
allocation schemes presented in this chapter:
fixed partitions, dynamic partitions, relocatable
dynamic partitions
 Best-fit memory allocation as well as first-fit
memory allocation schemes
 How a memory list keeps track of available
memory
 The importance of deallocation of memory in a
dynamic partition system
Understanding Operating Systems, Fourth Edition 3
Objectives (continued)
Students should be able to describe:
 The importance of the bounds register in memory
allocation schemes
 The role of compaction and how it improves
memory allocation efficiency
Understanding Operating Systems, Fourth Edition 4
Memory Management: Early
Systems
“Memory is the primary and fundamental power,
without which there could be no other intellectual
operation.” —Samuel Johnson (1709–1784)
Understanding Operating Systems, Fourth Edition 5
Memory Management: Early
Systems
 Types of memory allocation schemes:
 Single-user systems
 Fixed partitions
 Dynamic partitions
 Relocatable dynamic partitions
Understanding Operating Systems, Fourth Edition 6
Single-User Contiguous
Scheme
 Single-User Contiguous Scheme: Program
is loaded in its entirety into memory and
allocated as much contiguous space in memory
as it needs
 Jobs processed sequentially in single-user
systems
 Requires minimal work by the Memory Manager

Register to store the base address

Accumulator to keep track of the program size
Understanding Operating Systems, Fourth Edition 7
Single-User Contiguous
Scheme (continued)
 Disadvantages of Single-User Contiguous
Scheme:
 Doesn’t support multiprogramming
 Not cost effective
Understanding Operating Systems, Fourth Edition 8
Fixed Partitions
 Fixed Partitions: Main memory is partitioned;
one partition/job
 Allows multiprogramming
 Partition sizes remain static unless and until
computer system id shut down, reconfigured, and
restarted
 Requires protection of the job’s memory space
 Requires matching job size with partition size
Understanding Operating Systems, Fourth Edition 9
Fixed Partitions (continued)
Table 2.1: A simplified fixed partition memory table with the
free partition shaded
To allocate memory spaces to jobs, the operating system’s
Memory Manager must keep a table as shown below:
Understanding Operating Systems, Fourth Edition 10
Fixed Partitions (continued)
Figure 2.1: Main memory use during fixed partition allocation
of Table 2.1
NOTE: Job 3 must
wait even though
70K of free space
is available in
Partition 1 where
Job 1 occupies
only 30K of the
100K available
Understanding Operating Systems, Fourth Edition 11
Fixed Partitions (continued)
 Disadvantages:
 Requires entire program to be stored contiguously
 Jobs are allocated space on the basis of first
available partition of required size
 Works well only if all of the jobs are of the same
size or if the sizes are known ahead of time
 Arbitrary partition sizes lead to undesired results

Too small a partition size results in large jobs
having longer turnaround time

Too large a partition size results in memory
waste or internal fragmentation
Understanding Operating Systems, Fourth Edition 12
Dynamic Partitions
 Dynamic Partitions: Jobs are given only as
much memory as they request when they are
loaded
 Available memory is kept in contiguous blocks
 Memory waste is comparatively small
 Disadvantages:
 Fully utilizes memory only when the first jobs are
loaded
 Subsequent allocation leads to memory waste or
external fragmentation
Understanding Operating Systems, Fourth Edition 13
Dynamic Partitions
(continued)
Figure 2.2: Main memory use during dynamic partition allocation
Understanding Operating Systems, Fourth Edition 14
Dynamic Partitions
(continued)
Figure 2.2 (continued): Main memory use during dynamic partition allocation
Understanding Operating Systems, Fourth Edition 15
Best-Fit Versus First-Fit
Allocation
 Free partitions are allocated on the following
basis:
 First-fit memory allocation: First partition
fitting the requirements

Leads to fast allocation of memory space
 Best-fit memory allocation: Smallest partition
fitting the requirements

Results in least wasted space

Internal fragmentation reduced but not
eliminated
Understanding Operating Systems, Fourth Edition 16
Best-Fit Versus First-Fit
Allocation (continued)
 First-fit memory allocation:
 Advantage: Faster in making allocation
 Disadvantage: Leads to memory waste
 Best-fit memory allocation
 Advantage: Makes the best use of memory
space
 Disadvantage: Slower in making allocation
Understanding Operating Systems, Fourth Edition 17
Best-Fit Versus First-Fit
Allocation (continued)
Figure 2.3: An example of a first-fit free scheme
Understanding Operating Systems, Fourth Edition 18
Best-Fit Versus First-Fit
Allocation (continued)
Figure 2.4: An example of a best-fit free scheme
Understanding Operating Systems, Fourth Edition 19
Best-Fit Versus First-Fit
Allocation (continued)
 Algorithm for First-Fit:
 Assumes Memory Manager keeps two lists, one
for free memory and one for busy memory blocks
 Loop compares the size of each job to the size of
each memory block until a block is found that’s
large enough to fit the job
 Job is stored into that block of memory
 Memory Manager moves out of the loop to fetch
the next job from the entry queue
Understanding Operating Systems, Fourth Edition 20
Best-Fit Versus First-Fit
Allocation (continued)
 Algorithm for First-Fit (continued):
 If the entire list is searched in vain, then the job is
placed into a waiting queue
 The Memory Manager then fetches the next job
and repeats the process
Understanding Operating Systems, Fourth Edition 21
Best-Fit Versus First-Fit
Allocation (continued)
Table 2.2: Status of each memory block before and after a
request is made for a block of 200 spaces using
the first-fit algorithm
Understanding Operating Systems, Fourth Edition 22
Best-Fit Versus First-Fit
Allocation (continued)
 Algorithm for Best-Fit:
 Goal: find the smallest memory block into which
the job will fit
 Entire table must be searched before allocation
Understanding Operating Systems, Fourth Edition 23
Best-Fit Versus First-Fit
Allocation (continued)
Table 2.3: Status of each memory block before and after a
request is made for a memory block of 200 spaces
using the best-fit algorithm
Understanding Operating Systems, Fourth Edition 24
Best-Fit Versus First-Fit
Allocation (continued)
 Hypothetical allocation schemes:
 Next-fit: Starts searching from last allocated
block, for the next available block when a new job
arrives
 Worst-fit: Allocates the largest free available
block to the new job

Opposite of best-fit

Good way to explore the theory of memory
allocation; might not be the best choice for an
actual system
Understanding Operating Systems, Fourth Edition 25
Determine the number of jobs processed, total memory used and
total internal fragmentation using first-fit and best-fit memory
allocation.
Job List:
Job number
Memory
Requested
J1 5K
J2 20K
J3 35K
J4 50K
Memory List:
Memory
Location
Memory
Block
size Job number Job size Status
Internal
Fragment
ation
10240 60K        
40960 15K        
56320 50K        
107520 20K        
Total Available:   Total Used:      
Understanding Operating Systems, Fourth Edition 26
Deallocation
 Deallocation: Freeing an allocated memory
space
 For fixed-partition system:

Straightforward process

When job completes, Memory Manager resets
the status of the job’s memory block to “free”

Any code—for example, binary values with 0
indicating free and 1 indicating busy—may be
used
Understanding Operating Systems, Fourth Edition 27
Deallocation (continued)
 For dynamic-partition system:
 Algorithm tries to combine free areas of memory
whenever possible
 Three cases:

Case 1: When the block to be deallocated is
adjacent to another free block

Case 2: When the block to be deallocated is
between two free blocks

Case 3: When the block to be deallocated is
isolated from other free blocks
Understanding Operating Systems, Fourth Edition 28
Deallocation:
Dynamic Partition System
 Case 1: Joining Two Free Blocks
 Change list must reflect starting address of the
new free block

In the example, 7600—which was the address
of the first instruction of the job that just
released this block
 Memory block size for the new free space must be
changed to show its new size—that is, the
combined total of the two free partitions

In the example, (200 + 5)
Understanding Operating Systems, Fourth Edition 29
Case 1: Joining Two Free
Blocks
Table 2.4: Original free list before deallocation for Case 1
Understanding Operating Systems, Fourth Edition 30
Case 1: Joining Two Free
Blocks (continued)
Table 2.5: Free list after deallocation for Case 1
Understanding Operating Systems, Fourth Edition 31
Deallocation:
Dynamic Partition System
(continued)
 Case 2: Joining Three Free Blocks.
Deallocated memory space is between two free
memory blocks
 Change list to reflect the starting address of the
new free block

In the example, 7560— which was the smallest
beginning address
 Sizes of the three free partitions must be
combined

In the example, (20 + 20 + 205)
 Combined entry is given the status of null entry

In the example, 7600
Understanding Operating Systems, Fourth Edition 32
Case 2: Joining Three Free
Blocks
Table 2.6: Original free list before deallocation for Case 2
Understanding Operating Systems, Fourth Edition 33
Case 2: Joining Three Free
Blocks (continued)
Table 2.7: Free list after job has released memory
Understanding Operating Systems, Fourth Edition 34
Deallocation:
Dynamic Partition System
(continued)
 Case 3: Deallocating an Isolated Block.
Space to be deallocated is isolated from other
free areas
 System learns that the memory block to be
released is not adjacent to any free blocks of
memory, it is between two other busy areas
 Must search the table for a null entry
 Null entry in the busy list occurs when a memory
block between two other busy memory blocks is
returned to the free list
Understanding Operating Systems, Fourth Edition 35
Case 3: Deallocating an
Isolated Block
Table 2.8: Original free list before deallocation for Case 3
Understanding Operating Systems, Fourth Edition 36
Case 3: Deallocating an
Isolated Block (continued)
Table 2.9:
The job to be deallocated is of size 445 and begins at
location 8805. The asterisk indicates the soon-to-be-free
memory block.
Table 2.9: Memory list before deallocation
Understanding Operating Systems, Fourth Edition 37
Case 3: Deallocating an
Isolated Block (continued)
Table 2.10: Busy list after the job has released its memory.
The asterisk indicates the new null entry in the
busy list.
Understanding Operating Systems, Fourth Edition 38
Case 3: Deallocating an
Isolated Block (continued)
Table 2.11: Free list after the job has released its memory.
The asterisk indicates the new free block entry
replacing the null entry
Understanding Operating Systems, Fourth Edition 39
Relocatable Dynamic
Partitions
 Relocatable Dynamic Partitions:
 Memory Manager relocates programs to gather
together all of the empty blocks
 Compact the empty blocks to make one block of
memory large enough to accommodate some or
all of the jobs waiting to get in
Understanding Operating Systems, Fourth Edition 40
Relocatable Dynamic
Partitions
(continued)
 Compaction: Reclaiming fragmented sections
of the memory space
 Every program in memory must be relocated so
they are contiguous
 Operating system must distinguish between
addresses and data values

Every address must be adjusted to account for
the program’s new location in memory

Data values must be left alone
Understanding Operating Systems, Fourth Edition 41
Relocatable Dynamic
Partitions
(continued)
Figure 2.5: An assembly language program that performs
a simple incremental operation
Understanding Operating Systems, Fourth Edition 42
Relocatable Dynamic
Partitions
(continued)
Figure 2.6: The original assembly language program
after it has been processed by the
assembler
Understanding Operating Systems, Fourth Edition 43
Relocatable Dynamic
Partitions
(continued)
 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, Fourth Edition 44
Relocatable Dynamic
Partitions
(continued)
 What lists have to be updated?
 Free list must show the partition for the new block
of free memory
 Busy list must show the new locations for all of the
jobs already in process that were relocated
 Each job will have a new address except for those
that were already at the lowest memory locations
Understanding Operating Systems, Fourth Edition 45
Relocatable Dynamic
Partitions
(continued)
 Special-purpose registers are used for relocation:
 Bounds register

Stores highest location accessible by each
program
 Relocation register

Contains the value that must be added to each
address referenced in the program so it will be
able to access the correct memory addresses
after relocation

If the program isn’t relocated, the value stored
in the program’s relocation register is zero
Understanding Operating Systems, Fourth Edition 46
Relocatable Dynamic
Partitions
(continued)
Figure 2.7: Three snapshots of memory before and after
compaction
Understanding Operating Systems, Fourth Edition 47
Relocatable Dynamic
Partitions
(continued)
Figure 2.8: Contents of relocation register and close-up of
Job 4 memory area (a) before relocation and
(b) after relocation and compaction
Understanding Operating Systems, Fourth Edition 48
Relocatable Dynamic
Partitions
(continued)
 Compacting and relocating optimizes the use of
memory and thus improves throughput
 Options for when and how often it should be
done:
 When a certain percentage of memory is busy
 When there are jobs waiting to get in
 After a prescribed amount of time has elapsed
Goal: Optimize processing time and memory use
while keeping overhead as low as possible
Understanding Operating Systems, Fourth Edition 49
Summary
 Four memory management techniques were
used in early systems: single-user systems, fixed
partitions, dynamic partitions, and relocatable
dynamic partitions
 Memory waste in dynamic partitions is
comparatively small as compared to fixed
partitions
 First-fit is faster in making allocation but leads to
memory waste
 Best-fit makes the best use of memory space but
slower in making allocation
Understanding Operating Systems, Fourth Edition 50
Summary (continued)
 Compacting and relocating optimizes the use of
memory and thus improves throughput
 All techniques require that the entire program
must:
 Be loaded into memory
 Be stored contiguously
 Remain in memory until the job is completed
 Each technique puts severe restrictions on the size
of the jobs: can only be as large as the largest
partitions in memory

More Related Content

What's hot (20)

ODP
Distributed operating system(os)
Dinesh Modak
 
PPT
Memory Management in OS
vampugani
 
PPTX
Kernel I/O subsystem
AtiKa Bhatti
 
PPTX
Distributed operating system
Prankit Mishra
 
PPTX
Page replacement algorithms
Piyush Rochwani
 
PDF
Deadlock Avoidance - OS
MsAnita2
 
PPT
17. Recovery System in DBMS
koolkampus
 
PPTX
Kernel. Operating System
pratikkadam78
 
PPT
Scheduling algorithms
Chankey Pathak
 
PPTX
Demand paging
Trinity Dwarka
 
PPTX
Cpu scheduling in operating System.
Ravi Kumar Patel
 
PPTX
SCHEDULING ALGORITHMS
Dhaval Sakhiya
 
PDF
Distributed Operating System_1
Dr Sandeep Kumar Poonia
 
PPTX
Architecture of operating system
Supriya Kumari
 
PPTX
Free Space Management, Efficiency & Performance, Recovery and NFS
United International University
 
PDF
Monitors
Mohd Arif
 
PPTX
Thread scheduling in Operating Systems
Nitish Gulati
 
PPTX
Producer consumer problem operating system
Al Mamun
 
PPT
Mutual exclusion and sync
Dr. C.V. Suresh Babu
 
PDF
Multiprocessing operating systems
Chathurangi Shyalika
 
Distributed operating system(os)
Dinesh Modak
 
Memory Management in OS
vampugani
 
Kernel I/O subsystem
AtiKa Bhatti
 
Distributed operating system
Prankit Mishra
 
Page replacement algorithms
Piyush Rochwani
 
Deadlock Avoidance - OS
MsAnita2
 
17. Recovery System in DBMS
koolkampus
 
Kernel. Operating System
pratikkadam78
 
Scheduling algorithms
Chankey Pathak
 
Demand paging
Trinity Dwarka
 
Cpu scheduling in operating System.
Ravi Kumar Patel
 
SCHEDULING ALGORITHMS
Dhaval Sakhiya
 
Distributed Operating System_1
Dr Sandeep Kumar Poonia
 
Architecture of operating system
Supriya Kumari
 
Free Space Management, Efficiency & Performance, Recovery and NFS
United International University
 
Monitors
Mohd Arif
 
Thread scheduling in Operating Systems
Nitish Gulati
 
Producer consumer problem operating system
Al Mamun
 
Mutual exclusion and sync
Dr. C.V. Suresh Babu
 
Multiprocessing operating systems
Chathurangi Shyalika
 

Viewers also liked (20)

PPT
Memory management early_systems
Mybej Che
 
PPT
Memory management
Vishal Singh
 
PPTX
Memory management
Muhammad Fayyaz
 
PDF
Memory management
Rajni Sirohi
 
PPT
Understanding operating systems 5th ed ch01
BarrBoy
 
PPTX
Memory Management | Computer Science
Transweb Global Inc
 
PPT
Disk scheduling
niralim40
 
PPT
Os Swapping, Paging, Segmentation and Virtual Memory
sgpraju
 
PPTX
Operating System-Memory Management
Akmal Cikmat
 
PPT
Computer memory management
Kumar
 
PPT
Understanding operating systems 5th ed ch03
BarrBoy
 
PPT
Operating System Deadlock Galvin
Sonali Chauhan
 
PPT
CPU Scheduling Algorithms
Shubhashish Punj
 
PDF
Operating system Memory management
Shashank Asthana
 
PPT
Understanding operating systems 5th ed ch02
BarrBoy
 
ODP
Unix Memory Management - Operating Systems
Drishti Bhalla
 
PPT
Mark and sweep algorithm(garbage collector)
Ashish Jha
 
PPTX
Storage management
Atul Sharma
 
PPT
Linux Memory Management
Rajan Kandel
 
PPTX
cpu scheduling
hashim102
 
Memory management early_systems
Mybej Che
 
Memory management
Vishal Singh
 
Memory management
Muhammad Fayyaz
 
Memory management
Rajni Sirohi
 
Understanding operating systems 5th ed ch01
BarrBoy
 
Memory Management | Computer Science
Transweb Global Inc
 
Disk scheduling
niralim40
 
Os Swapping, Paging, Segmentation and Virtual Memory
sgpraju
 
Operating System-Memory Management
Akmal Cikmat
 
Computer memory management
Kumar
 
Understanding operating systems 5th ed ch03
BarrBoy
 
Operating System Deadlock Galvin
Sonali Chauhan
 
CPU Scheduling Algorithms
Shubhashish Punj
 
Operating system Memory management
Shashank Asthana
 
Understanding operating systems 5th ed ch02
BarrBoy
 
Unix Memory Management - Operating Systems
Drishti Bhalla
 
Mark and sweep algorithm(garbage collector)
Ashish Jha
 
Storage management
Atul Sharma
 
Linux Memory Management
Rajan Kandel
 
cpu scheduling
hashim102
 
Ad

Similar to Ch02 early system memory management (20)

PDF
chapter2-OS.pdf
MuhammedAyman10
 
PPT
Chap7
Mothi R
 
PDF
INTRODUCTION TO OPERATING SYSTEM_LESSON_2_SHARE.pdf
Nana Kofi Annan
 
PPT
Chapter 8 : Memory
Amin Omi
 
PPT
amer-memory1.ppt
RohitPaul71
 
PPT
Memory Management
Munazza-Mah-Jabeen
 
PPTX
Memory allocation for real time operating system
Asma'a Lafi
 
PPTX
local_media3192961381667787861026781.pptx
Lyn B
 
PPTX
4-Memory Management -Main memoryyesno.pptx
adeljoby2004
 
PPT
memory mgmt.ppt
Albin562191
 
PDF
Memory management OS
UmeshchandraYadav5
 
PPTX
Memory Management
SanthiNivas
 
PPTX
Dos
Erm78
 
PDF
Unit iiios Storage Management
donny101
 
PPTX
Main Memory Management in Operating System
Rashmi Bhat
 
PPTX
Memory Management in Linux-.ppt|FREE DOWNLOAD
faizanayub16
 
DOCX
Scheme of Evaluation Computer organization
truparanicse
 
PDF
Operating Systems Part III-Memory Management
Ajit Nayak
 
PDF
operating system anna university Unit 4 Part 2.pdf
iamsyril21
 
chapter2-OS.pdf
MuhammedAyman10
 
Chap7
Mothi R
 
INTRODUCTION TO OPERATING SYSTEM_LESSON_2_SHARE.pdf
Nana Kofi Annan
 
Chapter 8 : Memory
Amin Omi
 
amer-memory1.ppt
RohitPaul71
 
Memory Management
Munazza-Mah-Jabeen
 
Memory allocation for real time operating system
Asma'a Lafi
 
local_media3192961381667787861026781.pptx
Lyn B
 
4-Memory Management -Main memoryyesno.pptx
adeljoby2004
 
memory mgmt.ppt
Albin562191
 
Memory management OS
UmeshchandraYadav5
 
Memory Management
SanthiNivas
 
Dos
Erm78
 
Unit iiios Storage Management
donny101
 
Main Memory Management in Operating System
Rashmi Bhat
 
Memory Management in Linux-.ppt|FREE DOWNLOAD
faizanayub16
 
Scheme of Evaluation Computer organization
truparanicse
 
Operating Systems Part III-Memory Management
Ajit Nayak
 
operating system anna university Unit 4 Part 2.pdf
iamsyril21
 
Ad

Recently uploaded (20)

PDF
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
Edge AI and Vision Alliance
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PDF
Home Cleaning App Development Services.pdf
V3cube
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
[GDGoC FPTU] Spring 2025 Summary Slidess
minhtrietgect
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
Edge AI and Vision Alliance
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
Home Cleaning App Development Services.pdf
V3cube
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
[GDGoC FPTU] Spring 2025 Summary Slidess
minhtrietgect
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 

Ch02 early system memory management

  • 1. Chapter 2 Memory Management: Early Systems Understanding Operating Systems, Fourth Edition
  • 2. Understanding Operating Systems, Fourth Edition 2 Objectives You will be able to describe:  The basic functionality of the three memory allocation schemes presented in this chapter: fixed partitions, dynamic partitions, relocatable dynamic partitions  Best-fit memory allocation as well as first-fit memory allocation schemes  How a memory list keeps track of available memory  The importance of deallocation of memory in a dynamic partition system
  • 3. Understanding Operating Systems, Fourth Edition 3 Objectives (continued) Students should be able to describe:  The importance of the bounds register in memory allocation schemes  The role of compaction and how it improves memory allocation efficiency
  • 4. Understanding Operating Systems, Fourth Edition 4 Memory Management: Early Systems “Memory is the primary and fundamental power, without which there could be no other intellectual operation.” —Samuel Johnson (1709–1784)
  • 5. Understanding Operating Systems, Fourth Edition 5 Memory Management: Early Systems  Types of memory allocation schemes:  Single-user systems  Fixed partitions  Dynamic partitions  Relocatable dynamic partitions
  • 6. Understanding Operating Systems, Fourth Edition 6 Single-User Contiguous Scheme  Single-User Contiguous Scheme: Program is loaded in its entirety into memory and allocated as much contiguous space in memory as it needs  Jobs processed sequentially in single-user systems  Requires minimal work by the Memory Manager  Register to store the base address  Accumulator to keep track of the program size
  • 7. Understanding Operating Systems, Fourth Edition 7 Single-User Contiguous Scheme (continued)  Disadvantages of Single-User Contiguous Scheme:  Doesn’t support multiprogramming  Not cost effective
  • 8. Understanding Operating Systems, Fourth Edition 8 Fixed Partitions  Fixed Partitions: Main memory is partitioned; one partition/job  Allows multiprogramming  Partition sizes remain static unless and until computer system id shut down, reconfigured, and restarted  Requires protection of the job’s memory space  Requires matching job size with partition size
  • 9. Understanding Operating Systems, Fourth Edition 9 Fixed Partitions (continued) Table 2.1: A simplified fixed partition memory table with the free partition shaded To allocate memory spaces to jobs, the operating system’s Memory Manager must keep a table as shown below:
  • 10. Understanding Operating Systems, Fourth Edition 10 Fixed Partitions (continued) Figure 2.1: Main memory use during fixed partition allocation of Table 2.1 NOTE: Job 3 must wait even though 70K of free space is available in Partition 1 where Job 1 occupies only 30K of the 100K available
  • 11. Understanding Operating Systems, Fourth Edition 11 Fixed Partitions (continued)  Disadvantages:  Requires entire program to be stored contiguously  Jobs are allocated space on the basis of first available partition of required size  Works well only if all of the jobs are of the same size or if the sizes are known ahead of time  Arbitrary partition sizes lead to undesired results  Too small a partition size results in large jobs having longer turnaround time  Too large a partition size results in memory waste or internal fragmentation
  • 12. Understanding Operating Systems, Fourth Edition 12 Dynamic Partitions  Dynamic Partitions: Jobs are given only as much memory as they request when they are loaded  Available memory is kept in contiguous blocks  Memory waste is comparatively small  Disadvantages:  Fully utilizes memory only when the first jobs are loaded  Subsequent allocation leads to memory waste or external fragmentation
  • 13. Understanding Operating Systems, Fourth Edition 13 Dynamic Partitions (continued) Figure 2.2: Main memory use during dynamic partition allocation
  • 14. Understanding Operating Systems, Fourth Edition 14 Dynamic Partitions (continued) Figure 2.2 (continued): Main memory use during dynamic partition allocation
  • 15. Understanding Operating Systems, Fourth Edition 15 Best-Fit Versus First-Fit Allocation  Free partitions are allocated on the following basis:  First-fit memory allocation: First partition fitting the requirements  Leads to fast allocation of memory space  Best-fit memory allocation: Smallest partition fitting the requirements  Results in least wasted space  Internal fragmentation reduced but not eliminated
  • 16. Understanding Operating Systems, Fourth Edition 16 Best-Fit Versus First-Fit Allocation (continued)  First-fit memory allocation:  Advantage: Faster in making allocation  Disadvantage: Leads to memory waste  Best-fit memory allocation  Advantage: Makes the best use of memory space  Disadvantage: Slower in making allocation
  • 17. Understanding Operating Systems, Fourth Edition 17 Best-Fit Versus First-Fit Allocation (continued) Figure 2.3: An example of a first-fit free scheme
  • 18. Understanding Operating Systems, Fourth Edition 18 Best-Fit Versus First-Fit Allocation (continued) Figure 2.4: An example of a best-fit free scheme
  • 19. Understanding Operating Systems, Fourth Edition 19 Best-Fit Versus First-Fit Allocation (continued)  Algorithm for First-Fit:  Assumes Memory Manager keeps two lists, one for free memory and one for busy memory blocks  Loop compares the size of each job to the size of each memory block until a block is found that’s large enough to fit the job  Job is stored into that block of memory  Memory Manager moves out of the loop to fetch the next job from the entry queue
  • 20. Understanding Operating Systems, Fourth Edition 20 Best-Fit Versus First-Fit Allocation (continued)  Algorithm for First-Fit (continued):  If the entire list is searched in vain, then the job is placed into a waiting queue  The Memory Manager then fetches the next job and repeats the process
  • 21. Understanding Operating Systems, Fourth Edition 21 Best-Fit Versus First-Fit Allocation (continued) Table 2.2: Status of each memory block before and after a request is made for a block of 200 spaces using the first-fit algorithm
  • 22. Understanding Operating Systems, Fourth Edition 22 Best-Fit Versus First-Fit Allocation (continued)  Algorithm for Best-Fit:  Goal: find the smallest memory block into which the job will fit  Entire table must be searched before allocation
  • 23. Understanding Operating Systems, Fourth Edition 23 Best-Fit Versus First-Fit Allocation (continued) Table 2.3: Status of each memory block before and after a request is made for a memory block of 200 spaces using the best-fit algorithm
  • 24. Understanding Operating Systems, Fourth Edition 24 Best-Fit Versus First-Fit Allocation (continued)  Hypothetical allocation schemes:  Next-fit: Starts searching from last allocated block, for the next available block when a new job arrives  Worst-fit: Allocates the largest free available block to the new job  Opposite of best-fit  Good way to explore the theory of memory allocation; might not be the best choice for an actual system
  • 25. Understanding Operating Systems, Fourth Edition 25 Determine the number of jobs processed, total memory used and total internal fragmentation using first-fit and best-fit memory allocation. Job List: Job number Memory Requested J1 5K J2 20K J3 35K J4 50K Memory List: Memory Location Memory Block size Job number Job size Status Internal Fragment ation 10240 60K         40960 15K         56320 50K         107520 20K         Total Available:   Total Used:      
  • 26. Understanding Operating Systems, Fourth Edition 26 Deallocation  Deallocation: Freeing an allocated memory space  For fixed-partition system:  Straightforward process  When job completes, Memory Manager resets the status of the job’s memory block to “free”  Any code—for example, binary values with 0 indicating free and 1 indicating busy—may be used
  • 27. Understanding Operating Systems, Fourth Edition 27 Deallocation (continued)  For dynamic-partition system:  Algorithm tries to combine free areas of memory whenever possible  Three cases:  Case 1: When the block to be deallocated is adjacent to another free block  Case 2: When the block to be deallocated is between two free blocks  Case 3: When the block to be deallocated is isolated from other free blocks
  • 28. Understanding Operating Systems, Fourth Edition 28 Deallocation: Dynamic Partition System  Case 1: Joining Two Free Blocks  Change list must reflect starting address of the new free block  In the example, 7600—which was the address of the first instruction of the job that just released this block  Memory block size for the new free space must be changed to show its new size—that is, the combined total of the two free partitions  In the example, (200 + 5)
  • 29. Understanding Operating Systems, Fourth Edition 29 Case 1: Joining Two Free Blocks Table 2.4: Original free list before deallocation for Case 1
  • 30. Understanding Operating Systems, Fourth Edition 30 Case 1: Joining Two Free Blocks (continued) Table 2.5: Free list after deallocation for Case 1
  • 31. Understanding Operating Systems, Fourth Edition 31 Deallocation: Dynamic Partition System (continued)  Case 2: Joining Three Free Blocks. Deallocated memory space is between two free memory blocks  Change list to reflect the starting address of the new free block  In the example, 7560— which was the smallest beginning address  Sizes of the three free partitions must be combined  In the example, (20 + 20 + 205)  Combined entry is given the status of null entry  In the example, 7600
  • 32. Understanding Operating Systems, Fourth Edition 32 Case 2: Joining Three Free Blocks Table 2.6: Original free list before deallocation for Case 2
  • 33. Understanding Operating Systems, Fourth Edition 33 Case 2: Joining Three Free Blocks (continued) Table 2.7: Free list after job has released memory
  • 34. Understanding Operating Systems, Fourth Edition 34 Deallocation: Dynamic Partition System (continued)  Case 3: Deallocating an Isolated Block. Space to be deallocated is isolated from other free areas  System learns that the memory block to be released is not adjacent to any free blocks of memory, it is between two other busy areas  Must search the table for a null entry  Null entry in the busy list occurs when a memory block between two other busy memory blocks is returned to the free list
  • 35. Understanding Operating Systems, Fourth Edition 35 Case 3: Deallocating an Isolated Block Table 2.8: Original free list before deallocation for Case 3
  • 36. Understanding Operating Systems, Fourth Edition 36 Case 3: Deallocating an Isolated Block (continued) Table 2.9: The job to be deallocated is of size 445 and begins at location 8805. The asterisk indicates the soon-to-be-free memory block. Table 2.9: Memory list before deallocation
  • 37. Understanding Operating Systems, Fourth Edition 37 Case 3: Deallocating an Isolated Block (continued) Table 2.10: Busy list after the job has released its memory. The asterisk indicates the new null entry in the busy list.
  • 38. Understanding Operating Systems, Fourth Edition 38 Case 3: Deallocating an Isolated Block (continued) Table 2.11: Free list after the job has released its memory. The asterisk indicates the new free block entry replacing the null entry
  • 39. Understanding Operating Systems, Fourth Edition 39 Relocatable Dynamic Partitions  Relocatable Dynamic Partitions:  Memory Manager relocates programs to gather together all of the empty blocks  Compact the empty blocks to make one block of memory large enough to accommodate some or all of the jobs waiting to get in
  • 40. Understanding Operating Systems, Fourth Edition 40 Relocatable Dynamic Partitions (continued)  Compaction: Reclaiming fragmented sections of the memory space  Every program in memory must be relocated so they are contiguous  Operating system must distinguish between addresses and data values  Every address must be adjusted to account for the program’s new location in memory  Data values must be left alone
  • 41. Understanding Operating Systems, Fourth Edition 41 Relocatable Dynamic Partitions (continued) Figure 2.5: An assembly language program that performs a simple incremental operation
  • 42. Understanding Operating Systems, Fourth Edition 42 Relocatable Dynamic Partitions (continued) Figure 2.6: The original assembly language program after it has been processed by the assembler
  • 43. Understanding Operating Systems, Fourth Edition 43 Relocatable Dynamic Partitions (continued)  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?
  • 44. Understanding Operating Systems, Fourth Edition 44 Relocatable Dynamic Partitions (continued)  What lists have to be updated?  Free list must show the partition for the new block of free memory  Busy list must show the new locations for all of the jobs already in process that were relocated  Each job will have a new address except for those that were already at the lowest memory locations
  • 45. Understanding Operating Systems, Fourth Edition 45 Relocatable Dynamic Partitions (continued)  Special-purpose registers are used for relocation:  Bounds register  Stores highest location accessible by each program  Relocation register  Contains the value that must be added to each address referenced in the program so it will be able to access the correct memory addresses after relocation  If the program isn’t relocated, the value stored in the program’s relocation register is zero
  • 46. Understanding Operating Systems, Fourth Edition 46 Relocatable Dynamic Partitions (continued) Figure 2.7: Three snapshots of memory before and after compaction
  • 47. Understanding Operating Systems, Fourth Edition 47 Relocatable Dynamic Partitions (continued) Figure 2.8: Contents of relocation register and close-up of Job 4 memory area (a) before relocation and (b) after relocation and compaction
  • 48. Understanding Operating Systems, Fourth Edition 48 Relocatable Dynamic Partitions (continued)  Compacting and relocating optimizes the use of memory and thus improves throughput  Options for when and how often it should be done:  When a certain percentage of memory is busy  When there are jobs waiting to get in  After a prescribed amount of time has elapsed Goal: Optimize processing time and memory use while keeping overhead as low as possible
  • 49. Understanding Operating Systems, Fourth Edition 49 Summary  Four memory management techniques were used in early systems: single-user systems, fixed partitions, dynamic partitions, and relocatable dynamic partitions  Memory waste in dynamic partitions is comparatively small as compared to fixed partitions  First-fit is faster in making allocation but leads to memory waste  Best-fit makes the best use of memory space but slower in making allocation
  • 50. Understanding Operating Systems, Fourth Edition 50 Summary (continued)  Compacting and relocating optimizes the use of memory and thus improves throughput  All techniques require that the entire program must:  Be loaded into memory  Be stored contiguously  Remain in memory until the job is completed  Each technique puts severe restrictions on the size of the jobs: can only be as large as the largest partitions in memory