SlideShare una empresa de Scribd logo
1 de 59
Main MemoryMain Memory
Mr. SUBHASIS DASH
SCHOLE OF COMPUTER
ENGINEERING.
KIIT UNIVERSITY
BHUBANESWAR
BackgroundBackground
Program must be brought (from disk) into memory and placed within a
process for it to be run
Main memory and registers are only storage CPU can access directly
Register access in one CPU clock (or less)
Main memory can take many cycles
Cache sits between main memory and CPU registers
Protection of memory required to ensure correct operation
Registers
L1-Cache
L2-Cache
Main Memory
Disk, Tape, etc.
Bigger Faster & Costly
L3-Cache (optional)
CPU
Binding of Instructions and Data toBinding of Instructions and Data to
MemoryMemory
Address binding of instructions and data to memory addresses can happen
at three different stages
Compile time: If memory location known a priori, absolute code
can be generated; must recompile code if starting location changes
Load time: Must generate relocatable code if memory location is
not known at compile time
Execution time: Binding delayed until run time if the process can be
moved during its execution from one memory segment to another.
Need hardware support for address maps (e.g., base and limit
registers)
Dynamic LoadingDynamic Loading
Routine is not loaded until it is called
Routines are kept in a relocatable load format.
Better memory-space utilization; unused routine is never loaded
Useful when large amounts of code are needed to handle infrequently
occurring cases
No special support from the operating system is required implemented
through program design
Dynamic LinkingDynamic Linking
System always needs a copy of language library included in executable
image Dynamically linked libraries.
Static linking (System language libraries in binary program image).
Concept of dynamic linking == dynamic loading.(Rather held up loading until
execution we can held up the 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 needed to check if routine is in processes’ memory
address
Dynamic linking is particularly useful for libraries
System also known as shared libraries
Multistep Processing of a User ProgramMultistep Processing of a User Program
overlaysoverlays
 Program & data must be in physical memory to start execution.
 If (Program +Data) size <= size of physical memory
then
start execution
else
use a technique called overlays.
 Example:-
Given data:- Process Memory Size
Pass-1 70kb
Pass-2 80kb Total memory
Symbol table 20kb required 200kb.
Common Routine 30kb
Main memory size available is 150kb.
Hence 200kb >150kb
OverlaysOverlays
Continued….Continued….
Solution
Symbol
Table
20kb
Common
Routine
30kb
Overlay
Driver
10kb
90kb
Pass-1
70kb
Pass-2
80kb
Logical vs. Physical Address SpaceLogical vs. Physical Address Space
User’s view User program see primary memory as
continuous space
Actual view User program may be scattered according to the
instruction address location.
The concept of a logical address space that is bound to a
separate physical address space is central to proper
memory management
Logical address – generated by the CPU; also referred
to as virtual address
Physical address – address seen by the memory unit
Logical and physical addresses are the same in compile-time
and load-time address-binding schemes; logical (virtual) and
physical addresses differ in execution-time address-binding
scheme
Base and Limit RegistersBase and Limit Registers
A pair of base and limit registers define the logical address space
Memory-Management Unit (Memory-Management Unit (MMUMMU))
Hardware device that maps logical to physical address
In MMU scheme, the value in the basrelocation register is added to
every address generated by a user process at the time it is sent to
memory
The user program deals with logical addresses; it never sees the
real physical addresses
Dynamic relocation using a relocationDynamic relocation using a relocation
registerregister
HW address protection with base and limitHW address protection with base and limit
registersregisters
 Logical Physical
Address Address
Yes
Trap : Addressing Error
Limit
Register
Relocation
Register
<CPU +
Memory
SwappingSwapping
A process can be swapped temporarily out of memory to a backing
store, and then brought back into memory for continued execution
Backing store – fast disk large enough to accommodate copies
of all memory images for all users; must provide direct access to
these memory images
Roll out, roll in – swapping variant used for priority-based
scheduling algorithms; lower-priority process is swapped out so
higher-priority process can be loaded and executed
Major part of swap time is transfer time; total transfer time is
directly proportional to the amount of memory swapped
Modified versions of swapping are found on many systems (i.e.,
UNIX, Linux, and Windows)
System maintains a ready queue of ready-to-run processes
which have memory images on disk
Schematic View of SwappingSchematic View of Swapping
If a system wants to swaps a process ,it must take care of some
important points like:-
Is the process waits for its I/O operation?
System wants to create free space in memory
Contiguous AllocationContiguous Allocation
Main memory usually into two partitions:
Resident operating system, usually held in low memory with
interrupt vector
User processes then held in high memory.
Memory Partition
Operating system
USER Program
Contiguous Allocation (Cont.)Contiguous Allocation (Cont.)
1. SINGLE PARTITION ALLOCATION
Relocation registers used to protect user processes from each
other, and from changing operating-system code and data
Base register contains value of smallest physical address
Limit register contains range of logical addresses – each logical
address must be less than the limit register
MMU maps logical address dynamically
Contiguous Allocation (Cont.)Contiguous Allocation (Cont.)
2. MULTIPLE-PARTITION ALLOCATION
A. Multiprogramming With Fixed Partition (MFT) :-
Objective:- To have more then one process in memory at once.
Best way Divide memory into N Possible unequal partitions.
But no single partition can accommodate more than one process
When process arrives , it can put into the input queue for the
smallest partition but large enough to accommodate the process.
Though the technique moving towards best size fit ,still there are
some free spaces in partition which can’t be used further.
Unused memory space leads to INTERNAL FRAGMENTATION.
To avoid undesirable loss of memory space in the partition, search
the whole input queue when a partition becomes free,& pick up the
largest object that fits.
Contiguous Allocation (Cont.)Contiguous Allocation (Cont.)
Multiprogramming With Fixed Partition (MFT) :-
Single I/P queue
Partition -- 3
Partition -- 2
Partition – 1
Partition -- 4
Operating system
Contiguous Allocation (Cont.)Contiguous Allocation (Cont.)
B. Multiprogramming With variable Partition (MVT) :-
Number ,size of the process & memory partition vary
dynamically .
Hole – block of available memory; holes of various size
are scattered throughout memory
When a process arrives, it is allocated memory from a
hole large enough to accommodate it
Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
Process growth due to data segment can be adjusted
with the dynamic free space . If it is not sufficient then
process have to swap out otherwise kill the process.
Contiguous Allocation (Cont.)Contiguous Allocation (Cont.)
B. Multiprogramming With variable Partition (MVT) :-
 We can conclude that, When process appears  Kept into the
input queue according to the scheduling algorithm  allocate
the memory when it space is available  When memory is not
satisfy to the next process the operating system have to wait
until the required memory space is available otherwise it simply
skips that process and switch for the next smaller process.
 The unused spaces between different process leads to
EXTERNAL FRAGMENTATION.
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
Contiguous Allocation (Cont.)Contiguous Allocation (Cont.)
Example:-
Memory available = 2560kb
OS takes a memory space of = 400kb
Memory space for user process = 2560 − 400 = 2160kb
Use Round robin scheduling algorithm with quantum time = 07 unit of time.
Given data:-
Process Memory Time
P1 600kb 10
P2 1000kb 05
P3 300kb 20
P4 700kb 08
P5 500kb 15
Solution:-
0 7 12 19 26 33 36 43 44 51 57 58
P1 P2 P3 P4 P5 P1 P3 P4 P5 P3 P5
Dynamic Storage-Allocation ProblemDynamic Storage-Allocation Problem
First-fit: Allocate the first hole that is big enough
Best-fit: Allocate the smallest hole that is big enough; must
search entire list, unless ordered by size
Produces the smallest leftover hole
Worst-fit: Allocate the largest hole; must also search entire
list
Produces the largest leftover hole
How to satisfy a request of size n from a list of free holes
First-fit and best-fit better than worst-fit in terms of
speed and storage utilization
FragmentationFragmentation
External Fragmentation – total memory space exists to satisfy
a request, but it is not contiguous
Internal Fragmentation – allocated memory may be slightly
larger than requested memory; this size difference is memory
internal to a partition, but not being used
Reduce external fragmentation by compaction
Shuffle memory contents to place all free memory together in
one large block
Compaction is possible only if relocation is dynamic, and is
done at execution time
I/O problem
 Latch job in memory while it is involved in I/O
 Do I/O only into OS buffers
PagingPaging
External fragmentation problem can be treated by PAGING.
Logical address space of a process can be noncontiguous;
process is allocated physical memory whenever space is
available
Address mapping in paging scheme
Divide physical memory into fixed-sized blocks called frames
(size is power of 2, between 512 bytes and 8,192 bytes)
Divide logical memory into blocks of same size called pages
Keep track of all free frames
To run a program of size n pages, need to find n free frames
and load program
Set up a page table to translate logical to physical addresses
Internal fragmentation
Address Translation SchemeAddress Translation Scheme
Address generated by CPU (Logical Address ) is divided into
Page number (p) – used as an index into a page table which
contains base address of each page in physical memory
Page offset (d) – combined with base address to define the
physical memory address that is sent to the memory unit
Base address + page offset = physical address
Paging Model of Logical and PhysicalPaging Model of Logical and Physical
MemoryMemory
Page
Number
As
index
Base
Address
Of each
Page in
Physical
Memory
Paging HardwarePaging Hardware
Page no.(p) is
An index into
Page table.
Base address of
Each page in
Physical memory
Base address
+ page offset=
Physical address
LALA Address MappingAddress Mapping PAPA
If size of logical address space 2m
and page size2n
then
Low order n bits of logical address represents the page offset.
High order remaining bits (m-n) represents the page number.
Page number P is an index into page table.
page offset d is the displacement within pages.
page number page offset
p
m - n
d
n
Paging ExamplePaging Example
32-byte memory and 4-byte pages
Physical Address = (frame No.× page size) + Page offset
Page
Number
As
index
Base
Address
Of each
Page in
Physical
Memory
Page 0
Page 1
Page 2
Page 3
LALA Address MappingAddress Mapping PAPA
Physical Address = (frame No.× page size) + Page offset
Example:-
page size is 04 bytes.
Physical memory size is of 32bytes.
Hence total number of pages 32 bytes / 4 bytes = 08.
☻ If logical address is 0 then, what is its corresponding physical address?
☻ Page offset (d) = displacement within pages = 0 – 0 = 0
☻ Hence Page number is = 0, which is in frame 5 given as in page table.
☻ So physical address = (5 x 4) + 0 = 20
☻ If logical address is 03 then, what is its corresponding physical address?
☻ Page offset (d) = displacement within pages = 03 – 0 = 3
☻ Hence Page number is = 0, which is in frame 5 given as in page table.
☻ So physical address = (5 x 4) + 3 = 23
Paging ExamplePaging Example
Continue…Continue…
☻ If logical address is 04 then, what is its corresponding physical address?
☻ Page offset (d) = displacement within pages = 04 – 4 = 0
☻ Hence Page number is = 1, which is in frame 6 given as in page table.
☻ So physical address = (6 x 4) + 0 = 24
☻ If logical address is 10 then, what is its corresponding physical address?
☻ Page offset (d) = displacement within pages = 10 – 8 = 2
☻ Hence Page number is = 2, which is in frame 1 given as in page table.
☻ So physical address = (1 x 4) + 2 = 06
☻ If logical address is 13 then, what is its corresponding physical address?
☻ Page offset (d) = displacement within pages = 13 – 12 = 01
☻ Hence Page number is = 3, which is in frame 2 given as in page table.
☻ So physical address = (2 x 4) + 1 = 09
☻ If logical address is 15 then, what is its corresponding physical address?
☻ Page offset (d) = displacement within pages = 15 – 12 = 3
☻ Hence Page number is = 3, which is in frame 2 given as in page table.
☻ So physical address = (2x 4) + 3 = 11
Problems with pagingProblems with paging
During process scheduling pages are loaded into the available
frames & page table is updated.
Paging scheme don’t suffers with external fragmentation.
But Paging scheme suffers with internal fragmentation.
Because when process don’t comes under page boundaries, the last frame
allocated may not be full.
Example: Page size = 2048 bytes
Process size = 72,766 bytes
so it needs 72,766 / 2048 = 35 (1035 bytes)
So internal fragmentation is = 2048 – 1035 = 962 bytes free
Remedy
As small as the page size to reduce internal fragmentation
Increase the page table size.
Make disk I/O more efficient that large data can be transferred.
Implementation of Page TableImplementation of Page Table
Page table consist of dedicated registers with very high speed logic
to make the address translation efficient.
For large page table ,it must kept in main memory.
Page-table base register (PTBR) points to the page table
Page-table length register (PTLR) indicates size of the page
table
Example:
If we want to access location i then
 First page number index into the page table for i location.
 Frame number & page offset can found from page table.
In this scheme every data/instruction access requires two memory
accesses.
One for the page table and one for the data/instruction.
Implementation of Page TableImplementation of Page Table
Continue….Continue….
Solution:
The two memory access problem can be solved by the
use of a special fast-lookup hardware cache called
associative memory or translation look-aside
buffers (TLBs)
TLB register consist of two parts :- key & value
Some TLBs store address-space identifiers
(ASIDs) in each TLB entry – uniquely identifies each
process to provide address-space protection for that
process
TLB as Associative MemoryTLB as Associative Memory
Associative memory – parallel search
Address translation (p, d)
If p is in associative register, get frame # out  TLB HIT
Otherwise get frame # from page table in memory  TLB
MISS
Page # Frame #
Paging Hardware With TLBPaging Hardware With TLB
As Associative register
Effective Access TimeEffective Access Time
EAT = PH ( TA + TM ) + (1 - PH ) ( TA + 2TM )
Where
PH Hit ratio – percentage of times that a page
number is found in the associative registers; ratio
related to number of associative registers
TA Time to search associative memory.
TM  Memory access time.
Example:
Hit ratio for associative memory = 80 %
Time to search associative memory (TA) = 20 ns
Memory access time (TM ) = 100 ns
EAT = 0.80 ( 20 + 100 ) + (1 – 0.80 ) (20 + [ 2 x 100 ] )
= ( 0.8 x 120 ) + ( 0.2 x 220 ) = 96 + 44 = 140 ns
Hence we suffers with 40 % slowdown in memory access time.
Advantages of PagingAdvantages of Paging
Possibility of sharing common code in time sharing environment.
Each process has its own copy of register s and data storage .
Each user page table maps on to the same physical copy of the
shared code but data pages are mapped on to different frames.
Read only nature of shared code should not be left to the
correctness of the code
Memory Protection in pagingMemory Protection in paging
Memory protection implemented by associating protection bit with
each frame.
One protection bit can define a page is read only or read /write.
An attempt to write to a read only page causes a hardwire trap
(memory protection violation) to the operating system.
Valid-invalid bit attached to each entry in the page table:
“valid” indicates that the associated page is in the process
logical address space, and is thus a legal page
“invalid” indicates that the page is not in the process logical
address space and is thus an illegal page.
Memory Protection in pagingMemory Protection in paging
Continue……Continue……
Example:-
Total memory space is 16383 bytes.
Used memory space is 10468 bytes.
Page size 2000 bytes.
Total number of page required = 10468 / 2000 = 5 (468 / 2000)
= 6 pages
So the 0,1,2,3,4,5 are valid pages.
But any attempt to find page 6 or 7 or other pages (Invalid pages)
will be trapped by operating system.
Valid (v) or Invalid (i) Bit In A PageValid (v) or Invalid (i) Bit In A Page
TableTable
LOGICAL
ADDRES
S
PHYSICA
L
ADDRES
S
Shared PagesShared Pages
Shared code
One copy of read-only (reentrant) code shared among
processes (i.e., text editors, compilers, window systems).
Shared code must appear in same location in the logical
address space of all processes
Private code and data
Each process keeps a separate copy of the code and
data
The pages for the private code and data can appear
anywhere in the logical address space
Shared Pages ExampleShared Pages Example
Suppose a system supports 40 users.
Each user executes a text editor of 150 kb of code & 50 kb of
data space.
Hence total space required = (150 + 50) x 40 = 8000 kb
But shared page scheme can reduce the total space (8000
kb) required .
Solution:
If code is reentrant (pure code) it can be shared. Text editor
Code is reentrant means non self modifying code (CODECODE
NEVER CHANGES DURING EXECUTIONNEVER CHANGES DURING EXECUTION), only fetch / read can
possible.
Non self modifying code can be used by more than one user at
once.
Shared Pages ExampleShared Pages Example
Continue…..Continue…..
Solution:
Physical memory must contain a copy of text editor & data
required for each user.
Hence each user can have a copy of the text editor code along
with data page in their executable space, by which execution
can possible.
Each user’s page table maps on to the same physical copy of
the text editor but the data pages are mapped on to different
frames in the physical memory.
Divide text editor into 3 pages (50 kb each) & share among all
40 users.
But each user must have its own data page (50 kb each).
Hence to support 40 users total space required is
 150 kb + ( 50 kb x 40 ) = 2150 kb
Shared Pages ExampleShared Pages Example
SegmentationSegmentation
Memory-management scheme that supports user view of memory
Actually user view is not a linear array of memory space. It prefers
to view memory as a collection of variable sized segments.
Hence, A program is a collection of segments. A segment is a
logical unit such as:
Main program, Local variables
Procedure, Global variables
Function, common block,
Method, Stack,
Object, Symbol table
Subroutine Arrays
User’s View of a ProgramUser’s View of a Program
Logical View of SegmentationLogical View of Segmentation
Segmentation supports the view of memory
A logical address space is a collection of segments .
Logical Address specify both the segment number & offset within
the segment.
Each segment has a number & length.
Logical address consists of a two tuple:
< segment-number, segment offset >
SEGMENT
NUMBER
SEGMENT
OFFSET
L G I C A L
A D D R E S S
Logical View of SegmentationLogical View of Segmentation
Continue……Continue……
1
3
2 4
1
4
2
3
user space
physical memory space
Segmentation uses
variable size
partition.
Hence it suffers from
EXTERNAL
FRAGMENTATION.
Implementation of Segment TableImplementation of Segment Table
Segment table can be either in buffer or in main memory.
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
Segment table entry = STBR + S(offset)
Read the above result from memory & segment offset is
checked against the segment length ,hence the physical
address can be found.
LALA Address MappingAddress Mapping
PAPA
Segment table helps in mapping.
Logical address consists of a two tuple:
< segment-number, segment offset >
Segment number is used as an index to the segment table.
Each entry to the segment table has a base ( starting physical
address) and limit ( range of segment ) register.
The segment offset given in logical address must occur between the
range given by limit register ( legal offset ) otherwise there is an
addressing error.
If (Segment Offset Value < Limit Register Value)
then
ADD Base Register Value with Segment Offset value
else
Addressing Error
Segmentation HardwareSegmentation Hardware
Logical
Address
Segment
Offset
Limit
Register
Value
d
Base
Register
Value
Example of SegmentationExample of Segmentation
LALA Address MappingAddress Mapping
PAPA
Example :
Here we have 5 segments.
If a logical address is
then check 53 < 400
Physical Address = 4300 + 53 = 4353
If a logical address is
then check 852 < 1100
Physical Address = 3200 + 852 = 4052
If a logical address is
then check 1222 >1000
illegal segment offset (d).
Addressing Error (trap).
02 53
S d
03 852
S d
00 1222
S d
what is its corresponding
physical address?
what is its corresponding
physical address?
what is its corresponding
physical address?
Protection in SegmentationProtection in Segmentation
A program consists of instruction segment, data segment, editor
segment.
Instructions are non self modifying, so read only.
Protection bit is checked to prevent illegal access.
With each entry in segment table associate:
 validation bit = 0 ⇒ illegal segment
 validation bit = 1 ⇒ Legal 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
Sharing in SegmentationSharing in Segmentation
Instructions are non self modifying, (read only) hence the code
can be sharable.
When entries to the segment table of two different process
points to same physical locations then the segments are able
to share.
Example:
Consider a text editor in time sharing system.
If the text size is large, it is divided into multiple segments.
As the text editor is non self modifying, we can keep one copy on
physical memory along with data for respective process.
The text editor is shared among all the process for their execution
Sharing in SegmentationSharing in Segmentation
Continue….Continue….
Limit Base
25286 43062
4425 68348
Logical Memory
Process P1
Logical Memory
Process P2
Editor
Segment
0
Editor
Segment
0
Data 1
Data 2
Segment 1
Segment 1
Limit Base
25286 43062
8550 90003
0
1
0
1
Segment Table
Process P1
Segment Table
Process P1
Operating
system
Editor
Data 1
Data 2
43062
68348
72773
90003
98553
Physical
Memory
End of Chapter 8End of Chapter 8

Más contenido relacionado

La actualidad más candente

Unit iiios Storage Management
Unit iiios Storage ManagementUnit iiios Storage Management
Unit iiios Storage Managementdonny101
 
Ios103 ios102 iv-operating-system-memory-management_wk4
Ios103 ios102 iv-operating-system-memory-management_wk4Ios103 ios102 iv-operating-system-memory-management_wk4
Ios103 ios102 iv-operating-system-memory-management_wk4Anwal Mirza
 
Deterministic Memory Abstraction and Supporting Multicore System Architecture
Deterministic Memory Abstraction and Supporting Multicore System ArchitectureDeterministic Memory Abstraction and Supporting Multicore System Architecture
Deterministic Memory Abstraction and Supporting Multicore System ArchitectureHeechul Yun
 
Process management
Process managementProcess management
Process managementMohd Arif
 
Memory management
Memory managementMemory management
Memory managementcpjcollege
 
Operating Systems Part III-Memory Management
Operating Systems Part III-Memory ManagementOperating Systems Part III-Memory Management
Operating Systems Part III-Memory ManagementAjit Nayak
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating SystemRaj Mohan
 

La actualidad más candente (20)

Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
 
CS6401 OPERATING SYSTEMS Unit 3
CS6401 OPERATING SYSTEMS Unit 3CS6401 OPERATING SYSTEMS Unit 3
CS6401 OPERATING SYSTEMS Unit 3
 
Unit iiios Storage Management
Unit iiios Storage ManagementUnit iiios Storage Management
Unit iiios Storage Management
 
Cs8493 unit 3
Cs8493 unit 3Cs8493 unit 3
Cs8493 unit 3
 
OSCh9
OSCh9OSCh9
OSCh9
 
Cs8493 unit 2
Cs8493 unit 2Cs8493 unit 2
Cs8493 unit 2
 
Ios103 ios102 iv-operating-system-memory-management_wk4
Ios103 ios102 iv-operating-system-memory-management_wk4Ios103 ios102 iv-operating-system-memory-management_wk4
Ios103 ios102 iv-operating-system-memory-management_wk4
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Deterministic Memory Abstraction and Supporting Multicore System Architecture
Deterministic Memory Abstraction and Supporting Multicore System ArchitectureDeterministic Memory Abstraction and Supporting Multicore System Architecture
Deterministic Memory Abstraction and Supporting Multicore System Architecture
 
Process management
Process managementProcess management
Process management
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Memory management
Memory managementMemory management
Memory management
 
Ch4 memory management
Ch4 memory managementCh4 memory management
Ch4 memory management
 
Main Memory
Main MemoryMain Memory
Main Memory
 
Operating Systems Part III-Memory Management
Operating Systems Part III-Memory ManagementOperating Systems Part III-Memory Management
Operating Systems Part III-Memory Management
 
cache
cachecache
cache
 
Refining Linux
Refining LinuxRefining Linux
Refining Linux
 
03 Hadoop
03 Hadoop03 Hadoop
03 Hadoop
 
Memory management
Memory managementMemory management
Memory management
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 

Similar a Operating System

Chapter 9 OS
Chapter 9 OSChapter 9 OS
Chapter 9 OSC.U
 
Bab 4
Bab 4Bab 4
Bab 4n k
 
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 allVSKAMCSPSGCT
 
Unit 5Memory management.pptx
Unit 5Memory management.pptxUnit 5Memory management.pptx
Unit 5Memory management.pptxSourabhRaj29
 
CSE2010- Module 4 V1.pptx
CSE2010- Module 4 V1.pptxCSE2010- Module 4 V1.pptx
CSE2010- Module 4 V1.pptxMadhuraK13
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
 
Memory Managment(OS).pptx
Memory Managment(OS).pptxMemory Managment(OS).pptx
Memory Managment(OS).pptxRohitPaul71
 
Unit-4 swapping.pptx
Unit-4 swapping.pptxUnit-4 swapping.pptx
Unit-4 swapping.pptxItechAnand1
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
Main memory os - prashant odhavani- 160920107003
Main memory   os - prashant odhavani- 160920107003Main memory   os - prashant odhavani- 160920107003
Main memory os - prashant odhavani- 160920107003Prashant odhavani
 

Similar a Operating System (20)

Chapter 9 OS
Chapter 9 OSChapter 9 OS
Chapter 9 OS
 
CH08.pdf
CH08.pdfCH08.pdf
CH08.pdf
 
Bab 4
Bab 4Bab 4
Bab 4
 
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
 
Ch8
Ch8Ch8
Ch8
 
Memory comp
Memory compMemory comp
Memory comp
 
Opetating System Memory management
Opetating System Memory managementOpetating System Memory management
Opetating System Memory management
 
Unit 5Memory management.pptx
Unit 5Memory management.pptxUnit 5Memory management.pptx
Unit 5Memory management.pptx
 
Ch8 main memory
Ch8   main memoryCh8   main memory
Ch8 main memory
 
CSE2010- Module 4 V1.pptx
CSE2010- Module 4 V1.pptxCSE2010- Module 4 V1.pptx
CSE2010- Module 4 V1.pptx
 
Main Memory
Main MemoryMain Memory
Main Memory
 
Memory management OS
Memory management OSMemory management OS
Memory management OS
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Memory Managment(OS).pptx
Memory Managment(OS).pptxMemory Managment(OS).pptx
Memory Managment(OS).pptx
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
UNIT-2 OS.pptx
UNIT-2 OS.pptxUNIT-2 OS.pptx
UNIT-2 OS.pptx
 
Unit-4 swapping.pptx
Unit-4 swapping.pptxUnit-4 swapping.pptx
Unit-4 swapping.pptx
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
operating system
operating systemoperating system
operating system
 
Main memory os - prashant odhavani- 160920107003
Main memory   os - prashant odhavani- 160920107003Main memory   os - prashant odhavani- 160920107003
Main memory os - prashant odhavani- 160920107003
 

Más de Subhasis Dash

Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and ArchitectureSubhasis Dash
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and ArchitectureSubhasis Dash
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and ArchitectureSubhasis Dash
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and ArchitectureSubhasis Dash
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer ArchitectureSubhasis Dash
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer ArchitectureSubhasis Dash
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer ArchitectureSubhasis Dash
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer ArchitectureSubhasis Dash
 
Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1) Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1) Subhasis Dash
 

Más de Subhasis Dash (17)

Operating System
Operating SystemOperating System
Operating System
 
Operating System
Operating SystemOperating System
Operating System
 
Operating System
Operating SystemOperating System
Operating System
 
Operating System
Operating SystemOperating System
Operating System
 
Operating System
Operating SystemOperating System
Operating System
 
Operating System
Operating SystemOperating System
Operating System
 
Operating System
Operating SystemOperating System
Operating System
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and Architecture
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and Architecture
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and Architecture
 
Computer Organisation and Architecture
Computer Organisation and ArchitectureComputer Organisation and Architecture
Computer Organisation and Architecture
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer Architecture
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer Architecture
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer Architecture
 
High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer Architecture
 
Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1) Computer Organisation & Architecture (chapter 1)
Computer Organisation & Architecture (chapter 1)
 
Motherboard
MotherboardMotherboard
Motherboard
 

Último

Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 

Último (20)

Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 

Operating System

  • 1. Main MemoryMain Memory Mr. SUBHASIS DASH SCHOLE OF COMPUTER ENGINEERING. KIIT UNIVERSITY BHUBANESWAR
  • 2. BackgroundBackground Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only storage CPU can access directly Register access in one CPU clock (or less) Main memory can take many cycles Cache sits between main memory and CPU registers Protection of memory required to ensure correct operation Registers L1-Cache L2-Cache Main Memory Disk, Tape, etc. Bigger Faster & Costly L3-Cache (optional) CPU
  • 3. Binding of Instructions and Data toBinding of Instructions and Data to MemoryMemory Address binding of instructions and data to memory addresses can happen at three different stages Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes Load time: Must generate relocatable code if memory location is not known at compile time Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers)
  • 4. Dynamic LoadingDynamic Loading Routine is not loaded until it is called Routines are kept in a relocatable load format. Better memory-space utilization; unused routine is never loaded Useful when large amounts of code are needed to handle infrequently occurring cases No special support from the operating system is required implemented through program design
  • 5. Dynamic LinkingDynamic Linking System always needs a copy of language library included in executable image Dynamically linked libraries. Static linking (System language libraries in binary program image). Concept of dynamic linking == dynamic loading.(Rather held up loading until execution we can held up the 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 needed to check if routine is in processes’ memory address Dynamic linking is particularly useful for libraries System also known as shared libraries
  • 6. Multistep Processing of a User ProgramMultistep Processing of a User Program
  • 7. overlaysoverlays  Program & data must be in physical memory to start execution.  If (Program +Data) size <= size of physical memory then start execution else use a technique called overlays.  Example:- Given data:- Process Memory Size Pass-1 70kb Pass-2 80kb Total memory Symbol table 20kb required 200kb. Common Routine 30kb Main memory size available is 150kb. Hence 200kb >150kb
  • 9. Logical vs. Physical Address SpaceLogical vs. Physical Address Space User’s view User program see primary memory as continuous space Actual view User program may be scattered according to the instruction address location. The concept of a logical address space that is bound to a separate physical address space is central to proper memory management Logical address – generated by the CPU; also referred to as virtual address Physical address – address seen by the memory unit Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme
  • 10. Base and Limit RegistersBase and Limit Registers A pair of base and limit registers define the logical address space
  • 11. Memory-Management Unit (Memory-Management Unit (MMUMMU)) Hardware device that maps logical to physical address In MMU scheme, the value in the basrelocation register is added to every address generated by a user process at the time it is sent to memory The user program deals with logical addresses; it never sees the real physical addresses
  • 12. Dynamic relocation using a relocationDynamic relocation using a relocation registerregister
  • 13. HW address protection with base and limitHW address protection with base and limit registersregisters  Logical Physical Address Address Yes Trap : Addressing Error Limit Register Relocation Register <CPU + Memory
  • 14. SwappingSwapping A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows) System maintains a ready queue of ready-to-run processes which have memory images on disk
  • 15. Schematic View of SwappingSchematic View of Swapping If a system wants to swaps a process ,it must take care of some important points like:- Is the process waits for its I/O operation? System wants to create free space in memory
  • 16. Contiguous AllocationContiguous Allocation Main memory usually into two partitions: Resident operating system, usually held in low memory with interrupt vector User processes then held in high memory. Memory Partition Operating system USER Program
  • 17. Contiguous Allocation (Cont.)Contiguous Allocation (Cont.) 1. SINGLE PARTITION ALLOCATION Relocation registers used to protect user processes from each other, and from changing operating-system code and data Base register contains value of smallest physical address Limit register contains range of logical addresses – each logical address must be less than the limit register MMU maps logical address dynamically
  • 18. Contiguous Allocation (Cont.)Contiguous Allocation (Cont.) 2. MULTIPLE-PARTITION ALLOCATION A. Multiprogramming With Fixed Partition (MFT) :- Objective:- To have more then one process in memory at once. Best way Divide memory into N Possible unequal partitions. But no single partition can accommodate more than one process When process arrives , it can put into the input queue for the smallest partition but large enough to accommodate the process. Though the technique moving towards best size fit ,still there are some free spaces in partition which can’t be used further. Unused memory space leads to INTERNAL FRAGMENTATION. To avoid undesirable loss of memory space in the partition, search the whole input queue when a partition becomes free,& pick up the largest object that fits.
  • 19. Contiguous Allocation (Cont.)Contiguous Allocation (Cont.) Multiprogramming With Fixed Partition (MFT) :- Single I/P queue Partition -- 3 Partition -- 2 Partition – 1 Partition -- 4 Operating system
  • 20. Contiguous Allocation (Cont.)Contiguous Allocation (Cont.) B. Multiprogramming With variable Partition (MVT) :- Number ,size of the process & memory partition vary dynamically . Hole – block of available memory; holes of various size are scattered throughout memory When a process arrives, it is allocated memory from a hole large enough to accommodate it Operating system maintains information about: a) allocated partitions b) free partitions (hole) Process growth due to data segment can be adjusted with the dynamic free space . If it is not sufficient then process have to swap out otherwise kill the process.
  • 21. Contiguous Allocation (Cont.)Contiguous Allocation (Cont.) B. Multiprogramming With variable Partition (MVT) :-  We can conclude that, When process appears  Kept into the input queue according to the scheduling algorithm  allocate the memory when it space is available  When memory is not satisfy to the next process the operating system have to wait until the required memory space is available otherwise it simply skips that process and switch for the next smaller process.  The unused spaces between different process leads to EXTERNAL FRAGMENTATION. 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
  • 22. Contiguous Allocation (Cont.)Contiguous Allocation (Cont.) Example:- Memory available = 2560kb OS takes a memory space of = 400kb Memory space for user process = 2560 − 400 = 2160kb Use Round robin scheduling algorithm with quantum time = 07 unit of time. Given data:- Process Memory Time P1 600kb 10 P2 1000kb 05 P3 300kb 20 P4 700kb 08 P5 500kb 15 Solution:- 0 7 12 19 26 33 36 43 44 51 57 58 P1 P2 P3 P4 P5 P1 P3 P4 P5 P3 P5
  • 23. Dynamic Storage-Allocation ProblemDynamic Storage-Allocation Problem First-fit: Allocate the first hole that is big enough Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size Produces the smallest leftover hole Worst-fit: Allocate the largest hole; must also search entire list Produces the largest leftover hole How to satisfy a request of size n from a list of free holes First-fit and best-fit better than worst-fit in terms of speed and storage utilization
  • 24. FragmentationFragmentation External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used Reduce external fragmentation by compaction Shuffle memory contents to place all free memory together in one large block Compaction is possible only if relocation is dynamic, and is done at execution time I/O problem  Latch job in memory while it is involved in I/O  Do I/O only into OS buffers
  • 25. PagingPaging External fragmentation problem can be treated by PAGING. Logical address space of a process can be noncontiguous; process is allocated physical memory whenever space is available Address mapping in paging scheme Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8,192 bytes) Divide logical memory into blocks of same size called pages Keep track of all free frames To run a program of size n pages, need to find n free frames and load program Set up a page table to translate logical to physical addresses Internal fragmentation
  • 26. Address Translation SchemeAddress Translation Scheme Address generated by CPU (Logical Address ) is divided into Page number (p) – used as an index into a page table which contains base address of each page in physical memory Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit Base address + page offset = physical address
  • 27. Paging Model of Logical and PhysicalPaging Model of Logical and Physical MemoryMemory Page Number As index Base Address Of each Page in Physical Memory
  • 28. Paging HardwarePaging Hardware Page no.(p) is An index into Page table. Base address of Each page in Physical memory Base address + page offset= Physical address
  • 29. LALA Address MappingAddress Mapping PAPA If size of logical address space 2m and page size2n then Low order n bits of logical address represents the page offset. High order remaining bits (m-n) represents the page number. Page number P is an index into page table. page offset d is the displacement within pages. page number page offset p m - n d n
  • 30. Paging ExamplePaging Example 32-byte memory and 4-byte pages Physical Address = (frame No.× page size) + Page offset Page Number As index Base Address Of each Page in Physical Memory Page 0 Page 1 Page 2 Page 3
  • 31. LALA Address MappingAddress Mapping PAPA Physical Address = (frame No.× page size) + Page offset Example:- page size is 04 bytes. Physical memory size is of 32bytes. Hence total number of pages 32 bytes / 4 bytes = 08. ☻ If logical address is 0 then, what is its corresponding physical address? ☻ Page offset (d) = displacement within pages = 0 – 0 = 0 ☻ Hence Page number is = 0, which is in frame 5 given as in page table. ☻ So physical address = (5 x 4) + 0 = 20 ☻ If logical address is 03 then, what is its corresponding physical address? ☻ Page offset (d) = displacement within pages = 03 – 0 = 3 ☻ Hence Page number is = 0, which is in frame 5 given as in page table. ☻ So physical address = (5 x 4) + 3 = 23
  • 32. Paging ExamplePaging Example Continue…Continue… ☻ If logical address is 04 then, what is its corresponding physical address? ☻ Page offset (d) = displacement within pages = 04 – 4 = 0 ☻ Hence Page number is = 1, which is in frame 6 given as in page table. ☻ So physical address = (6 x 4) + 0 = 24 ☻ If logical address is 10 then, what is its corresponding physical address? ☻ Page offset (d) = displacement within pages = 10 – 8 = 2 ☻ Hence Page number is = 2, which is in frame 1 given as in page table. ☻ So physical address = (1 x 4) + 2 = 06 ☻ If logical address is 13 then, what is its corresponding physical address? ☻ Page offset (d) = displacement within pages = 13 – 12 = 01 ☻ Hence Page number is = 3, which is in frame 2 given as in page table. ☻ So physical address = (2 x 4) + 1 = 09 ☻ If logical address is 15 then, what is its corresponding physical address? ☻ Page offset (d) = displacement within pages = 15 – 12 = 3 ☻ Hence Page number is = 3, which is in frame 2 given as in page table. ☻ So physical address = (2x 4) + 3 = 11
  • 33. Problems with pagingProblems with paging During process scheduling pages are loaded into the available frames & page table is updated. Paging scheme don’t suffers with external fragmentation. But Paging scheme suffers with internal fragmentation. Because when process don’t comes under page boundaries, the last frame allocated may not be full. Example: Page size = 2048 bytes Process size = 72,766 bytes so it needs 72,766 / 2048 = 35 (1035 bytes) So internal fragmentation is = 2048 – 1035 = 962 bytes free Remedy As small as the page size to reduce internal fragmentation Increase the page table size. Make disk I/O more efficient that large data can be transferred.
  • 34. Implementation of Page TableImplementation of Page Table Page table consist of dedicated registers with very high speed logic to make the address translation efficient. For large page table ,it must kept in main memory. Page-table base register (PTBR) points to the page table Page-table length register (PTLR) indicates size of the page table Example: If we want to access location i then  First page number index into the page table for i location.  Frame number & page offset can found from page table. In this scheme every data/instruction access requires two memory accesses. One for the page table and one for the data/instruction.
  • 35. Implementation of Page TableImplementation of Page Table Continue….Continue…. Solution: The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs) TLB register consist of two parts :- key & value Some TLBs store address-space identifiers (ASIDs) in each TLB entry – uniquely identifies each process to provide address-space protection for that process
  • 36. TLB as Associative MemoryTLB as Associative Memory Associative memory – parallel search Address translation (p, d) If p is in associative register, get frame # out  TLB HIT Otherwise get frame # from page table in memory  TLB MISS Page # Frame #
  • 37. Paging Hardware With TLBPaging Hardware With TLB As Associative register
  • 38. Effective Access TimeEffective Access Time EAT = PH ( TA + TM ) + (1 - PH ) ( TA + 2TM ) Where PH Hit ratio – percentage of times that a page number is found in the associative registers; ratio related to number of associative registers TA Time to search associative memory. TM  Memory access time. Example: Hit ratio for associative memory = 80 % Time to search associative memory (TA) = 20 ns Memory access time (TM ) = 100 ns EAT = 0.80 ( 20 + 100 ) + (1 – 0.80 ) (20 + [ 2 x 100 ] ) = ( 0.8 x 120 ) + ( 0.2 x 220 ) = 96 + 44 = 140 ns Hence we suffers with 40 % slowdown in memory access time.
  • 39. Advantages of PagingAdvantages of Paging Possibility of sharing common code in time sharing environment. Each process has its own copy of register s and data storage . Each user page table maps on to the same physical copy of the shared code but data pages are mapped on to different frames. Read only nature of shared code should not be left to the correctness of the code
  • 40. Memory Protection in pagingMemory Protection in paging Memory protection implemented by associating protection bit with each frame. One protection bit can define a page is read only or read /write. An attempt to write to a read only page causes a hardwire trap (memory protection violation) to the operating system. Valid-invalid bit attached to each entry in the page table: “valid” indicates that the associated page is in the process logical address space, and is thus a legal page “invalid” indicates that the page is not in the process logical address space and is thus an illegal page.
  • 41. Memory Protection in pagingMemory Protection in paging Continue……Continue…… Example:- Total memory space is 16383 bytes. Used memory space is 10468 bytes. Page size 2000 bytes. Total number of page required = 10468 / 2000 = 5 (468 / 2000) = 6 pages So the 0,1,2,3,4,5 are valid pages. But any attempt to find page 6 or 7 or other pages (Invalid pages) will be trapped by operating system.
  • 42. Valid (v) or Invalid (i) Bit In A PageValid (v) or Invalid (i) Bit In A Page TableTable LOGICAL ADDRES S PHYSICA L ADDRES S
  • 43. Shared PagesShared Pages Shared code One copy of read-only (reentrant) code shared among processes (i.e., text editors, compilers, window systems). Shared code must appear in same location in the logical address space of all processes Private code and data Each process keeps a separate copy of the code and data The pages for the private code and data can appear anywhere in the logical address space
  • 44. Shared Pages ExampleShared Pages Example Suppose a system supports 40 users. Each user executes a text editor of 150 kb of code & 50 kb of data space. Hence total space required = (150 + 50) x 40 = 8000 kb But shared page scheme can reduce the total space (8000 kb) required . Solution: If code is reentrant (pure code) it can be shared. Text editor Code is reentrant means non self modifying code (CODECODE NEVER CHANGES DURING EXECUTIONNEVER CHANGES DURING EXECUTION), only fetch / read can possible. Non self modifying code can be used by more than one user at once.
  • 45. Shared Pages ExampleShared Pages Example Continue…..Continue….. Solution: Physical memory must contain a copy of text editor & data required for each user. Hence each user can have a copy of the text editor code along with data page in their executable space, by which execution can possible. Each user’s page table maps on to the same physical copy of the text editor but the data pages are mapped on to different frames in the physical memory. Divide text editor into 3 pages (50 kb each) & share among all 40 users. But each user must have its own data page (50 kb each). Hence to support 40 users total space required is  150 kb + ( 50 kb x 40 ) = 2150 kb
  • 46. Shared Pages ExampleShared Pages Example
  • 47. SegmentationSegmentation Memory-management scheme that supports user view of memory Actually user view is not a linear array of memory space. It prefers to view memory as a collection of variable sized segments. Hence, A program is a collection of segments. A segment is a logical unit such as: Main program, Local variables Procedure, Global variables Function, common block, Method, Stack, Object, Symbol table Subroutine Arrays
  • 48. User’s View of a ProgramUser’s View of a Program
  • 49. Logical View of SegmentationLogical View of Segmentation Segmentation supports the view of memory A logical address space is a collection of segments . Logical Address specify both the segment number & offset within the segment. Each segment has a number & length. Logical address consists of a two tuple: < segment-number, segment offset > SEGMENT NUMBER SEGMENT OFFSET L G I C A L A D D R E S S
  • 50. Logical View of SegmentationLogical View of Segmentation Continue……Continue…… 1 3 2 4 1 4 2 3 user space physical memory space Segmentation uses variable size partition. Hence it suffers from EXTERNAL FRAGMENTATION.
  • 51. Implementation of Segment TableImplementation of Segment Table Segment table can be either in buffer or in main memory. 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 Segment table entry = STBR + S(offset) Read the above result from memory & segment offset is checked against the segment length ,hence the physical address can be found.
  • 52. LALA Address MappingAddress Mapping PAPA Segment table helps in mapping. Logical address consists of a two tuple: < segment-number, segment offset > Segment number is used as an index to the segment table. Each entry to the segment table has a base ( starting physical address) and limit ( range of segment ) register. The segment offset given in logical address must occur between the range given by limit register ( legal offset ) otherwise there is an addressing error. If (Segment Offset Value < Limit Register Value) then ADD Base Register Value with Segment Offset value else Addressing Error
  • 55. LALA Address MappingAddress Mapping PAPA Example : Here we have 5 segments. If a logical address is then check 53 < 400 Physical Address = 4300 + 53 = 4353 If a logical address is then check 852 < 1100 Physical Address = 3200 + 852 = 4052 If a logical address is then check 1222 >1000 illegal segment offset (d). Addressing Error (trap). 02 53 S d 03 852 S d 00 1222 S d what is its corresponding physical address? what is its corresponding physical address? what is its corresponding physical address?
  • 56. Protection in SegmentationProtection in Segmentation A program consists of instruction segment, data segment, editor segment. Instructions are non self modifying, so read only. Protection bit is checked to prevent illegal access. With each entry in segment table associate:  validation bit = 0 ⇒ illegal segment  validation bit = 1 ⇒ Legal 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
  • 57. Sharing in SegmentationSharing in Segmentation Instructions are non self modifying, (read only) hence the code can be sharable. When entries to the segment table of two different process points to same physical locations then the segments are able to share. Example: Consider a text editor in time sharing system. If the text size is large, it is divided into multiple segments. As the text editor is non self modifying, we can keep one copy on physical memory along with data for respective process. The text editor is shared among all the process for their execution
  • 58. Sharing in SegmentationSharing in Segmentation Continue….Continue…. Limit Base 25286 43062 4425 68348 Logical Memory Process P1 Logical Memory Process P2 Editor Segment 0 Editor Segment 0 Data 1 Data 2 Segment 1 Segment 1 Limit Base 25286 43062 8550 90003 0 1 0 1 Segment Table Process P1 Segment Table Process P1 Operating system Editor Data 1 Data 2 43062 68348 72773 90003 98553 Physical Memory
  • 59. End of Chapter 8End of Chapter 8