SlideShare a Scribd company logo
1 of 42
Memory Management
CMC2C15 Operating Systems
Temasek Polytechnic • School of Informatics & IT
• 3.1 describe the early and current memory
management allocation schemes;
Learning Outcomes
Temasek Polytechnic • School of Informatics & IT
E-Lecture Video
Please view this video “Operating Systems 2 -
Memory Manager” by Shaun Stone
http://www.youtube.com/watch?v=qdkxXygc3rE
Temasek Polytechnic • School of Informatics & IT
Introduction
• Management of main memory is critical
• Entire system performance dependent on two
items
– How much memory is available
– Optimization of memory during job processing
• Memory manager
– Old Schemes of memory management
1. Single-user contiguous
2. Fixed partitions
3. Dynamic partitions
Temasek Polytechnic • School of Informatics & IT
1. Single-User Contiguous Scheme
• Commercially available in 1940s and 1950s
• Entire program loaded into memory
• Contiguous memory space allocated as
needed
• Jobs processed sequentially
• Memory manager performs minimal work
Temasek Polytechnic • School of Informatics & IT
Single-User Contiguous Scheme
(cont'd.)
• Disadvantages
– No support for multiprogramming or
networking
– Not cost effective
– Program size must be less than memory size to
execute
Temasek Polytechnic • School of Informatics & IT
2. Fixed Partitions
• Commercially available in 1950s and 1960s
• Main memory is partitioned
– At system startup
– One contiguous partition per job
• Permits multiprogramming
• Partition sizes remain static
– Must shut down computer system to
reconfigure
• Requires:
– Protection of the job’s memory space
– Matching job size with partition size
7
Temasek Polytechnic • School of Informatics & IT
Fixed Partitions (cont'd.)
• Memory manager allocates memory space to
jobs
– Through the use of a table
Temasek Polytechnic • School of Informatics & IT
Fixed Partitions (cont'd.)
Temasek Polytechnic • School of Informatics & IT
Fixed Partitions (cont'd.)
• Disadvantages
– Requires contiguous loading of entire program
– Job allocation method
• First available partition with required size
– To work well:
• All jobs must be same 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
Some portion of memory within the partition is left unused, and
cannot be used by another process.
Temasek Polytechnic • School of Informatics & IT
3. Dynamic Partitions
• Main memory is partitioned
– Jobs given memory requested when loaded
– One contiguous partition per job
• Job allocation method
– First come, first serve allocation method
– Memory waste: comparatively small
• Disadvantages
– Full memory utilization only during loading of first
jobs
– Subsequent allocation: memory waste
• External fragmentation: fragments between blocks
Total memory sufficient but not contiguous it so cannot be used
Temasek Polytechnic • School of Informatics & IT
Dynamic Partitions (cont'd.)
Temasek Polytechnic • School of Informatics & IT
Best-Fit Versus First-Fit Allocation
• Two methods for free space allocation
– 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
• Fixed and dynamic memory allocation
schemes use both methods
Temasek Polytechnic • School of Informatics & IT
Best-Fit Versus First-Fit Allocation
(cont'd.)
• 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
Temasek Polytechnic • School of Informatics & IT
De-allocation
• De-allocation: freeing allocated memory
space
• For fixed-partition system:
– Straightforward process
– Memory Manager resets the status of job’s
memory block to “free” upon job completion
– Any code may be used
– Example code: binary values with zero
indicating free and one indicating busy
Temasek Polytechnic • School of Informatics & IT
De-allocation (cont'd.)
• For dynamic-partition system:
– Algorithm tries to combine free areas of
memory
– More complex
Temasek Polytechnic • School of Informatics & IT
*Summary – old memory allocation schemes*
• 3 old memory management schemes
– Single-user contiguous, fixed partitions,
dynamic partitions
• Common requirements of old memory
management techniques (Disadvantages)
1. Entire program loaded into memory
2. Contiguous storage
3. Stays in memory until job completed
• Each places severe restrictions on job size
• Sufficient for first three generations of
computers
Temasek Polytechnic • School of Informatics & IT
1. Paged Memory Allocation
• Divides each incoming job into pages of equal size
• Best condition
– Page size = Memory block size (page frames)
= Size of disk section (sector, block)
• Sizes depend on operating system and disk sector size (size is
power of 2)
Paging to solve external fragmentation problem of dynamic partition
• The job is divided into equal parts called pages.
• They tend will be loaded into memory locations
called page frames.
Temasek Polytechnic • School of Informatics & IT
• Memory manager tasks prior to program execution
1. Determines number of pages in program
2. Locates enough empty page frames in main memory
3. Loads all program pages into page frames
• Advantage of storing program non contiguously
– New problem: keeping track of job’s pages
Paged Memory Allocation (cont'd.)
Temasek Polytechnic • School of Informatics & IT
Paged Memory Allocation (cont'd.)
Temasek Polytechnic • School of Informatics & IT
Paged Memory Allocation (cont'd.)
• Three tables for tracking pages
– Job Table (JT)
• Size of job
• Memory location where its PMT is stored
– Page Map Table (PMT)
• Page number
• Corresponding page frame memory address
– Memory Map Table (MMT)
• Location for each page frame
• Free/busy status
Temasek Polytechnic • School of Informatics & IT
Paged Memory Allocation (cont'd.)
• Advantages
– Allows job allocation in non-contiguous
memory
• Efficient memory use
• Disadvantages
– Increased overhead from address resolution
– Internal fragmentation in last page
– Must store entire job in memory location
• Page size selection is crucial
– Too small: generates very long PMTs
– Too large: excessive internal fragmentation
Temasek Polytechnic • School of Informatics & IT
2. Demand Paging
• Pages brought into memory only as needed
– Removes restriction: entire program in memory
– Requires high-speed page access
• Exploits programming techniques
– Modules written sequentially
• All pages not necessary needed simultaneously
– Examples
• User-written error handling modules
• Mutually exclusive modules
• Certain program options: mutually exclusive or not
accessible
• Tables given fixed amount of space: fraction used
Temasek Polytechnic • School of Informatics & IT
Demand Paging (cont'd.)
• Allowed for wide availability of virtual
memory concept
– Provides appearance of almost infinite or
nonfinite physical memory
– Jobs run with less main memory than required
in paged memory allocation scheme
– Requires high-speed direct access storage
device
• Works directly with CPU
– Swapping: how and when pages passed in
memory
• Depends on predefined policies
Temasek Polytechnic • School of Informatics & IT
Demand Paging (cont'd.)
• Memory Manager requires three tables
• Job Table
• Page Map Table: three new fields
– If requested page is already in memory
– If page contents have been modified
– If page has been referenced recently
• Determines which page remains in main memory and
which is swapped out
• Memory Map Table
Temasek Polytechnic • School of Informatics & IT
Demand Paging (cont'd.)
Temasek Polytechnic • School of Informatics & IT
Demand Paging (cont'd.)
• Swapping Process
– Exchanges resident memory page with
secondary storage page
– Involves
• Copying resident page to disk (if it was modified)
• Writing new page into the empty page frame
– Requires close interaction between:
• Hardware components
• Software algorithms
• Policy schemes
Temasek Polytechnic • School of Informatics & IT
Demand Paging (cont'd.)
• Advantages
– Job no longer constrained by the size of
physical memory (concept of virtual memory)
– Utilizes memory more efficiently than previous
schemes
– Faster response
• Disadvantages
– Increased overhead caused by tables and page
interrupts
Temasek Polytechnic • School of Informatics & IT
Page Replacement Policies and Concepts
• Policy to select page removal
– Crucial to system efficiency
• Page replacement polices
1. First-In First-Out (FIFO) policy
• Best page to remove is one in memory longest
2. Least Recently Used (LRU) policy
• Best page to remove is least recently accessed
3. Least Frequently Used(LFU) policy
• Best page to remove is least frequently accessed
4. Most Recently Used (MRU) policy
• Best page to remove is most recently accessed
Temasek Polytechnic • School of Informatics & IT
3. Segmented Memory Allocation
• Each job divided into several segments (logical
piece)
– Segments are different sizes
– One for each module containing related
functions
• Reduces page faults
– Segment’s loops not split over two or more
pages
• Main memory no longer divided into page frames
– Now allocated dynamically
• The job is divided into several segments of
different sizes, one for each module
Temasek Polytechnic • School of Informatics & IT
Segmented Memory Allocation
(cont'd.)
• Memory Manager tracks segments using tables
– Job Table
• Lists every job in process (one for whole system)
– Segment Map Table
• Lists details about each segment (one for each job)
– Memory Map Table
• Monitors allocation of main memory (one for whole system)
• Instructions with segments ordered sequentially
• Segments not necessarily stored contiguously
Temasek Polytechnic • School of Informatics & IT
Segmented Memory Allocation
(cont'd.)
• Addressing scheme requirement
– Segment number and displacement
• Advantages
– Internal fragmentation is removed
– Memory allocated dynamically
• Disadvantages
– Difficulty managing variable-length segments in
secondary storage
– External fragmentation
Temasek Polytechnic • School of Informatics & IT
4. Segmented / Demand Paged
Memory Allocation
• Subdivides segments into pages of equal size
– Smaller than most segments
– More easily manipulated than whole segments
– Logical benefits of segmentation
– Physical benefits of paging
• Segmentation problems removed
– Compaction, external fragmentation, secondary
storage handling
• Addressing scheme requirements
– Segment number, page number within that
segment, and displacement within that page
Combination of segmentation and demand paging
Temasek Polytechnic • School of Informatics & IT
Segmented/Demand Paged
Memory Allocation (cont'd.)
• Scheme requires four tables
1. Job Table
• Lists every job in process (one for the whole system)
2. Segment Map Table
• Lists details about each segment (one for each job)
3. Page Map Table
• Lists details about every page (one for each segment)
4. Memory Map Table
• Monitors allocation of page frames in main memory
(one for the whole system)
Temasek Polytechnic • School of Informatics & IT
Segmented/Demand Paged
Memory Allocation (cont'd.)
• Advantages
– Large virtual memory
– Segment loaded on demand
– Logical benefits of segmentation
– Physical benefits of paging
• Disadvantages
– Table handling overhead
– Memory needed for page and segment tables
Temasek Polytechnic • School of Informatics & IT
5. Virtual Memory
• Allows program execution even if not
stored entirely in memory
• Requires cooperation between memory
manager and processor hardware
• Advantages
– Job size not restricted to size of main memory
– Memory used more efficiently
– Allows an unlimited amount of
multiprogramming
– Eliminates external fragmentation and
minimizes internal fragmentation
Virtual memory is a combination of RAM and disk
space that running processes can use.
Temasek Polytechnic • School of Informatics & IT
Virtual Memory (cont'd.)
• Advantages (cont'd.)
– Allows the sharing of code and data
– Facilitates dynamic linking of program
segments
• Disadvantages
– Increased processor hardware costs
– Increased overhead for handling paging
interrupts
– Increased software complexity to prevent
thrashing
Temasek Polytechnic • School of Informatics & IT
Virtual Memory (cont'd.)
 Virtual Address = Logical Address _ address generated by CPU
 Physical Address = address actually available on memory
 MMU (Memory Management Unit) converts virtual to physical address
 User program deals with virtual addresses
Temasek Polytechnic • School of Informatics & IT
Virtual Memory (cont'd.)
Virtual memory is commonly
implemented by demand paging. It
can also be implemented in a
segmentation system.
Temasek Polytechnic • School of Informatics & IT
*Summary of newer memory management schemes*
1. Paged memory allocation
– Efficient use of memory
– Allocate jobs in non-contiguous memory locations
– Problems
• Increased overhead
• Internal fragmentation
2. Demand paging scheme
– Eliminates physical memory size constraint
– LRU provides slightly better efficiency (compared
to FIFO)
3. Segmented memory allocation scheme
– Solves internal fragmentation problem
Temasek Polytechnic • School of Informatics & IT
Summary (cont'd.)
4. Segmented/demand paged memory
– Problems solved
• Compaction, external fragmentation, secondary storage
handling
5. Virtual memory
– Programs execute if not stored entirely in memory
– Job’s size no longer restricted to main memory size
Mechanics (i.e. calculation) of
memory management will not be
expected.
Temasek Polytechnic • School of Informatics & IT
Summary (cont'd.)

More Related Content

Similar to Lecture 3 - Memory Management(2).pptx

Evolution, Strutcture and Operations.pptx
Evolution, Strutcture and Operations.pptxEvolution, Strutcture and Operations.pptx
Evolution, Strutcture and Operations.pptx
ssuser000e54
 

Similar to Lecture 3 - Memory Management(2).pptx (20)

UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
 
Evolution, Strutcture and Operations.pptx
Evolution, Strutcture and Operations.pptxEvolution, Strutcture and Operations.pptx
Evolution, Strutcture and Operations.pptx
 
08 operating system support
08 operating system support08 operating system support
08 operating system support
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Memory Management in Operating Systems for all
Memory Management in Operating Systems for allMemory Management in Operating Systems for all
Memory Management in Operating Systems for all
 
Memory management1
Memory management1Memory management1
Memory management1
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
OS UNIT4.pptx
OS UNIT4.pptxOS UNIT4.pptx
OS UNIT4.pptx
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 
Memory Management-Muhammad Ahmad.ppt
Memory Management-Muhammad Ahmad.pptMemory Management-Muhammad Ahmad.ppt
Memory Management-Muhammad Ahmad.ppt
 
Ch4 memory management
Ch4 memory managementCh4 memory management
Ch4 memory management
 
PAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docxPAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docx
 
Operating System
Operating SystemOperating System
Operating System
 
cache
cachecache
cache
 
Unit I OS.pdf
Unit I OS.pdfUnit I OS.pdf
Unit I OS.pdf
 
16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx
 
Internet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IVInternet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IV
 
memory managment on computer science.ppt
memory managment on computer science.pptmemory managment on computer science.ppt
memory managment on computer science.ppt
 
Operating system Chapter One
Operating system Chapter OneOperating system Chapter One
Operating system Chapter One
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

Lecture 3 - Memory Management(2).pptx

  • 2. Temasek Polytechnic • School of Informatics & IT • 3.1 describe the early and current memory management allocation schemes; Learning Outcomes
  • 3. Temasek Polytechnic • School of Informatics & IT E-Lecture Video Please view this video “Operating Systems 2 - Memory Manager” by Shaun Stone http://www.youtube.com/watch?v=qdkxXygc3rE
  • 4. Temasek Polytechnic • School of Informatics & IT Introduction • Management of main memory is critical • Entire system performance dependent on two items – How much memory is available – Optimization of memory during job processing • Memory manager – Old Schemes of memory management 1. Single-user contiguous 2. Fixed partitions 3. Dynamic partitions
  • 5. Temasek Polytechnic • School of Informatics & IT 1. Single-User Contiguous Scheme • Commercially available in 1940s and 1950s • Entire program loaded into memory • Contiguous memory space allocated as needed • Jobs processed sequentially • Memory manager performs minimal work
  • 6. Temasek Polytechnic • School of Informatics & IT Single-User Contiguous Scheme (cont'd.) • Disadvantages – No support for multiprogramming or networking – Not cost effective – Program size must be less than memory size to execute
  • 7. Temasek Polytechnic • School of Informatics & IT 2. Fixed Partitions • Commercially available in 1950s and 1960s • Main memory is partitioned – At system startup – One contiguous partition per job • Permits multiprogramming • Partition sizes remain static – Must shut down computer system to reconfigure • Requires: – Protection of the job’s memory space – Matching job size with partition size 7
  • 8. Temasek Polytechnic • School of Informatics & IT Fixed Partitions (cont'd.) • Memory manager allocates memory space to jobs – Through the use of a table
  • 9. Temasek Polytechnic • School of Informatics & IT Fixed Partitions (cont'd.)
  • 10. Temasek Polytechnic • School of Informatics & IT Fixed Partitions (cont'd.) • Disadvantages – Requires contiguous loading of entire program – Job allocation method • First available partition with required size – To work well: • All jobs must be same 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 Some portion of memory within the partition is left unused, and cannot be used by another process.
  • 11. Temasek Polytechnic • School of Informatics & IT 3. Dynamic Partitions • Main memory is partitioned – Jobs given memory requested when loaded – One contiguous partition per job • Job allocation method – First come, first serve allocation method – Memory waste: comparatively small • Disadvantages – Full memory utilization only during loading of first jobs – Subsequent allocation: memory waste • External fragmentation: fragments between blocks Total memory sufficient but not contiguous it so cannot be used
  • 12. Temasek Polytechnic • School of Informatics & IT Dynamic Partitions (cont'd.)
  • 13. Temasek Polytechnic • School of Informatics & IT Best-Fit Versus First-Fit Allocation • Two methods for free space allocation – 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 • Fixed and dynamic memory allocation schemes use both methods
  • 14. Temasek Polytechnic • School of Informatics & IT Best-Fit Versus First-Fit Allocation (cont'd.) • 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
  • 15. Temasek Polytechnic • School of Informatics & IT De-allocation • De-allocation: freeing allocated memory space • For fixed-partition system: – Straightforward process – Memory Manager resets the status of job’s memory block to “free” upon job completion – Any code may be used – Example code: binary values with zero indicating free and one indicating busy
  • 16. Temasek Polytechnic • School of Informatics & IT De-allocation (cont'd.) • For dynamic-partition system: – Algorithm tries to combine free areas of memory – More complex
  • 17. Temasek Polytechnic • School of Informatics & IT *Summary – old memory allocation schemes* • 3 old memory management schemes – Single-user contiguous, fixed partitions, dynamic partitions • Common requirements of old memory management techniques (Disadvantages) 1. Entire program loaded into memory 2. Contiguous storage 3. Stays in memory until job completed • Each places severe restrictions on job size • Sufficient for first three generations of computers
  • 18. Temasek Polytechnic • School of Informatics & IT 1. Paged Memory Allocation • Divides each incoming job into pages of equal size • Best condition – Page size = Memory block size (page frames) = Size of disk section (sector, block) • Sizes depend on operating system and disk sector size (size is power of 2) Paging to solve external fragmentation problem of dynamic partition • The job is divided into equal parts called pages. • They tend will be loaded into memory locations called page frames.
  • 19. Temasek Polytechnic • School of Informatics & IT • Memory manager tasks prior to program execution 1. Determines number of pages in program 2. Locates enough empty page frames in main memory 3. Loads all program pages into page frames • Advantage of storing program non contiguously – New problem: keeping track of job’s pages Paged Memory Allocation (cont'd.)
  • 20. Temasek Polytechnic • School of Informatics & IT Paged Memory Allocation (cont'd.)
  • 21. Temasek Polytechnic • School of Informatics & IT Paged Memory Allocation (cont'd.) • Three tables for tracking pages – Job Table (JT) • Size of job • Memory location where its PMT is stored – Page Map Table (PMT) • Page number • Corresponding page frame memory address – Memory Map Table (MMT) • Location for each page frame • Free/busy status
  • 22. Temasek Polytechnic • School of Informatics & IT Paged Memory Allocation (cont'd.) • Advantages – Allows job allocation in non-contiguous memory • Efficient memory use • Disadvantages – Increased overhead from address resolution – Internal fragmentation in last page – Must store entire job in memory location • Page size selection is crucial – Too small: generates very long PMTs – Too large: excessive internal fragmentation
  • 23. Temasek Polytechnic • School of Informatics & IT 2. Demand Paging • Pages brought into memory only as needed – Removes restriction: entire program in memory – Requires high-speed page access • Exploits programming techniques – Modules written sequentially • All pages not necessary needed simultaneously – Examples • User-written error handling modules • Mutually exclusive modules • Certain program options: mutually exclusive or not accessible • Tables given fixed amount of space: fraction used
  • 24. Temasek Polytechnic • School of Informatics & IT Demand Paging (cont'd.) • Allowed for wide availability of virtual memory concept – Provides appearance of almost infinite or nonfinite physical memory – Jobs run with less main memory than required in paged memory allocation scheme – Requires high-speed direct access storage device • Works directly with CPU – Swapping: how and when pages passed in memory • Depends on predefined policies
  • 25. Temasek Polytechnic • School of Informatics & IT Demand Paging (cont'd.) • Memory Manager requires three tables • Job Table • Page Map Table: three new fields – If requested page is already in memory – If page contents have been modified – If page has been referenced recently • Determines which page remains in main memory and which is swapped out • Memory Map Table
  • 26. Temasek Polytechnic • School of Informatics & IT Demand Paging (cont'd.)
  • 27. Temasek Polytechnic • School of Informatics & IT Demand Paging (cont'd.) • Swapping Process – Exchanges resident memory page with secondary storage page – Involves • Copying resident page to disk (if it was modified) • Writing new page into the empty page frame – Requires close interaction between: • Hardware components • Software algorithms • Policy schemes
  • 28. Temasek Polytechnic • School of Informatics & IT Demand Paging (cont'd.) • Advantages – Job no longer constrained by the size of physical memory (concept of virtual memory) – Utilizes memory more efficiently than previous schemes – Faster response • Disadvantages – Increased overhead caused by tables and page interrupts
  • 29. Temasek Polytechnic • School of Informatics & IT Page Replacement Policies and Concepts • Policy to select page removal – Crucial to system efficiency • Page replacement polices 1. First-In First-Out (FIFO) policy • Best page to remove is one in memory longest 2. Least Recently Used (LRU) policy • Best page to remove is least recently accessed 3. Least Frequently Used(LFU) policy • Best page to remove is least frequently accessed 4. Most Recently Used (MRU) policy • Best page to remove is most recently accessed
  • 30. Temasek Polytechnic • School of Informatics & IT 3. Segmented Memory Allocation • Each job divided into several segments (logical piece) – Segments are different sizes – One for each module containing related functions • Reduces page faults – Segment’s loops not split over two or more pages • Main memory no longer divided into page frames – Now allocated dynamically • The job is divided into several segments of different sizes, one for each module
  • 31. Temasek Polytechnic • School of Informatics & IT Segmented Memory Allocation (cont'd.) • Memory Manager tracks segments using tables – Job Table • Lists every job in process (one for whole system) – Segment Map Table • Lists details about each segment (one for each job) – Memory Map Table • Monitors allocation of main memory (one for whole system) • Instructions with segments ordered sequentially • Segments not necessarily stored contiguously
  • 32. Temasek Polytechnic • School of Informatics & IT Segmented Memory Allocation (cont'd.) • Addressing scheme requirement – Segment number and displacement • Advantages – Internal fragmentation is removed – Memory allocated dynamically • Disadvantages – Difficulty managing variable-length segments in secondary storage – External fragmentation
  • 33. Temasek Polytechnic • School of Informatics & IT 4. Segmented / Demand Paged Memory Allocation • Subdivides segments into pages of equal size – Smaller than most segments – More easily manipulated than whole segments – Logical benefits of segmentation – Physical benefits of paging • Segmentation problems removed – Compaction, external fragmentation, secondary storage handling • Addressing scheme requirements – Segment number, page number within that segment, and displacement within that page Combination of segmentation and demand paging
  • 34. Temasek Polytechnic • School of Informatics & IT Segmented/Demand Paged Memory Allocation (cont'd.) • Scheme requires four tables 1. Job Table • Lists every job in process (one for the whole system) 2. Segment Map Table • Lists details about each segment (one for each job) 3. Page Map Table • Lists details about every page (one for each segment) 4. Memory Map Table • Monitors allocation of page frames in main memory (one for the whole system)
  • 35. Temasek Polytechnic • School of Informatics & IT Segmented/Demand Paged Memory Allocation (cont'd.) • Advantages – Large virtual memory – Segment loaded on demand – Logical benefits of segmentation – Physical benefits of paging • Disadvantages – Table handling overhead – Memory needed for page and segment tables
  • 36. Temasek Polytechnic • School of Informatics & IT 5. Virtual Memory • Allows program execution even if not stored entirely in memory • Requires cooperation between memory manager and processor hardware • Advantages – Job size not restricted to size of main memory – Memory used more efficiently – Allows an unlimited amount of multiprogramming – Eliminates external fragmentation and minimizes internal fragmentation Virtual memory is a combination of RAM and disk space that running processes can use.
  • 37. Temasek Polytechnic • School of Informatics & IT Virtual Memory (cont'd.) • Advantages (cont'd.) – Allows the sharing of code and data – Facilitates dynamic linking of program segments • Disadvantages – Increased processor hardware costs – Increased overhead for handling paging interrupts – Increased software complexity to prevent thrashing
  • 38. Temasek Polytechnic • School of Informatics & IT Virtual Memory (cont'd.)  Virtual Address = Logical Address _ address generated by CPU  Physical Address = address actually available on memory  MMU (Memory Management Unit) converts virtual to physical address  User program deals with virtual addresses
  • 39. Temasek Polytechnic • School of Informatics & IT Virtual Memory (cont'd.) Virtual memory is commonly implemented by demand paging. It can also be implemented in a segmentation system.
  • 40. Temasek Polytechnic • School of Informatics & IT *Summary of newer memory management schemes* 1. Paged memory allocation – Efficient use of memory – Allocate jobs in non-contiguous memory locations – Problems • Increased overhead • Internal fragmentation 2. Demand paging scheme – Eliminates physical memory size constraint – LRU provides slightly better efficiency (compared to FIFO) 3. Segmented memory allocation scheme – Solves internal fragmentation problem
  • 41. Temasek Polytechnic • School of Informatics & IT Summary (cont'd.) 4. Segmented/demand paged memory – Problems solved • Compaction, external fragmentation, secondary storage handling 5. Virtual memory – Programs execute if not stored entirely in memory – Job’s size no longer restricted to main memory size Mechanics (i.e. calculation) of memory management will not be expected.
  • 42. Temasek Polytechnic • School of Informatics & IT Summary (cont'd.)