Professional Documents
Culture Documents
Unit4 OS
Unit4 OS
Unit4 OS
Operating Systems
ACSE0403A
Unit 4
Memory Allocation: Allocation Strategies First Fit, Best Fit, and Worst Fit, Paging,
Segmentation, Paged Segmentation, Virtual Memory Concepts, Demand Paging,
Performance of Demand Paging, Page Replacement Algorithms: FIFO,LRU,
Optimal and LFU, Belady’s Anomaly, Thrashing, Cache Memory Organization,
Locality of Reference.
Memory management keeps track of the status of each memory location, whether it is
allocated or free.
It allocates the memory dynamically to the programs at their request and frees it for
reuse when it is no longer needed.
Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter Baer Galvin, and Greg
Gagne Page No. -316
June 1, 2024 Rajeev Kumar ACSE0403A OS Unit 4 7
Hardware Address Protection (CO4)
Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter Baer
Galvin, and Greg Gagne Page No. -317
Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter Baer
Galvin, and Greg Gagne Page No. -318-319.
June 1, 2024 11
Rajeev Kumar ACSE0403A OS Unit 4
Memory-Management Unit (MMU)
-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
-Logical address bound to physical addresses
For Video Lecture:-
http://www.infocobuild.com/education/audio-video-courses/computer-science/IntroToOperatin
gSystems-IIT-Madras/lecture-07.html
13
June 1, 2024 Rajeev Kumar ACSE0403A OS Unit 4
Dynamic relocation using a relocation register
14
June 1, 2024 Rajeev Kumar ACSE0403A OS Unit 4
Linking & Loading (CO4)
Types of Linking
A.Static linking
B.Dynamic linking
Types of Loading
A.Static Loading
B.Dynamic Loading
• As explained above, when static linking is used, the linker combines all other
modules needed by a program into a single executable program to avoid any
runtime dependency.
• When dynamic linking is used, it is not required to link the actual module or
library with the program, rather a reference to the dynamic module is provided
at the time of compilation and linking. Dynamic Link Libraries (DLL) in
Windows and Shared Objects in Unix are good examples of dynamic libraries.
Backing store – fast disk large enough to accommodate copies of all memory
images for all users; must provide direct access to these memory images
Topic CO
Multiprogramming with Fixed CO4
Partitions, Multiprogramming with
variable partitions,
Memory Allocation: Allocation CO4
Strategies First Fit, Best Fit, and Worst
Fit
Topic Objective
Students will be able to
Multiprogramming with Fixed Understand the static and dynamic approaches of memory
Partitions, Multiprogramming with partition with their advantages and
variable partitions,
Memory Allocation: Allocation Understand different types of allocation strategies
Strategies First Fit, Best Fit, and Worst
Fit
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
– Can then allow actions such as kernel code being transient and kernel
changing size
Multiple-partition allocation
Hole – block of available memory; holes of various size are scattered throughout
memory
• 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
Note:- First-fit and best-fit are better than worst-fit in terms of speed and storage
utilization
Internal Fragmentation
• In this fragmentation, the process is allocated a memory block of size more
than the size of that process. Due to this some part of the memory is left
unused and this cause internal fragmentation.
• Example: Suppose there is fixed partitioning (i.e. the memory blocks are of
fixed sizes) is used for memory allocation in RAM. These sizes are 2MB,
4MB, 4MB, 8MB. Some part of this RAM is occupied by the Operating
System (OS).
• Now, suppose a process P1 of size 3MB comes and it gets memory block of
size 4MB. So, the 1MB that is free in this block is wasted and this space can’t
be utilized for allocating memory to some other process. This is
called internal fragmentation.
P2
Prerequisite
To know about the basic knowledge of program execution environment and what the usage of
Random Access Memory(RAM) .
Recap
To understood various techniques of allocating memory to processes.
Topic CO
Paging & Segmentation CO4
Topic Objective
Students will be able to
Paging & Segmentation Understand the non contiguous memory allocation
schemes
Segmentation With Paging Know about the implementation of segmentation
with paging concept
• To discuss in detail how paging & segmentation works in contemporary computer systems.
• To understand different types of structure of page table.
Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter Baer Galvin, and Greg
Gagne Page No. -328-332.
Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter Baer Galvin, and
Greg Gagne Page No. -333
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
Video Lecture:-https://www.youtube.com/watch?v=xD5PB_g1rIE
Advantages :
No internal fragmentation
Average segment size is larger than the actual page size.
It is easier to relocate segments than entire address space.
The segment table is of lesser size as compared to the page table in paging.
Less overhead.
Disadvantages :
It can have external fragmentation.
Costly memory management algorithms.
It is difficult to allocate contiguous memory to variable sized partition.
Segments of unequal size not suited well for swapping.
In segmented paging,
Process is first divided into segments and then each segment is divided into pages.
These pages are then stored in the frames of main memory.
A page table exists for each segment that keeps track of the frames storing the pages of
that segment.
Each page in page table occupies one frame in the main memory.
Number of entries in the page table of a segment = Number of pages that segment is
divided.
A segment table exists that keeps track of the frames storing the page tables of
segments.
Number of entries in the segment table of a process = Number of segments that
process is divided.
The base address of the segment table is stored in the segment table base register.
Advantages-
• Segment table contains only one entry corresponding to each segment.
• It reduces memory usage.
• The size of page table is limited by the segment size.
• It solves the problem of external fragmentation.
Disadvantages-
• Segmented paging suffers from internal fragmentation.
• The complexity level is much higher as compared to paging.
Topic CO
Virtual Memory Concepts, CO4
Topic Objective
Students will be able to
Virtual Memory Concepts, Understand the concept of Virtual Memory
Demand Paging, Performance of Demand Know about Demand Paging, Performance of Demand
Paging, Paging
Page Replacement Algorithms: FIFO,LRU, Understand the Page Replacement Algorithms:
Optimal and LFU, FIFO,LRU, Optimal and LFU,
• In the modern world, virtual memory has become quite common these days. It
is used whenever some pages require to be loaded in the main memory for the
execution, and the memory is not available for those many pages.
• So, in that case, instead of preventing pages from entering in the main memory,
the OS searches for the RAM space that are minimum used in the recent times
or that are not referenced into the secondary memory to make the space for the
new pages in the main memory.
Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter Baer
Galvin, and Greg Gagne Page No. -361
Prerequisite
To know about the difference between RAM and virtual memory
Recap
To understood usage of the and benefits of a virtual memory system.
During MMU address translation, if valid–invalid bit in page table entry is i page fault
Figure:- Page table when some pages are not in main memory.
Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are
written to disk
Page replacement completes separation between logical memory and physical memory –
large virtual memory can be provided on a smaller physical memory
Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter Baer Galvin, and Greg
Gagne Page No. -369-377
15 page faults
Can vary by reference string: consider 1,2,3,4,1,2,5,1,2,3,4,5
Adding more frames can cause more page faults!
Belady’s Anomaly: It is the phenomenon in which increasing the number of
page frames results in an increase in the number of page faults for certain
memory access patterns.
9 page faults
For Video lecture:- https://www.youtube.com/watch?v=Ub4VVDGLJx0
12 page faults
Keep a counter of the number of references that have been made to each page
Not common.
Least Frequently Used (LFU) Algorithm: replaces page with smallest count
Most Frequently Used (MFU) Algorithm: based on the argument that the page with
the smallest count was probably just brought in and has yet to be used
• Local replacement – each process selects from only its own set of
allocated frames
– More consistent per-process performance
– But possibly underutilized memory
• Let's understand by an example, if any process does not have the number of
frames that it needs to support pages in active use then it will quickly page fault.
And at this point, the process must replace some pages. As all the pages of the
process are actively in use, it must replace a page that will be needed again right
away. Consequently, the process will quickly fault again, and again, and again,
replacing pages that it must bring back in immediately. This high paging activity
by a process is called thrashing.
• During thrashing, the CPU spends less time on some actual productive work and
spend more time on swapping.
June 1, 2024 Rajeev Kumar ACSE0403A OS Unit 4 103
Thrashing (Cont.)
Reference Book :- Operating System Concepts (8th Edition) Abraham Silberschatz, Peter Baer Galvin, and Greg Gagne Page No. -
386-391.
https://docs.google.com/forms/d/e/
1FAIpQLSdsUDs1JSLT_04DIWS7UoSn4CyswTRFbUVrDV3Yn2AmYA6quA/viewform?usp=sf_link
1.https://www.youtube.com/watch?v=kt4LkPFt8Zg
2.https://www.youtube.com/watch?v=Ub4VVDGLJx0
3.https://www.youtube.com/watch?v=njXBgjdn--Y
4.https://www.youtube.com/watch?v=xD5PB_g1rIE
5.https://www.youtube.com/watch?v=j2QujhrwLYA
6.https://www.youtube.com/watch?v=UDPYpf-nsDY
7.https://www.youtube.com/watch?v=lWVQsld8hMI
8.https://www.youtube.com/watch?v=CmTMr_x3NwY
9.https://www.youtube.com/watch?v=zDxEctO31TA
10.https://www.youtube.com/watch?v=kt4LkPFt8Zg&t=165s
11.https://www.youtube.com/watch?v=xD5PB_g1rIE
12.https://www.youtube.com/watch?v=ujoJ7J_l9cY
13.https://www.youtube.com/watch?v=lgmws9oraXE
MCQ Link:-
1. https://www.sanfoundry.com/operating-system-questions-answers-memory-management/
2. https://www.sanfoundry.com/operating-system-mcqs-memory-allocation-1/
3. https://www.sanfoundry.com/operating-system-mcqs-memory-allocation-2/
4. https://www.sanfoundry.com/operating-system-mcqs-memory-management-paging-1/
5. https://www.sanfoundry.com/operating-system-mcqs-memory-management-swapping-1/
6. https://www.sanfoundry.com/operating-system-mcqs-memory-management-segmentation/
7. https://www.sanfoundry.com/operating-system-questions-answers-virtual-memory/
8. https://www.sanfoundry.com/operating-system-mcqs-virtual-memory-page-replacement-algorithms-
1/
https://drive.google.com/drive/folders/1UPXvZ7NY09OunSLrEkTFWpw_M3xLzjhs?
usp=sharing
Books :
1.Silberschatz, Galvin and Gagne, “Operating Systems Concepts”, Wiley
2. SibsankarHalder and Alex A Aravind, “Operating Systems”, Pearson Education
3. Harvey M Dietel, “ An Introduction to Operating System”, Pearson Education
4. D M Dhamdhere, “Operating Systems : A Concept basedApproach”, McGraw Hill.
5.Charles Crowley, “Operating Systems: A Design-Oriented Approach”, Tata McGraw Hill
Education”.
6. Stuart E. Madnick & John J. Donovan, “ Operating Systems”, Tata McGraw