OS Chapter 5
OS Chapter 5
• Absolute code: It is a code and data which will placed where you
insist assembler to be placed.
1.Entire program load into main memory before 1.On demand it load program into memory
program start execution.
2.Memory utilization is inefficient because it require 2. Memory utilization is efficient because it load
or not it load whole program into main memory. program on demand.
5. Static linking is applied if the static loading used 5. dynamic linking is applied if the dynamic loading
accordingly used accordingly
6.To start execution absolute data and program load 6. Bit by bit loading of data and information in run
into memory time
Swapping
• For temporarily any process can be swapped out of memory to
backing store and take back into memory for further execution.
• Roll out roll in: for priority based scheduling algorithm swapping
variant used; to load high-priority process and to get execute lower
priority process need to swapped out.
1000MB
Figure – 8 Single Process Monitor[9]
Single Process Monitor
• Only one process can load to memory in Single Process Monitor. The
next process will be loaded into memory when one process is
complete.
• The number of partitions are fixed but the size of each partition can
be different.
1000
Figure - 10 Multiprogramming with Variable Partition[9]
Multiprogramming with Variable Partition(MVT)
• In figure above memory is divide into 4 unequal size partitions.
Partition size is not equal.
1000
Figure - 12 Example of Internal Fragmentation [13]
External Fragmentation
• When the process is loaded or removed from the memory, a free
space is created. This free space creates an empty space in the
memory which is called external fragmentation.
• The main idea behind the paging is to divide each process in the
form of pages.
• Initially, all the frames are empty therefore pages of the processes
will get stored in the contiguous way.
Example of Paging
• Let us consider that, P2 and P4 are moved to waiting state after
some time.
• The logical address is the address generated by the CPU for every
page while the physical address is the actual address of the frame
where each page will be stored.
Memory Management Unit
• 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.
.
Physical Address Space
• Physical address space in a system can be defined as the size of the
main memory.
• It is really important to compare the process size with the physical
address space. The process size must be less than the physical address
space.
• Syntax of Physical Address Space is:
Physical Address Space = Size of the Main Memory
Example of Physical Address Space
If, physical address space = 64 KB = 2 ^ 6 KB = 2 ^ 6 X 2 ^ 10 Bytes = 2
^ 16 bytes
Let us consider,
word size = 8 Bytes = 2 ^ 3 Bytes
Hence,
Physical address space (in words) = (2 ^ 16) / (2 ^ 3) = 2 ^ 13 Words
Therefore,
Physical Address = 13 bits
Logical Address Space
• Logical address space can be defined as the size of the process. The
size of the process should be less enough so that it can reside in the
main memory.
For Example of Logical Address Space is:
Logical Address Space = 128 MB = (2 ^ 7 X 2 ^ 20) Bytes = 2 ^ 27 Bytes
Word size = 4 Bytes = 2 ^ 2 Bytes
Logical Address Space (in words) = (2 ^ 27) / (2 ^ 2) = 2 ^ 25 Words
Logical Address = 25 Bits
Logical Address Space
• What is a Word?
The Word is the smallest unit of the memory. It is the collection of
bytes. Every operating system defines different word sizes after
analyzing the n-bit address that is inputted to the decoder and the
2 ^ n memory locations that are produced from the decoder.
.
Page Table
• Page Table is a data structure used by the virtual memory system to
store the mapping between logical addresses and physical addresses.
• Logical addresses are generated by the CPU for the pages of the
processes therefore they are generally used by the processes.
• Physical addresses are the actual frame address of the memory.
• They are generally used by the hardware or more specifically by
RAM subsystems.
Representation of Physical and Logical Address
• In other words memory can be used efficiently and each job runs on
its own address space. Frames, pages and the mapping between the
two is shown in the .
Example of Page Allocation
• From figure, the size of each page is
100 memory locations.
• Pointer to the page table is stored with other register values in PCB.
• The main use of registers for the page table is satisfactory if the
page table is reasonably small.
• But current systems have Page table size that is very large, so
use of only registers is not feasible.
Hardware Support
2) Using Translation look-aside buffer (TLB).
• A CPU generates 32-bit virtual addresses and the page size is 4 KB.
The processor have translation look-aside buffer (TLB) which can hold
a total of 128 page table entries and it is 4-way set associative.
Answer:-
Here, size of a page = 4KB = 2^12
Total number of bits required to address a page frame = 32 – 12 = 20
If there are ‘n’ cache lines in a set, the cache placement is called n-
way set associative.
TLB is 4 way set associative and can hold total 128 (2^7) page table
entries, number of sets in cache = 2^7/4 = 2^5.
So 5 bits are needed to address a set, and 15 (20 – 5) bits are needed
for tag.
Paging Hardware with TLB
• For Example:-
If pages are 120 bytes, a process of 400 bytes requires 3
pages + for 40 bytes it requires again 1 page. So total 4
pages will be allocated.
For Example,
• Segment 2 is 400 bytes long. Begins at 4300.
• It will check 53 < 0 – limit ( i.e. 400)
• So that, a reference to byte 53 of segment 2 is mapped as
4300 + 53 = 4353.
• now check for 1222 byte for segment 0 .
• 1222 < 0 – 1000 , which is false so it will be trapped to OS.
Difference between Segmentation and Paging
Segmentation Paging
1 Program is divided into variable size Program is divided into fix size of pages.
segments.
2 Segmentation is slower than paging. Paging is faster than segmentation.
• Costly algorithm.
• So that the page table is paged, the page number is again divided
into following:
- a 12-bit page number
- a 10-bit page offset (p2)
Two – Level Paging Example
• Thus, a logical address is as follows:
page number page offset
p1 p2 d
12 10 10
• where,
- the outer page table use p1 as an index number
- p2 is the rearrangement within the page of the inner page
table