Virtual Memeory
Virtual Memeory
PAGE SIZE
In operating systems, "page size" refers to the fixed-size blocks (pages)
into which virtual memory is divided, and the physical memory is divided
into frames, used for memory management.
These pages are typically powers of 2, such as 4KB or 16KB, and are
used to map virtual addresses to physical memory addresses.
Common Page Sizes:
4KB: This is a very common page size, supported by many architectures, including x86
and ARM.
16KB: While less common, some architectures, like ARM, also support larger page
sizes, and Android 15 and higher have support for building Android with a 16 KB ELF
alignment, which works with 4 KB and 16 KB kernels starting with android14-6.1.
Other Sizes: Some architectures support other page sizes, such as 2MB or 4MB (i386)
or 1GB (newer CPUs).
Priority Scheduling:
Preemptive Scheduling:
Allows a higher-priority process to interrupt a lower-priority process that is
currently running.
This ensures that high-priority tasks are addressed promptly, but can lead to
frequent context switching.
Non-Preemptive Scheduling:
Once a process starts running, it continues to run until it completes or
voluntarily yields the CPU, even if a higher-priority process arrives.
This minimizes context switching, but can lead to longer wait times for high-
priority tasks.
Short-Term Scheduler
3. Medium-Term Scheduler
Medium Term Scheduler (MTS) is responsible for moving a process from
memory to disk (or swapping).
It reduces the degree of multiprogramming (Number of processes
present in main memory).
A running process may become suspended if it makes an I/O request.
A suspended processes cannot make any progress towards
completion. In this condition, to remove the process from memory and
make space for other processes, the suspended process is moved to
the secondary storage. This process is called swapping, and the
process is said to be swapped out or rolled out. Swapping may be
necessary to improve the process mix (of CPU bound and IO bound)
When needed, it brings process back into memory and pick up right
where it left off.
It is faster than long term and slower than short term.
Medium-Term Scheduler
Context Switching
Conte xt Switching
Program Counter
Scheduling information
The base and limit register value
Currently used register
Changed State
I/O State information
Accounting information
Seek Time - It is the time taken by the disk arm to locate the
desired track.
Rotational Latency - The time taken by a desired sector of
the disk to rotate itself to the position where it can access the
Read/Write heads is called Rotational Latency.
Transfer Time - It is the time taken to transfer the data
requested by the processes.
Disk Access Time - Disk Access time is the sum of the Seek
Time, Rotational Latency, and Transfer Time.
3. SCAN
In the SCAN algorithm the disk arm moves in a particular direction and
services the requests coming in its path and after reaching the end of the
disk, it reverses its direction and again services the request arriving in its
path. So, this algorithm works as an elevator and is hence also known as
an elevator algorithm. As a result, the requests at the midrange are
serviced more and those arriving behind the disk arm will have to wait.
Example:
C-SCAN
In the SCAN algorithm, the disk arm again scans the path that has been
scanned, after reversing its direction. So, it may be possible that too many
requests are waiting at the other end or there may be zero or few requests
pending at the scanned area.
These situations are avoided in the CSCAN algorithm in which the disk
arm instead of reversing its direction goes to the other end of the disk and
starts servicing the requests from there. So, the disk arm moves in a
circular fashion and this algorithm is also similar to the SCAN algorithm
hence it is known as C-SCAN (Circular SCAN).
Example:
5. LOOK
LOOK Algorithm is similar to the SCAN disk scheduling algorithm except
for the difference that the disk arm in spite of going to the end of the disk
goes only to the last request to be serviced in front of the head and then
reverses its direction from there only. Thus it prevents the extra delay
which occurred due to unnecessary traversal to the end of the disk.
Example:
LOOK Algorithm
So, the total overhead movement (total distance covered by the disk arm)
is calculated as
= (190-50) + (190-16) + (43-16) = 341
7. RSS (Random Scheduling)
It stands for Random Scheduling and just like its name it is natural. It is
used in situations where scheduling involves random attributes such as
random processing time, random due dates, random weights, and
stochastic machine breakdowns this algorithm sits perfectly. Which is why
it is usually used for analysis and simulation.
8. LIFO (Last-In First-Out)
In LIFO (Last In, First Out) algorithm, the newest jobs are serviced before
the existing ones i.e. in order of requests that get serviced the job that is
newest or last entered is serviced first, and then the rest in the same
order.
Advantages of LIFO (Last-In First-Out)
Here are some of the advantages of the Last In First Out Algorithm.
Maximizes locality and resource utilization
Can seem a little unfair to other requests and if new requests keep
coming in, it cause starvation to the old and existing ones.
9. N-STEP SCAN
It is also known as the N-STEP LOOK algorithm. In this, a buffer is
created for N requests. All requests belonging to a buffer will be serviced
in one go. Also once the buffer is full no new requests are kept in this
buffer and are sent to another one. Now, when these N requests are
serviced, the time comes for another top N request and this way all get
requests to get a guaranteed service
Advantages of N-STEP SCAN
Here are some of the advantages of the N-Step Algorithm.
It eliminates the starvation of requests completely
10. F-SCAN
This algorithm uses two sub-queues. During the scan, all requests in the
first queue are serviced and the new incoming requests are added to the
second queue. All new requests are kept on halt until the existing
requests in the first queue are serviced.
Advantages of F-SCAN
Here are some of the advantages of the F-SCAN Algorithm.
F-SCAN along with N-Step-SCAN prevents “arm stickiness”
(phenomena in I/O scheduling where the scheduling algorithm
continues to service requests at or near the current sector and thus
prevents any seeking)
Each algorithm is unique in its own way. Overall Performance depends on
the number and type of requests.
Note: Average Rotational latency is generally taken as 1/2(Rotational
latency).