SlideShare une entreprise Scribd logo
1  sur  33
CSE323 Memory Management 1
CSE323 Memory ManagementCSE323 Memory Management
These slides were compiled from the OSC textbook slides (Silberschatz, Galvin,
and Gagne) and the instructor’s class materials.
Base and Limit Registers
 A pair of base and limit registers define the logical address space
 CPU must check every memory access generated in user mode to be sure it is between base
and limit for that user
Hardware Address Protection with Base and Limit Registers
Address Binding
 Programs on disk, ready to be brought into memory to execute form an input queue
 Inconvenient to have first user process physical address always at 0000
 Addresses represented in different ways at different stages of a program’s life
 Source code addresses are usually symbolic
 A Compiler bind this symbolic address to relocatable addresses
 i.e. “14 bytes from beginning of this module”
 Linker or loader will bind relocatable addresses to absolute addresses

i.e. 74014
 Each binding maps one address space to another
CSE323 Memory Management 5
From Source to Executable
Compiler
main()
sub1()
data
source
program
foo.c
main
sub1
data
object
modules
foo.o
printf
scanf
gets
fopen
exit
data
...
static
library
libc.a
Linkage
Editor
main
sub1
data
printf
exit
data
load
module
a.out
other
programs
...
main
sub1
data
printf
exit
data
other
...
...
kernel
Machine
memory
?
(system
calls)
Loader
(Run Time)
Dynamic library case not shown
“Load time”
CSE323 Memory Management 6
Binding of Instructions and Data to
Memory Addresses
Compile time: If memory location known a priori, absolute code can be
generated; must recompile code if starting location changes.
Load time: If memory location is not known at compile time, compiler
must generate relocatable code.
Loader knows final location and binds addresses for that location
Execution time: If the process can be moved during its execution,
binding must be delayed until run time. Need hardware support for
address maps (e.g., base and limit registers).
Memory-Management Unit
(MMU)
 MMU is the Hardware device that maps virtual address to physical address at run time
 To start, consider simple scheme where the value in the relocation register is added to every
address generated by a user process at the time it is sent to memory
 Base register now called relocation register
 MS-DOS on Intel 80x86 used 4 relocation registers
 The user program deals with logical addresses; it never sees the real physical addresses
 Execution-time binding occurs when reference is made to location in memory
CSE323 Memory Management 8
Logical vs. Physical Address
Space
 Physical address: The actual
hardware memory address.
 32-bit CPU’s physical
address 0 ~ 232
-1
(00000000 – FFFFFFFF)
 128MB’s memory
address 0 ~ 227
-1
(00000000 – 07FFFFFF)
 Logical address: Each
(relocatable) program
assumes the starting location
is always 0 and the memory
space is much larger than
actual memory
Dynamic relocation using a
relocation register
CSE323 Memory Management 9
Memory Protection
 For each process
 Logical space is mapped to a contiguous portion of physical space
 A relocation and a limit register are prepared

Relocation register = the value of the smallest physical address

Limit register = the range of logical address space
CSE323 Memory Management 10
Memory Protection
 When the CPU scheduler selects a process for
execution, the dispatcher loads the relocation and
limit registers with the correct values as part of the
context switch.
 Every address generated by the CPU is checked
against these registers.
CSE323 Memory Management 11
Dynamic Loading
 Unused routine is never
loaded
 Useful when the code
size is large
 Unix execv can be
categorized:
 Overloading a necessary
program onto the current
program.
main( ) {
f1( );
}
f1( ) {
f2( );
}
f2( ) {
f3( );
}
memory
1. Loaded when called
2. Loaded when called
3. Loaded when called
CSE323 Memory Management 12
Dynamic Linking
 Linking postponed until
execution time.
 Small piece of code,
stub, used to locate the
appropriate memory-
resident library routine.
 Stub replaces itself with
the address of the
routine, and executes
the routine.
 Operating system needs
to check if routine is in
processes’ memory
address
int x;
void main(){
stub = dlopen(“lib”):
f = dlsym(stub, “f1”);
f( );
}
extern int x;
f1( ) {
x = 5;
}
lib.so.a
memory
int x;
void main(){
stub = dlopen(“lib”):
f = dlsym(stub, “f1”);
f( );
}
extern int x;
f1( ) {
x = 5;
}
CSE323 Memory Management 13
Overlays
 Code and data used at
any given time are
placed in memory.
 New code is overloaded
onto the code not used
any more.
 It is not so frequently
used now.
CSE323 Memory Management 14
Swapping
 When a process p1 is
blocked so long (for
I/O), it is swapped out
to the backing store,
(swap area in Unix.)
 When a process p2 is
(served by I/O and )
back to a ready
queue, it is swapped
in the memory.
 Use the Unix top
command to see
which processes are
swapped out.
CSE323 Memory Management 15
Contiguous Memory Allocation
 The main memory is usually divided into two parts :
one for the operating system and one for the user
processes.
 Where the OS will reside will decide upon the location
of interrupt vector.
CSE323 Memory Management 16
Memory Allocation
(Fixed sized partition)
 Memory is divided to fixed-
sized partitions
 Each partition is allocated to a
process
 IBM OS/360
 Then, how about this
process?
OS
process1
process2
process3
process4
?
CSE323 Memory Management 17
Variable-Sized Partitions
 Primarily used in Batch environment
 The OS keeps a table indicating which parts of
memory are available and which are occupied
 Initially all memory is available for the user processes
and is considered as one large block of available
memory, “HOLE”.
 When a process arrives and needs memory, we
search for a hole large enough for this process.
 If we find one, we allocate only as much memory as
is needed.
CSE323 Memory Management 18
Variable-Sized Partitions
 Whenever one of running processes, (p8) is terminated
 Find a ready process whose size is best fit to the hole, (p9)
 Allocate it from the top of hole
 If there is still an available hole, repeat the above (for p10).
 Any size of processes, (up to the physical memory size) can be
allocated.
OS
process 5
process 8
process 2
OS
process 5
process 2
OS
process 5
process 2
OS
process 5
process 9
process 2
process 9
process 10
CSE323 Memory Management 19
Dynamic Storage-Allocation
Problem
 First-fit: Allocate the first hole that is big enough. (Fastest
search)
 Best-fit: Allocate the smallest hole that is big enough; must
search entire list, unless ordered by size. Produces the
smallest leftover hole. (Best memory usage)
 Worst-fit: Allocate the largest hole; must also search entire
list. Produces the largest leftover hole (that could be used
effectively later.)
 http://thumbsup2life.blogspot.com/2011/02/best-fit-first-fit-and-wors
First-fit and best-fit better than worst-fit in terms of
speed and storage utilization.
Example
CSE323 Memory Management 20
List of Jobs Size Turnaround
Job 1 100k 3
Job 2 10k 1
Job 3 35k 2
Job 4 15k 1
Job 5 23k 2
Job 6 6k 1
Job 7 25k 1
Job 8 55k 2
Job 9 88k 3
Job 10 100k 3
            Memory Block            Size           
                      Block 1                    50k
                      Block 2                  200k 
                      Block 3                    70k
                      Block 4                  115k
                      Block 5                    15k
Best Fit (Turn 1 and 2)
Block Size Process
1 50 P3
2 200 P5
3 70 P4
4 115 P1
5 15 P2
CSE323 Memory Management 21
Block Size Process
1 50 P3
2 200 P5
3 70 P7
4 115 P1
5 15 P6
Best Fit (Turn 3 and 4)
Block Size Process
1 50
2 200 P9
3 70 P8
4 115 P1
5 15
CSE323 Memory Management 22
Block Size Process
1 50
2 200 P9
3 70 P8
4 115 P10
5 15
Best Fit (Turn 5 and 6)
Block Size Process
1 50
2 200 P9
3 70
4 115 P10
5 15
CSE323 Memory Management 23
Block Size Process
1 50
2 200
3 70
4 115 P10
5 15
CSE323 Memory Management 24
External Fragmentation
 Problem
 50-percent rule (for first fit):
total memory space exists
to satisfy a request, but it is
not contiguous.
 Solution
 Compaction: shuffle the
memory contents to place
all free memory together in
one large block

Relocatable code

Expensive
 Paging: Allow non-
contiguous logical-to-
phyiscal space mapping.
process1
process2
process3
Can’t fit
Shift up
CSE323 Memory Management 25
Internal Fragmentation
 With the scheme of breaking the physical memory
into fixed-sized blocks, and allocate memory in unit of
block size, results internal fragmentation.
 With this approach, the memory allocated to a
process may be slightly larger than the requested
memory. The difference between these two number
is internal fragmentation.
Segmentation
 Memory-management scheme that
supports user view of memory
 A program is a collection of segments
 A segment is a logical unit such as:
main program
procedure
function
method
object
local variables, global variables
common block
stack
symbol table
arrays
User’s View of a Program
Logical View of Segmentation
Data
Code
Stack
Heap
user view of memory
Data
Heap
Stack
Code
logical memory space
Segmentation Architecture
 Logical address consists of a two tuple:
<segment-number, offset>,
 Segment table – maps two-dimensional physical addresses;
each table entry has:
 base – contains the starting physical address where the
segments reside in memory
 limit – specifies the length of the segment
 Segment-table base register (STBR) points to the
segment table’s location in memory
 Segment-table length register (STLR) indicates number
of segments used by a program;
segment number s is legal if s < STLR
Segmentation Architecture
(Cont.)
 Protection
 With each entry in segment table associate:

validation bit = 0 ⇒ illegal segment

read/write/execute privileges
 Protection bits associated with segments; code sharing occurs
at segment level
 Since segments vary in length, memory allocation is a dynamic
storage-allocation problem
 A segmentation example is shown in the following diagram
Segmentation Hardware
CSE323 Memory Management 32
Segmentation Example
used
PC
used
SP
Stack top
Currently executed
offset d1 d1
offset d2
d2
CSE323 Memory Management 33

Contenu connexe

Tendances

Deadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddikDeadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddik
Saeed Siddik
 

Tendances (20)

CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Memory management
Memory managementMemory management
Memory management
 
Deadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddikDeadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddik
 
Dynamic storage allocation techniques in Compiler design
Dynamic storage allocation techniques in Compiler designDynamic storage allocation techniques in Compiler design
Dynamic storage allocation techniques in Compiler design
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding Scheme
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Memory management
Memory managementMemory management
Memory management
 
distributed Computing system model
distributed Computing system modeldistributed Computing system model
distributed Computing system model
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its concepts
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
 
Memory management
Memory managementMemory management
Memory management
 
Contiguous Memory Allocation.ppt
Contiguous Memory Allocation.pptContiguous Memory Allocation.ppt
Contiguous Memory Allocation.ppt
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Loaders ( system programming )
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming )
 
2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts
 

Similaire à Chapter 8 : Memory

ECECS 472572 Final Exam ProjectRemember to check the errat.docx
ECECS 472572 Final Exam ProjectRemember to check the errat.docxECECS 472572 Final Exam ProjectRemember to check the errat.docx
ECECS 472572 Final Exam ProjectRemember to check the errat.docx
tidwellveronique
 
ECECS 472572 Final Exam ProjectRemember to check the err.docx
ECECS 472572 Final Exam ProjectRemember to check the err.docxECECS 472572 Final Exam ProjectRemember to check the err.docx
ECECS 472572 Final Exam ProjectRemember to check the err.docx
tidwellveronique
 
ECECS 472572 Final Exam ProjectRemember to check the errata
ECECS 472572 Final Exam ProjectRemember to check the errata ECECS 472572 Final Exam ProjectRemember to check the errata
ECECS 472572 Final Exam ProjectRemember to check the errata
EvonCanales257
 
Please do ECE572 requirementECECS 472572 Final Exam Project (W.docx
Please do ECE572 requirementECECS 472572 Final Exam Project (W.docxPlease do ECE572 requirementECECS 472572 Final Exam Project (W.docx
Please do ECE572 requirementECECS 472572 Final Exam Project (W.docx
ARIV4
 

Similaire à Chapter 8 : Memory (20)

Chapter 8 memory-updated
Chapter 8 memory-updatedChapter 8 memory-updated
Chapter 8 memory-updated
 
Memory management OS
Memory management OSMemory management OS
Memory management OS
 
Bab 4
Bab 4Bab 4
Bab 4
 
SO-Memoria.pdf
SO-Memoria.pdfSO-Memoria.pdf
SO-Memoria.pdf
 
SO-Memoria.pdf
SO-Memoria.pdfSO-Memoria.pdf
SO-Memoria.pdf
 
Ch8
Ch8Ch8
Ch8
 
ECECS 472572 Final Exam ProjectRemember to check the errat.docx
ECECS 472572 Final Exam ProjectRemember to check the errat.docxECECS 472572 Final Exam ProjectRemember to check the errat.docx
ECECS 472572 Final Exam ProjectRemember to check the errat.docx
 
ECECS 472572 Final Exam ProjectRemember to check the err.docx
ECECS 472572 Final Exam ProjectRemember to check the err.docxECECS 472572 Final Exam ProjectRemember to check the err.docx
ECECS 472572 Final Exam ProjectRemember to check the err.docx
 
Operating Systems Part III-Memory Management
Operating Systems Part III-Memory ManagementOperating Systems Part III-Memory Management
Operating Systems Part III-Memory Management
 
ECECS 472572 Final Exam ProjectRemember to check the errata
ECECS 472572 Final Exam ProjectRemember to check the errata ECECS 472572 Final Exam ProjectRemember to check the errata
ECECS 472572 Final Exam ProjectRemember to check the errata
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Opetating System Memory management
Opetating System Memory managementOpetating System Memory management
Opetating System 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
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
 
Operating System
Operating SystemOperating System
Operating System
 
Please do ECE572 requirementECECS 472572 Final Exam Project (W.docx
Please do ECE572 requirementECECS 472572 Final Exam Project (W.docxPlease do ECE572 requirementECECS 472572 Final Exam Project (W.docx
Please do ECE572 requirementECECS 472572 Final Exam Project (W.docx
 
Linux memorymanagement
Linux memorymanagementLinux memorymanagement
Linux memorymanagement
 
Co question 2006
Co question 2006Co question 2006
Co question 2006
 
CS6401 OPERATING SYSTEMS Unit 3
CS6401 OPERATING SYSTEMS Unit 3CS6401 OPERATING SYSTEMS Unit 3
CS6401 OPERATING SYSTEMS Unit 3
 
CH08.pdf
CH08.pdfCH08.pdf
CH08.pdf
 

Plus de Amin Omi (20)

Chapter 7
Chapter 7Chapter 7
Chapter 7
 
Pipelining
PipeliningPipelining
Pipelining
 
Sad lecture 1
Sad lecture 1Sad lecture 1
Sad lecture 1
 
Sad lecture 2
Sad lecture 2Sad lecture 2
Sad lecture 2
 
Sad lecture 3
Sad lecture 3Sad lecture 3
Sad lecture 3
 
Sad lecture 4
Sad lecture 4Sad lecture 4
Sad lecture 4
 
Sad lecture 5
Sad lecture 5Sad lecture 5
Sad lecture 5
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
 
Chapter04
Chapter04Chapter04
Chapter04
 
Chapter02
Chapter02Chapter02
Chapter02
 
Chapter01
Chapter01Chapter01
Chapter01
 
Transaction
TransactionTransaction
Transaction
 
Normalization
NormalizationNormalization
Normalization
 
Transport Layer
Transport LayerTransport Layer
Transport Layer
 
Basic health tips
Basic health tipsBasic health tips
Basic health tips
 
Style of living
Style of livingStyle of living
Style of living
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Basic SQL Command
Basic SQL CommandBasic SQL Command
Basic SQL Command
 
Chapter 5 : Link Layer
Chapter 5 : Link LayerChapter 5 : Link Layer
Chapter 5 : Link Layer
 
Chapter 2 : Application Layer
Chapter 2 : Application LayerChapter 2 : Application Layer
Chapter 2 : Application Layer
 

Dernier

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Dernier (20)

WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 

Chapter 8 : Memory

  • 1. CSE323 Memory Management 1 CSE323 Memory ManagementCSE323 Memory Management These slides were compiled from the OSC textbook slides (Silberschatz, Galvin, and Gagne) and the instructor’s class materials.
  • 2. Base and Limit Registers  A pair of base and limit registers define the logical address space  CPU must check every memory access generated in user mode to be sure it is between base and limit for that user
  • 3. Hardware Address Protection with Base and Limit Registers
  • 4. Address Binding  Programs on disk, ready to be brought into memory to execute form an input queue  Inconvenient to have first user process physical address always at 0000  Addresses represented in different ways at different stages of a program’s life  Source code addresses are usually symbolic  A Compiler bind this symbolic address to relocatable addresses  i.e. “14 bytes from beginning of this module”  Linker or loader will bind relocatable addresses to absolute addresses  i.e. 74014  Each binding maps one address space to another
  • 5. CSE323 Memory Management 5 From Source to Executable Compiler main() sub1() data source program foo.c main sub1 data object modules foo.o printf scanf gets fopen exit data ... static library libc.a Linkage Editor main sub1 data printf exit data load module a.out other programs ... main sub1 data printf exit data other ... ... kernel Machine memory ? (system calls) Loader (Run Time) Dynamic library case not shown “Load time”
  • 6. CSE323 Memory Management 6 Binding of Instructions and Data to Memory Addresses Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes. Load time: If memory location is not known at compile time, compiler must generate relocatable code. Loader knows final location and binds addresses for that location Execution time: If the process can be moved during its execution, binding must be delayed until run time. Need hardware support for address maps (e.g., base and limit registers).
  • 7. Memory-Management Unit (MMU)  MMU is the Hardware device that maps virtual address to physical address at run time  To start, consider simple scheme where the value in the relocation register is added to every address generated by a user process at the time it is sent to memory  Base register now called relocation register  MS-DOS on Intel 80x86 used 4 relocation registers  The user program deals with logical addresses; it never sees the real physical addresses  Execution-time binding occurs when reference is made to location in memory
  • 8. CSE323 Memory Management 8 Logical vs. Physical Address Space  Physical address: The actual hardware memory address.  32-bit CPU’s physical address 0 ~ 232 -1 (00000000 – FFFFFFFF)  128MB’s memory address 0 ~ 227 -1 (00000000 – 07FFFFFF)  Logical address: Each (relocatable) program assumes the starting location is always 0 and the memory space is much larger than actual memory Dynamic relocation using a relocation register
  • 9. CSE323 Memory Management 9 Memory Protection  For each process  Logical space is mapped to a contiguous portion of physical space  A relocation and a limit register are prepared  Relocation register = the value of the smallest physical address  Limit register = the range of logical address space
  • 10. CSE323 Memory Management 10 Memory Protection  When the CPU scheduler selects a process for execution, the dispatcher loads the relocation and limit registers with the correct values as part of the context switch.  Every address generated by the CPU is checked against these registers.
  • 11. CSE323 Memory Management 11 Dynamic Loading  Unused routine is never loaded  Useful when the code size is large  Unix execv can be categorized:  Overloading a necessary program onto the current program. main( ) { f1( ); } f1( ) { f2( ); } f2( ) { f3( ); } memory 1. Loaded when called 2. Loaded when called 3. Loaded when called
  • 12. CSE323 Memory Management 12 Dynamic Linking  Linking postponed until execution time.  Small piece of code, stub, used to locate the appropriate memory- resident library routine.  Stub replaces itself with the address of the routine, and executes the routine.  Operating system needs to check if routine is in processes’ memory address int x; void main(){ stub = dlopen(“lib”): f = dlsym(stub, “f1”); f( ); } extern int x; f1( ) { x = 5; } lib.so.a memory int x; void main(){ stub = dlopen(“lib”): f = dlsym(stub, “f1”); f( ); } extern int x; f1( ) { x = 5; }
  • 13. CSE323 Memory Management 13 Overlays  Code and data used at any given time are placed in memory.  New code is overloaded onto the code not used any more.  It is not so frequently used now.
  • 14. CSE323 Memory Management 14 Swapping  When a process p1 is blocked so long (for I/O), it is swapped out to the backing store, (swap area in Unix.)  When a process p2 is (served by I/O and ) back to a ready queue, it is swapped in the memory.  Use the Unix top command to see which processes are swapped out.
  • 15. CSE323 Memory Management 15 Contiguous Memory Allocation  The main memory is usually divided into two parts : one for the operating system and one for the user processes.  Where the OS will reside will decide upon the location of interrupt vector.
  • 16. CSE323 Memory Management 16 Memory Allocation (Fixed sized partition)  Memory is divided to fixed- sized partitions  Each partition is allocated to a process  IBM OS/360  Then, how about this process? OS process1 process2 process3 process4 ?
  • 17. CSE323 Memory Management 17 Variable-Sized Partitions  Primarily used in Batch environment  The OS keeps a table indicating which parts of memory are available and which are occupied  Initially all memory is available for the user processes and is considered as one large block of available memory, “HOLE”.  When a process arrives and needs memory, we search for a hole large enough for this process.  If we find one, we allocate only as much memory as is needed.
  • 18. CSE323 Memory Management 18 Variable-Sized Partitions  Whenever one of running processes, (p8) is terminated  Find a ready process whose size is best fit to the hole, (p9)  Allocate it from the top of hole  If there is still an available hole, repeat the above (for p10).  Any size of processes, (up to the physical memory size) can be allocated. OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10
  • 19. CSE323 Memory Management 19 Dynamic Storage-Allocation Problem  First-fit: Allocate the first hole that is big enough. (Fastest search)  Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole. (Best memory usage)  Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole (that could be used effectively later.)  http://thumbsup2life.blogspot.com/2011/02/best-fit-first-fit-and-wors First-fit and best-fit better than worst-fit in terms of speed and storage utilization.
  • 20. Example CSE323 Memory Management 20 List of Jobs Size Turnaround Job 1 100k 3 Job 2 10k 1 Job 3 35k 2 Job 4 15k 1 Job 5 23k 2 Job 6 6k 1 Job 7 25k 1 Job 8 55k 2 Job 9 88k 3 Job 10 100k 3             Memory Block            Size                                  Block 1                    50k                       Block 2                  200k                        Block 3                    70k                       Block 4                  115k                       Block 5                    15k
  • 21. Best Fit (Turn 1 and 2) Block Size Process 1 50 P3 2 200 P5 3 70 P4 4 115 P1 5 15 P2 CSE323 Memory Management 21 Block Size Process 1 50 P3 2 200 P5 3 70 P7 4 115 P1 5 15 P6
  • 22. Best Fit (Turn 3 and 4) Block Size Process 1 50 2 200 P9 3 70 P8 4 115 P1 5 15 CSE323 Memory Management 22 Block Size Process 1 50 2 200 P9 3 70 P8 4 115 P10 5 15
  • 23. Best Fit (Turn 5 and 6) Block Size Process 1 50 2 200 P9 3 70 4 115 P10 5 15 CSE323 Memory Management 23 Block Size Process 1 50 2 200 3 70 4 115 P10 5 15
  • 24. CSE323 Memory Management 24 External Fragmentation  Problem  50-percent rule (for first fit): total memory space exists to satisfy a request, but it is not contiguous.  Solution  Compaction: shuffle the memory contents to place all free memory together in one large block  Relocatable code  Expensive  Paging: Allow non- contiguous logical-to- phyiscal space mapping. process1 process2 process3 Can’t fit Shift up
  • 25. CSE323 Memory Management 25 Internal Fragmentation  With the scheme of breaking the physical memory into fixed-sized blocks, and allocate memory in unit of block size, results internal fragmentation.  With this approach, the memory allocated to a process may be slightly larger than the requested memory. The difference between these two number is internal fragmentation.
  • 26. Segmentation  Memory-management scheme that supports user view of memory  A program is a collection of segments  A segment is a logical unit such as: main program procedure function method object local variables, global variables common block stack symbol table arrays
  • 27. User’s View of a Program
  • 28. Logical View of Segmentation Data Code Stack Heap user view of memory Data Heap Stack Code logical memory space
  • 29. Segmentation Architecture  Logical address consists of a two tuple: <segment-number, offset>,  Segment table – maps two-dimensional physical addresses; each table entry has:  base – contains the starting physical address where the segments reside in memory  limit – specifies the length of the segment  Segment-table base register (STBR) points to the segment table’s location in memory  Segment-table length register (STLR) indicates number of segments used by a program; segment number s is legal if s < STLR
  • 30. Segmentation Architecture (Cont.)  Protection  With each entry in segment table associate:  validation bit = 0 ⇒ illegal segment  read/write/execute privileges  Protection bits associated with segments; code sharing occurs at segment level  Since segments vary in length, memory allocation is a dynamic storage-allocation problem  A segmentation example is shown in the following diagram
  • 32. CSE323 Memory Management 32 Segmentation Example used PC used SP Stack top Currently executed offset d1 d1 offset d2 d2

Notes de l'éditeur

  1. Hello! Everyone, My name is Shinya Kobayashi. Today, I am going to present our paper titled “Inter-Cluster Job Coordination Using Mobile Agents” on behalf of the first author, Munehiro Fukuda. Munehiro was hoping to show up and present the paper at AMS2001, however he got to wait in Japan until he will get an H1B visa. Since I received the presentation materials from him quite recently, please allow me to present this paper using this script. I can respond to your questions as far as I know, however you can also ask Munehiro by email. His email address is on the title page of our paper. (time 1:05)