SlideShare a Scribd company logo
Chapter 7
Memory Management
BYU CS 345 Memory Management 2
CS 345
Stalling’s Chapter # Project
1: Computer System Overview
2: Operating System Overview
4 P1: Shell
3: Process Description and Control
4: Threads
4 P2: Tasking
5: Concurrency: ME and Synchronization
6: Concurrency: Deadlock and Starvation
6 P3: Jurassic Park
7: Memory Management
8: Virtual memory
6 P4: Virtual Memory
9: Uniprocessor Scheduling
10: Multiprocessor and Real-Time Scheduling
6 P5: Scheduling
11: I/O Management and Disk Scheduling
12: File Management
8 P6: FAT
Student Presentations 6
Chapter 7 Learning Objectives
After studying this chapter, you should be able to:
 Discuss the principal requirements for memory
management.
 Understand the reason for memory partitioning and
explain the various techniques that are used.
 Understand and explain the concept of paging.
 Understand and explain the concept of segmentation.
 Assess the relative advantages of paging and
segmentation.
 Summarize key security issues related to memory
management.
 Describe the concepts of loading and linking.
BYU CS 345 Memory Management 3
BYU CS 345 Memory Management 4
Memory Management Requirements
 Relocation
 Users generally don’t know where they will be placed in main memory
 May swap in at a different place (pointers???)
 Generally handled by hardware
 Protection
 Prevent processes from interfering with the O.S. or other processes
 Often integrated with relocation
 Sharing
 Allow processes to share data/programs
 Logical Organization
 Support modules, shared subroutines
 Physical Organization
 Main memory verses secondary memory
 Overlaying
Requirements
BYU CS 345 Memory Management 5
Address Binding
 A process must be tied to a
physical address at some point
(bound)
 Binding can take place at 3 times
 Compile time
 Always loaded to same memory address
 Load time
 relocatable code
 stays in same spot once loaded
 Execution time
 may be moved during execution
 special hardware needed
source
object
Compiler/Assembler
load module
Linker
Loader
Executable
BYU CS 345 Memory Management 6
Memory Management Techniques
1. Fixed Partitioning
 Divide memory into partitions at boot time, partition sizes
may be equal or unequal but don’t change
 Simple but has internal fragmentation
2. Dynamic Partitioning
 Create partitions as programs loaded
 Avoids internal fragmentation, but must deal with external
fragmentation
3. Simple Paging
 Divide memory into equal-size pages, load program into
available pages
 No external fragmentation, small amount of internal
fragmentation
BYU CS 345 Memory Management 7
4. Simple Segmentation
 Divide program into segments
 No internal fragmentation, some external fragmentation
5. Virtual-Memory Paging
 Paging, but not all pages need to be in memory at one time
 Allows large virtual memory space
 More multiprogramming, overhead
6. Virtual Memory Segmentation
 Like simple segmentation, but not all segments need to be in
memory at one time
 Easy to share modules
 More multiprogramming, overhead
Memory Management Techniques
BYU CS 345 Memory Management 8
1. Fixed Partitioning
 Main memory divided into static
partitions
 Simple to implement
 Inefficient use of memory
 Small programs use entire partition
 Maximum active processes fixed
 Internal Fragmentation
8 M
8 M
8 M
8 M
8 M
Operating System
Fixed Partitioning
BYU CS 345 Memory Management 9
Fixed Partitioning
 Variable-sized partitions
 assign smaller programs to smaller
partitions
 lessens the problem, but still a
problem
 Placement
 Which partition do we use?
 Want to use smallest possible partition
 What if there are no large jobs waiting?
 Can have a queue for each partition
size, or one queue for all partitions
 Used by IBM OS/MFT, obsolete
 Smaller partition by using overlays
Operating System
8 M
12 M
8 M
8 M
6 M
4 M
2 M
Fixed Partitioning
BYU CS 345 Memory Management 10
Placement Algorithm w/Partitions
 Equal-size partitions
 because all partitions are of equal size, it does not
matter which partition is used
 Unequal-size partitions
 can assign each process to the smallest partition
within which it will fit
 queue for each partition
 processes are assigned in such a way as to minimize
wasted memory within a partition
Fixed Partitioning
BYU CS 345 Memory Management 11
Process Queues
New
Processes
Operating
System
Operating
System
New
Processes
 When its time to load a process into main
memory the smallest available partition that will
hold the process is selected
Fixed Partitioning
BYU CS 345 Memory Management 12
2. Dynamic Partitioning
 Partitions are of variable length and number
 Process is allocated exactly as much memory as
required
 Eventually get holes in the memory.
 external fragmentation
 Must use compaction to shift processes so they
are contiguous and all free memory is in one
block
Dynamic Partitioning
BYU CS 345 Memory Management 13
Allocation Strategies
 First Fit
 Allocate the first spot in memory that is big enough to
satisfy the requirements.
 Best Fit
 Search through all the spots, allocate the spot in
memory that most closely matches requirements.
 Next Fit
 Scan memory from the location of the last placement
and choose the next available block that is large
enough.
 Worst Fit
 The largest free block of memory is used for bringing
in a process.
Dynamic Partitioning
BYU CS 345 Memory Management 14
Which Allocation Strategy?
 The first-fit algorithm is not only the simplest but
usually the best and the fastest as well.
 May litter the front end with small free partitions that must
be searched over on subsequent first-fit passes.
 The next-fit algorithm will more frequently lead to
an allocation from a free block at the end of
memory.
 Results in fragmenting the largest block of free memory.
 Compaction may be required more frequently.
 Best-fit is usually the worst performer.
 Guarantees the fragment left behind is as small as possible.
 Main memory quickly littered by blocks too small to satisfy
memory allocation requests.
Dynamic Partitioning
BYU CS 345 Memory Management 15
Dynamic Partitioning Placement Algorithm
Last
allocated
block (14K)
Before
8K
12K
22K
18K
6K
8K
14K
36K
Free block
Allocated block
After
8K
12K
6K
8K
14K
6K
2K
20K
Allocate 18K
First Fit
Next Fit
Best Fit
Dynamic Partitioning
BYU CS 345 Memory Management 16
Memory Fragmentation
 As memory is allocated and deallocated
fragmentation occurs
 External -
 Enough space exists to launch a program, but it is
not contiguous
 Internal -
 Allocate more memory than asked for to avoid having
very small holes
Dynamic Partitioning
BYU CS 345 Memory Management 17
Memory Fragmentation
 Statistical analysis shows that given N allocated
blocks, another 0.5 N blocks will be lost due to
fragmentation.
 On average, 1/3 of memory is unusable
 (50-percent rule)
 Solution – Compaction.
 Move allocated memory blocks so they are
contiguous
 Run compaction algorithm periodically
 How often?
 When to schedule?
Dynamic Partitioning
BYU CS 345 Memory Management 18
Buddy System
 Tries to allow a variety of block sizes while avoiding
excess fragmentation
 Blocks generally are of size 2k, for a suitable range of k
 Initially, all memory is one block
 All sizes are rounded up to 2s
 If a block of size 2s is available, allocate it
 Else find a block of size 2s+1 and split it in half to create
two buddies
 If two buddies are both free, combine them into a larger
block
 Largely replaced by paging
 Seen in parallel systems and Unix kernel memory allocation
Dynamic Partitioning
Address Translation
BYU CS 345 Memory Management 20
Address Types
 Programmers refer to a memory address (address space)
as the way to access a memory cell (addressability).
 Logical (relative)
 Reference to a memory location independent of the current
assignment of data to physical memory
 Consists of a segment and an offset
 Linear (virtual)
 Address expressed as a location relative to some known base
address
 Mapped via segmentation
 Physical (memory bus)
 The absolute address or actual memory location
 Mapped via paging
BYU CS 345 Memory Management 21
Hardware Support for Relocation
Interrupt to
operating system
Process image in
main memory
Logical address
Physical
address
Adder
Comparator
Base Register
Bounds Register
Process Control
Block
Program
Data / Stack
Kernel Stack
BYU CS 345 Memory Management 22
Base/Bounds Relocation
 Base Register
 Holds beginning physical address
 Add to all program addresses
 Bounds Register
 Used to detect accesses beyond the end of
the allocated memory
 May have length instead of end address
 Provides protection to system
 Easy to move programs in memory
 These values are set when the process is
loaded and when the process is swapped in
 Largely replaced by paging
BYU CS 345 Memory Management 23
3. Simple Paging
 Partition memory into small equal-size chunks
and divide each process into the same size
chunks
 The chunks of a process are called pages and
chunks of memory are called frames
 Operating system maintains a page table for
each process
 contains the frame location
for each page in the process
 memory address consist of a
page number and offset
within the page
Simple Paging
BYU CS 345 Memory Management 24
Paging (continued…)
 Page size typically a power of 2 to simplify the
paging hardware
 Example (16-bit address, 1K pages)
 010101 011011010
 Top 6 bits (010101)= page #
 Bottom 10 bits (011011010) = offset within page
 Common sizes: 512 bytes, 1K, 4K
A B C D Free
0
1
2
3
-
-
-
7
8
9
10
4
5
6
11
12
13
14
Simple Paging
BYU CS 345 Memory Management 25
B.0
B.1
B.2
A.0
A.1
A.2
A.3
Paging
Frame
Number 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
C.0
C.1
C.2
C.3
D.0
D.1
D.2
D.3
D.4
0
1
2
3
Process A
0
1
2
3
0
1
2
Process B
4
5
6
0
1
2
3
Process C
7
8
9
10
0
1
2
3
4
4
5
6
11
12
Process D
Free Frame List
13
14
0
1
2
Process B
---
---
---
Simple Paging
BYU CS 345 Memory Management 26
4. Simple Segmentation
 Program views memory as a set of segments of
varying sizes
 Supports user view of memory
 Easy to handle growing data structures
 Easy to share libraries, memory
 Privileges can be applied to a segment
 Programs may use multiple segments
 Implemented with segmentation tables
 Array of base-limit register pairs
 Beginning address (segment base)
 Size (segment limit)
 Status bits (Present, Modified, Accessed, Permission,
Protection)
Simple Segmentation
BYU CS 345 Memory Management 27
Simple Segmentation
 A logical address consists of two parts: a segment
identifier and an offset that specifies the relative address
within the segment.
 The segment identifier is a 16-bit field called the Segment
Selector, while the offset is a 32-bit field.
 To make it easy to retrieve segment selectors quickly, the
processor provides segmentation registers whose only
purpose is to hold Segment Selectors.
 cs: points to a segment containing program instructions
 ss: points to a segment containing the current program stack
 ds: points to a segment containing global and static data
 es: 
 fs: points to a segment containing user data
 gs: /
Simple Segmentation
The cs register includes a 2-bit field
That specifies the Current Privilege
Level (CPL) of the CPU.
BYU CS 345 Memory Management 28
Segmentation/Paging
 In Pentium systems
 CPU generate logical addresses
 Segmentation unit produces a linear address
 Paging unit generates physical address in memory
 (Equivalent to an MMU)
CPU
Segmentation
Unit
logical
address
Paging
Unit
linear
address
Physical
Memory
physical
address
Simple Segmentation
BYU CS 345 Memory Management 29

More Related Content

Similar to local_media3192961381667787861026781.pptx

Memory Managementgggffffffffffgggggggggg
Memory ManagementgggffffffffffggggggggggMemory Managementgggffffffffffgggggggggg
Memory Managementgggffffffffffgggggggggg
BHUPESHRAHANGDALE200
 
Chap7
Chap7Chap7
Chap7
Mothi R
 
Opetating System Memory management
Opetating System Memory managementOpetating System Memory management
Opetating System Memory management
Johan Granados Montero
 
DB ppt OS unit - 3.pdf
DB ppt OS unit - 3.pdfDB ppt OS unit - 3.pdf
DB ppt OS unit - 3.pdf
DBharathi8
 
Chapter07_ds.ppt
Chapter07_ds.pptChapter07_ds.ppt
Chapter07_ds.ppt
AvadhRakholiya3
 
381 ccs chapter6_updated(2)
381 ccs chapter6_updated(2)381 ccs chapter6_updated(2)
381 ccs chapter6_updated(2)
Rabie Masoud
 
Unit iiios Storage Management
Unit iiios Storage ManagementUnit iiios Storage Management
Unit iiios Storage Management
donny101
 
M20CA1030_391_2_Part2.pptx
M20CA1030_391_2_Part2.pptxM20CA1030_391_2_Part2.pptx
M20CA1030_391_2_Part2.pptx
HarikishnaKNHk
 
Memory Management
Memory ManagementMemory Management
Memory Management
DEDE IRYAWAN
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
Rashmi Bhat
 
Memory Management
Memory ManagementMemory Management
Memory Management
sangrampatil81
 
Paging and Segmentation
Paging and SegmentationPaging and Segmentation
Paging and Segmentation
Madhur Gupta
 
Chapter 8 : Memory
Chapter 8 : MemoryChapter 8 : Memory
Chapter 8 : Memory
Amin Omi
 
Paging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory managementPaging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory management
kazim Hussain
 
Mca admissions in india
Mca admissions in indiaMca admissions in india
Mca admissions in india
Edhole.com
 
Chapter 9 OS
Chapter 9 OSChapter 9 OS
Chapter 9 OS
C.U
 
lecture 8 b main memory
lecture 8 b main memorylecture 8 b main memory
lecture 8 b main memory
ITNet
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
Rajapriya82
 
Memory management
Memory managementMemory management
Memory management
lodhran-hayat
 
Operating system
Operating systemOperating system
Operating system
Hussain Ahmady
 

Similar to local_media3192961381667787861026781.pptx (20)

Memory Managementgggffffffffffgggggggggg
Memory ManagementgggffffffffffggggggggggMemory Managementgggffffffffffgggggggggg
Memory Managementgggffffffffffgggggggggg
 
Chap7
Chap7Chap7
Chap7
 
Opetating System Memory management
Opetating System Memory managementOpetating System Memory management
Opetating System Memory management
 
DB ppt OS unit - 3.pdf
DB ppt OS unit - 3.pdfDB ppt OS unit - 3.pdf
DB ppt OS unit - 3.pdf
 
Chapter07_ds.ppt
Chapter07_ds.pptChapter07_ds.ppt
Chapter07_ds.ppt
 
381 ccs chapter6_updated(2)
381 ccs chapter6_updated(2)381 ccs chapter6_updated(2)
381 ccs chapter6_updated(2)
 
Unit iiios Storage Management
Unit iiios Storage ManagementUnit iiios Storage Management
Unit iiios Storage Management
 
M20CA1030_391_2_Part2.pptx
M20CA1030_391_2_Part2.pptxM20CA1030_391_2_Part2.pptx
M20CA1030_391_2_Part2.pptx
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Paging and Segmentation
Paging and SegmentationPaging and Segmentation
Paging and Segmentation
 
Chapter 8 : Memory
Chapter 8 : MemoryChapter 8 : Memory
Chapter 8 : Memory
 
Paging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory managementPaging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory management
 
Mca admissions in india
Mca admissions in indiaMca admissions in india
Mca admissions in india
 
Chapter 9 OS
Chapter 9 OSChapter 9 OS
Chapter 9 OS
 
lecture 8 b main memory
lecture 8 b main memorylecture 8 b main memory
lecture 8 b main memory
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
 
Memory management
Memory managementMemory management
Memory management
 
Operating system
Operating systemOperating system
Operating system
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 

local_media3192961381667787861026781.pptx

  • 2. BYU CS 345 Memory Management 2 CS 345 Stalling’s Chapter # Project 1: Computer System Overview 2: Operating System Overview 4 P1: Shell 3: Process Description and Control 4: Threads 4 P2: Tasking 5: Concurrency: ME and Synchronization 6: Concurrency: Deadlock and Starvation 6 P3: Jurassic Park 7: Memory Management 8: Virtual memory 6 P4: Virtual Memory 9: Uniprocessor Scheduling 10: Multiprocessor and Real-Time Scheduling 6 P5: Scheduling 11: I/O Management and Disk Scheduling 12: File Management 8 P6: FAT Student Presentations 6
  • 3. Chapter 7 Learning Objectives After studying this chapter, you should be able to:  Discuss the principal requirements for memory management.  Understand the reason for memory partitioning and explain the various techniques that are used.  Understand and explain the concept of paging.  Understand and explain the concept of segmentation.  Assess the relative advantages of paging and segmentation.  Summarize key security issues related to memory management.  Describe the concepts of loading and linking. BYU CS 345 Memory Management 3
  • 4. BYU CS 345 Memory Management 4 Memory Management Requirements  Relocation  Users generally don’t know where they will be placed in main memory  May swap in at a different place (pointers???)  Generally handled by hardware  Protection  Prevent processes from interfering with the O.S. or other processes  Often integrated with relocation  Sharing  Allow processes to share data/programs  Logical Organization  Support modules, shared subroutines  Physical Organization  Main memory verses secondary memory  Overlaying Requirements
  • 5. BYU CS 345 Memory Management 5 Address Binding  A process must be tied to a physical address at some point (bound)  Binding can take place at 3 times  Compile time  Always loaded to same memory address  Load time  relocatable code  stays in same spot once loaded  Execution time  may be moved during execution  special hardware needed source object Compiler/Assembler load module Linker Loader Executable
  • 6. BYU CS 345 Memory Management 6 Memory Management Techniques 1. Fixed Partitioning  Divide memory into partitions at boot time, partition sizes may be equal or unequal but don’t change  Simple but has internal fragmentation 2. Dynamic Partitioning  Create partitions as programs loaded  Avoids internal fragmentation, but must deal with external fragmentation 3. Simple Paging  Divide memory into equal-size pages, load program into available pages  No external fragmentation, small amount of internal fragmentation
  • 7. BYU CS 345 Memory Management 7 4. Simple Segmentation  Divide program into segments  No internal fragmentation, some external fragmentation 5. Virtual-Memory Paging  Paging, but not all pages need to be in memory at one time  Allows large virtual memory space  More multiprogramming, overhead 6. Virtual Memory Segmentation  Like simple segmentation, but not all segments need to be in memory at one time  Easy to share modules  More multiprogramming, overhead Memory Management Techniques
  • 8. BYU CS 345 Memory Management 8 1. Fixed Partitioning  Main memory divided into static partitions  Simple to implement  Inefficient use of memory  Small programs use entire partition  Maximum active processes fixed  Internal Fragmentation 8 M 8 M 8 M 8 M 8 M Operating System Fixed Partitioning
  • 9. BYU CS 345 Memory Management 9 Fixed Partitioning  Variable-sized partitions  assign smaller programs to smaller partitions  lessens the problem, but still a problem  Placement  Which partition do we use?  Want to use smallest possible partition  What if there are no large jobs waiting?  Can have a queue for each partition size, or one queue for all partitions  Used by IBM OS/MFT, obsolete  Smaller partition by using overlays Operating System 8 M 12 M 8 M 8 M 6 M 4 M 2 M Fixed Partitioning
  • 10. BYU CS 345 Memory Management 10 Placement Algorithm w/Partitions  Equal-size partitions  because all partitions are of equal size, it does not matter which partition is used  Unequal-size partitions  can assign each process to the smallest partition within which it will fit  queue for each partition  processes are assigned in such a way as to minimize wasted memory within a partition Fixed Partitioning
  • 11. BYU CS 345 Memory Management 11 Process Queues New Processes Operating System Operating System New Processes  When its time to load a process into main memory the smallest available partition that will hold the process is selected Fixed Partitioning
  • 12. BYU CS 345 Memory Management 12 2. Dynamic Partitioning  Partitions are of variable length and number  Process is allocated exactly as much memory as required  Eventually get holes in the memory.  external fragmentation  Must use compaction to shift processes so they are contiguous and all free memory is in one block Dynamic Partitioning
  • 13. BYU CS 345 Memory Management 13 Allocation Strategies  First Fit  Allocate the first spot in memory that is big enough to satisfy the requirements.  Best Fit  Search through all the spots, allocate the spot in memory that most closely matches requirements.  Next Fit  Scan memory from the location of the last placement and choose the next available block that is large enough.  Worst Fit  The largest free block of memory is used for bringing in a process. Dynamic Partitioning
  • 14. BYU CS 345 Memory Management 14 Which Allocation Strategy?  The first-fit algorithm is not only the simplest but usually the best and the fastest as well.  May litter the front end with small free partitions that must be searched over on subsequent first-fit passes.  The next-fit algorithm will more frequently lead to an allocation from a free block at the end of memory.  Results in fragmenting the largest block of free memory.  Compaction may be required more frequently.  Best-fit is usually the worst performer.  Guarantees the fragment left behind is as small as possible.  Main memory quickly littered by blocks too small to satisfy memory allocation requests. Dynamic Partitioning
  • 15. BYU CS 345 Memory Management 15 Dynamic Partitioning Placement Algorithm Last allocated block (14K) Before 8K 12K 22K 18K 6K 8K 14K 36K Free block Allocated block After 8K 12K 6K 8K 14K 6K 2K 20K Allocate 18K First Fit Next Fit Best Fit Dynamic Partitioning
  • 16. BYU CS 345 Memory Management 16 Memory Fragmentation  As memory is allocated and deallocated fragmentation occurs  External -  Enough space exists to launch a program, but it is not contiguous  Internal -  Allocate more memory than asked for to avoid having very small holes Dynamic Partitioning
  • 17. BYU CS 345 Memory Management 17 Memory Fragmentation  Statistical analysis shows that given N allocated blocks, another 0.5 N blocks will be lost due to fragmentation.  On average, 1/3 of memory is unusable  (50-percent rule)  Solution – Compaction.  Move allocated memory blocks so they are contiguous  Run compaction algorithm periodically  How often?  When to schedule? Dynamic Partitioning
  • 18. BYU CS 345 Memory Management 18 Buddy System  Tries to allow a variety of block sizes while avoiding excess fragmentation  Blocks generally are of size 2k, for a suitable range of k  Initially, all memory is one block  All sizes are rounded up to 2s  If a block of size 2s is available, allocate it  Else find a block of size 2s+1 and split it in half to create two buddies  If two buddies are both free, combine them into a larger block  Largely replaced by paging  Seen in parallel systems and Unix kernel memory allocation Dynamic Partitioning
  • 20. BYU CS 345 Memory Management 20 Address Types  Programmers refer to a memory address (address space) as the way to access a memory cell (addressability).  Logical (relative)  Reference to a memory location independent of the current assignment of data to physical memory  Consists of a segment and an offset  Linear (virtual)  Address expressed as a location relative to some known base address  Mapped via segmentation  Physical (memory bus)  The absolute address or actual memory location  Mapped via paging
  • 21. BYU CS 345 Memory Management 21 Hardware Support for Relocation Interrupt to operating system Process image in main memory Logical address Physical address Adder Comparator Base Register Bounds Register Process Control Block Program Data / Stack Kernel Stack
  • 22. BYU CS 345 Memory Management 22 Base/Bounds Relocation  Base Register  Holds beginning physical address  Add to all program addresses  Bounds Register  Used to detect accesses beyond the end of the allocated memory  May have length instead of end address  Provides protection to system  Easy to move programs in memory  These values are set when the process is loaded and when the process is swapped in  Largely replaced by paging
  • 23. BYU CS 345 Memory Management 23 3. Simple Paging  Partition memory into small equal-size chunks and divide each process into the same size chunks  The chunks of a process are called pages and chunks of memory are called frames  Operating system maintains a page table for each process  contains the frame location for each page in the process  memory address consist of a page number and offset within the page Simple Paging
  • 24. BYU CS 345 Memory Management 24 Paging (continued…)  Page size typically a power of 2 to simplify the paging hardware  Example (16-bit address, 1K pages)  010101 011011010  Top 6 bits (010101)= page #  Bottom 10 bits (011011010) = offset within page  Common sizes: 512 bytes, 1K, 4K A B C D Free 0 1 2 3 - - - 7 8 9 10 4 5 6 11 12 13 14 Simple Paging
  • 25. BYU CS 345 Memory Management 25 B.0 B.1 B.2 A.0 A.1 A.2 A.3 Paging Frame Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 C.0 C.1 C.2 C.3 D.0 D.1 D.2 D.3 D.4 0 1 2 3 Process A 0 1 2 3 0 1 2 Process B 4 5 6 0 1 2 3 Process C 7 8 9 10 0 1 2 3 4 4 5 6 11 12 Process D Free Frame List 13 14 0 1 2 Process B --- --- --- Simple Paging
  • 26. BYU CS 345 Memory Management 26 4. Simple Segmentation  Program views memory as a set of segments of varying sizes  Supports user view of memory  Easy to handle growing data structures  Easy to share libraries, memory  Privileges can be applied to a segment  Programs may use multiple segments  Implemented with segmentation tables  Array of base-limit register pairs  Beginning address (segment base)  Size (segment limit)  Status bits (Present, Modified, Accessed, Permission, Protection) Simple Segmentation
  • 27. BYU CS 345 Memory Management 27 Simple Segmentation  A logical address consists of two parts: a segment identifier and an offset that specifies the relative address within the segment.  The segment identifier is a 16-bit field called the Segment Selector, while the offset is a 32-bit field.  To make it easy to retrieve segment selectors quickly, the processor provides segmentation registers whose only purpose is to hold Segment Selectors.  cs: points to a segment containing program instructions  ss: points to a segment containing the current program stack  ds: points to a segment containing global and static data  es:  fs: points to a segment containing user data  gs: / Simple Segmentation The cs register includes a 2-bit field That specifies the Current Privilege Level (CPL) of the CPU.
  • 28. BYU CS 345 Memory Management 28 Segmentation/Paging  In Pentium systems  CPU generate logical addresses  Segmentation unit produces a linear address  Paging unit generates physical address in memory  (Equivalent to an MMU) CPU Segmentation Unit logical address Paging Unit linear address Physical Memory physical address Simple Segmentation
  • 29. BYU CS 345 Memory Management 29

Editor's Notes

  1. 1
  2. 4
  3. 5
  4. 6
  5. 7
  6. 8
  7. 9
  8. 10
  9. 11
  10. 12
  11. 13
  12. 14
  13. 15
  14. 16
  15. 17
  16. 18
  17. 20
  18. 21
  19. 22
  20. 23
  21. 24
  22. 25
  23. 26
  24. 27
  25. 28
  26. 29