OS-III UNIT IN CS3402 Operating System about Deadlock
1.
MAIN MEMORY orPrimary Memory
¸Primary memory is a segment of computer memory.
¸It can be accessed directly by the processor.
¸It has a storage capacity lesser than secondary memory and
greater than cache memory.
MAIN MEMORY
RAM :
¸Itstands for Random Access Memory.
¸RAM is a volatile memory.
¸That is, it does not store data or
instructions permanently.
¸It located on the motherboard of a computer and acts as an
internal memory of the CPU.
2 Types.
1. SRAM STATIC RAM
2. DRAM DYNAMIC RAM
4.
MAIN MEMORY
ROM :
¸Itstands for Read Only Memory.
¸It is also primary memory unit of computer
¸ROM is a non-volatile memory.
¸That is, it stores information permanently.
¸it is called read only memory. Because we can only read the
programs and data stored on it but cannot write on it.
5.
MAIN MEMORY
ROM :
¸Themanufacturer of ROM fills the programs into
the ROM at the time of manufacturing the ROM. After
this, the content of the ROM can't be altered, which
means you can't reprogram, rewrite, or erase its
content later.
6.
MAIN MEMORY
TYPES OFROM :
1. PROM Programmable Read Only Memory
2. EPROM Erasable and Programmable Read Only Memory
3. EEPROM Electrically Erasable and Programmable Read
Only Memory
7.
MEMORY MANAGEMENT
¸Memory ManagementTechnique is used to managing the
memory in the operating system.
¸It keeps track of every memory location(if it is free or
occupied).
¸Memory Management Techniques are classified broadly
into
two categories:
1. Contiguous
2. Non-contiguous
Contiguous Memory Allocation:
¸ Contiguous memory allocation is a memory management
technique
¸ This technique is used to assign contiguous blocks of
memory
to each task. (contiguous block - adjacent block)
¸ Thus, whenever a process asks to access the main memory,
It allocates a continuous segment from the empty region to
the process based on its size.
Single Contiguous MemoryManagement
Scheme :
¸ In this scheme, the main memory is divided into two
contiguous areas or partitions.
1. The operating systems reside permanently in one
partition(lower memory)
2. The user process is loaded into the other partition.
Multiple Partitioning
¸ Thistechnique allows more than one processes to be
loaded
into main memory.
¸ In this type of allocation, main memory is divided into two
types partitions.
1. fixed-sized partitions.
2. Variable-sized partitions.
14.
Fixed - sizedPartitioning : (Oldest Technique)
¸It is also called Static Partitioning.
¸In this technique, main memory is pre-divided into fixed
size partitions.
¸ In this partitioning, the number of partitions in Main memory
is fixed but the size of each partition may or may not be the
same.
¸ The operating system always resides in the first partition
while the other partitions can be used to store user
processes.
¸ Only one process can be placed in a partition.
15.
Fixed - sizedPartitioning :
In fixed partitioning,
1. The partitions cannot overlap. (no join)
2. A process must be contiguously present in a partition
for the execution.
Fixed - sizedPartitioning :
As illustrated in above figure,
¸first process is only consuming 1MB out of 4MB in the main
memory.
Hence, Internal Fragmentation in first block is (4-1) = 3MB.
Sum of Internal Fragmentation in every block
(4-1)+(8-7)+(8-7)+(16-14)= 3+1+1+2 = 7MB.
¸Suppose process P5 of size 7MB comes.
¸But this process cannot be accommodated in spite of
available free space because of contiguous allocation.
18.
Advantage :
1. Easyto implement:
2. No external fragmentation:
3. Suitable for systems with a fixed number of processes
Disadvantage :
1. Internal Fragmentation.
2. External Fragmentation.
3. Limit process size.
19.
Internal Fragmentation :
¸Mainmemory use is inefficient.
¸Any program, no matter how small, occupies an entire
partition. This can cause internal fragmentation.
20.
External Fragmentation :
Thetotal unused space of various partitions cannot be
used to load the processes even though there is space
available but not in the contiguous form (as spanning is not
allowed).
21.
VARIABLE PARTITIONS
¸ Itis also called Dynamic Partitioning.
¸ In this technique, main memory is not divided into fixed
size partitions.
¸ In this technique, the partition size is not declared initially. It
is declared at the time of process loading.
¸ The first partition is reserved for the operating system. The
remaining space is divided into processes.
¸ The size of each partition will be equal to the size of the
process.
¸ The partition size varies according to the need of the
process
External Fragmentation invariable Partitioning :
Let's consider
¸Three processes P1 (1 MB) and P2 (3 MB) and P3 (1 MB)
are being loaded in the respective partitions of the main
memory.
¸After some time P1 and P3 got completed and their
assigned space is freed.
¸Now there are two unused partitions (1 MB and 1 MB)
available in the main memory but they cannot be used to
load a 2 MB process in the memory since they are not
contiguously located.
25.
Advantage :
1. NoInternal Fragmentation
2. No Limitation on the size of the process
Disadvantage :
1. External Fragmentation
2. Complex Memory Allocation
26.
NON-CONTIGUOUS MEMORY ALLOCATION
¸Non-contiguous memory allocation is a method of memory
allocation in operating systems
¸ The processes get overall space in the memory, but not in a
single place.
¸ That is , The processes are present in various locations
according to the needs of the process.
Paging :
¸ Pagingis one of the storage mechanism.
¸ It is used to retrieve processes from the secondary storage
into the main memory in the form of pages.
¸ The main idea behind the paging is to divide each process in
the form of pages.
¸ The main memory will also be divided in the form of frames.
¸ One page of the method should be saved in one of the
memory frames.
¸ The size of each frame must be uniform. The page size must
match the frame size since the frames in Paging are mapped
to
31.
Example,
¸Let us considerthe main memory size 16 Kb and Frame size
is
1 KB therefore the main memory will be divided into the
collection of 16 frames of 1 KB each.
¸ There are 4 processes in the system that is P1, P2, P3 and P4
of 4 KB each.
¸ Each process is divided into pages of 1 KB each so that one
page can be stored in one frame.
¸ Initially, all the frames are empty therefore pages of the
processes will get stored in the contiguous way.
Example,
¸Let us considerthat, P2 and P4 are moved to waiting state
after some time.
¸ Now, 8 frames become empty and therefore other pages can
be loaded in that empty place.
¸ The process P5 of size 8 KB (8 pages) is waiting inside the
ready queue.
36.
Logical Address:
The logicaladdress is the address generated by the CPU for
every page
Physical Address :
Physical address is the actual address of the frame where each
page will be stored.
37.
When a pageis to be accessed by the CPU by using the
logical address, the operating system needs to obtain the
physical address to access that page physically.
The logical address has two parts.
1. Page Number
2. Offset
Memory management unit of OS needs to convert the page
number to the frame number.
38.
PAGE TABLE :
¸A Page Table is a data structure used by the operating
system.
¸ It is used to keep track of the mapping between virtual
addresses(logical address) used by a process and the
corresponding physical addresses in the system’s memory.
¸Thus page table mainly provides the corresponding frame
number (base address of the frame) where that page is stored
in the main memory.
PAGE TABLE :
¸Eachprocess has its own independent page table.
The Number of entries in the page table = the Number of
Pages in which the process is divided.
Techniques used for Structuring the Page Table:
Some of the common techniques that are used for structuring
the Page table are as follows:
1. Hierarchical Paging
2. Hashed Page Tables
3. Inverted Page Tables
42.
SEGMENTATION :
¸ Segmentationis a memory management technique.
¸ Here, the memory is divided into the variable size parts. Each
part is known as Segment.
¸ A segment can be allocated to a process.
¸ Segmentation gives the user’s view of the process which
paging does not provide.
SEGMENTATION TABLE :
¸The details about each segment are stored in a table called
a
segment table.
¸ It maps a two-dimensional Logical address into a one-
dimensional Physical address.
¸ Segment table contains mainly two information about
segment:
Base : It contains the starting physical address where
the
segments reside in memory.
Limit : Also known as segment offset. It specifies the
45.
Translation of Two-dimensionalLogical Address
to Dimensional Physical Address.
The address generated by the CPU is divided into:
Segment number (s):
Number of bits required to represent the segment.
Segment offset (d):
Number of bits required to represent the size of the segment.
46.
Advantages :
¸ NoInternal fragmentation.
¸ Segment Table consumes less space in comparison to Page
table in paging.
¸ As a complete module is loaded all at once, segmentation
improves CPU utilization.
¸ Flexibility
¸ Sharing: Segmentation allows for sharing of memory
segments between processes. This can be useful for inter-
process communication or for sharing code libraries.
47.
Disadvantage :
¸ Itcan have external fragmentation.
¸ it is difficult to allocate contiguous memory to variable sized
partition.
¸ Costly memory management algorithms.
48.
Types of Segmentation:
There are 2 types of segmentation in os
1. Virtual Memory Segmentation
2. Simple Segmentation
DIFFERENCE B/W PAGINGAND SEGMENTATION
Paging Segmentation
Non-Contiguous memory
allocation
Non-contiguous memory
allocation
Paging divides process into
fixed size pages.
Segmentation divides process
into variable size segments.
OS is responsible Compiler is responsible.
Paging is faster than
segmentation
Segmentation is slower than
paging
51.
DIFFERENCE B/W PAGINGAND SEGMENTATION
Paging Segmentation
Paging is closer to Operating
System
Segmentation is closer to
User
Logical address is divided into
page number and page offset
Logical address is divided into
segment number and
segment offset
Page table is used to maintain
the page information.
Segment Table maintains the
segment information
VIRTUAL MEMORY
¸ Virtualmemory is a memory management technique.
¸ It provides user an illusion(imaginary) of having a very big
main memory.
¸ This is done by treating a part of secondary memory as the
main memory.
¸ In this scheme, User can load the bigger size processes than
the available main memory by having the illusion that the
memory is available to load the process.
55.
HOW VIRTUAL MEMEORYWORK ?
¸ In this scheme, whenever some pages needs to be loaded in
the
main memory for the execution.
¸ But the memory is not available for those many pages,
¸ In this situation, instead of stopping the pages from entering
in
the main memory, the OS search for the RAM area that are
least
used in the recent times or that are not referenced and copy
that into the secondary memory to make the space for the
56.
For example,
¸suppose aprocess requires 5 GB of memory.
¸But the computer system has only 4 GB of RAM installed.
¸In this case, the virtual memory system will allocate additional
memory needed by creating a larger virtual address space
and
mapping it to both the available RAM and the computer's
secondary storage device.
Advantage :
¸The degreeof Multiprogramming will be increased.
¸User can run large application with less real RAM.
¸There is no need to buy more memory RAMs.
Disadvantage :
¸The system becomes slower since swapping takes time.
¸It takes more time in switching between applications.
¸The user will have the lesser hard disk space for its use.
Degree of Multiprogramming :
It describes the maximum number of processes that a
single-processor system can accommodate efficiently.
DEMAND PAGING:
¸ Demandpaging is a memory management technique.
¸ Demand paging is a technique used in virtual memory
systems.
¸ In demand paging, the operating system loads only the
necessary pages of a process into memory at runtime,
instead of loading the entire program into memory at the
start.
¸ It is used to improve memory usage and system
performance.
Advantages of DemandPaging :
1. It increases the degree of multiprogramming as many
processes can be present in the main memory
simultaneously.
2. If any program is larger than physical memory, it helps run
this program without compaction.
3. Partition management is simpler.
4. It is more useful in .
5. Discards external fragmentation.
6. Easy to swap all pages.
64.
Dis advantages ofDemand Paging :
1. The amount of processor overhead and the number of
tables used for handling the page faults is greater than in
simple page management techniques.
2. It has more probability of internal fragmentation.
3. Its memory access time is longer.
4. Page Table Length Register (PTLR) has a limit for
.
5. Page map table is needed additional memory and .
65.
COMPACTION :
Compaction isa technique to collect all the free memory
present in the form of fragments into one large chunk of free
memory which can be used to run other processes.
Advantages :
1. Reducesexternal fragmentation.
2. Make memory usage efficient.
3. Memory becomes contiguous.
4. Since memory becomes contiguous more processes can be
loaded to memory, thereby increasing scalability of OS.
5. Fragmentation of file system can be temporarily removed by
compaction.
6. Improves memory utilization as their is less gap between
memory blocks.
68.
Disadvantages :
1. Systemefficiency reduces and latency is increased.
2. A huge amount of time is wasted in performing compaction.
3. CPU sits idle for a long time.
4. Not always easy to perform compaction.
5. It may cause deadlocks since it disturbs the memory
allocation process.
69.
THRASHING :
¸Thrashing isa condition or a situation when the system is
spending a major portion of its time servicing the page faults,
but the actual processing done is very negligible.
¸ Thrashing causes serious performance issues with the
operating system.
¸ When the CPU’s usage is low, the process scheduling
mechanism tries to load multiple processes into memory at
the same time, increasing the degree of Multi programming.
Page fault : Page fault is a type of error that occurs when a
program tries to access data that is not currently in the main
memory