0% found this document useful (0 votes)
3 views

OS

CPU scheduling is crucial for system performance, determining the order and priority of processes based on criteria like CPU utilization, throughput, and turnaround time. Selecting the appropriate scheduling algorithm is vital as different algorithms excel in different scenarios, such as Round Robin for time-sharing systems and Shortest Job First for batch processing. Deadlocks can occur when processes wait indefinitely for resources, and managing them involves prevention, detection, and recovery strategies.

Uploaded by

ishi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

OS

CPU scheduling is crucial for system performance, determining the order and priority of processes based on criteria like CPU utilization, throughput, and turnaround time. Selecting the appropriate scheduling algorithm is vital as different algorithms excel in different scenarios, such as Round Robin for time-sharing systems and Shortest Job First for batch processing. Deadlocks can occur when processes wait indefinitely for resources, and managing them involves prevention, detection, and recovery strategies.

Uploaded by

ishi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

CPU Scheduling: Performance criteria

CPU scheduling is essential for the system’s performance and ensures


that processes are executed correctly and on time. Different CPU
scheduling algorithms have other properties and the choice of a particular
algorithm depends on various factors. Many criteria have been suggested
for comparing CPU scheduling algorithms.

What is CPU scheduling?

CPU Scheduling is a process that allows one process to use the CPU while
another process is delayed due to unavailability of any resources such as I
/ O etc, thus making full use of the CPU. In short, CPU scheduling decides
the order and priority of the processes to run and allocates the CPU time
based on various parameters such as CPU usage, throughput, turnaround,
waiting time, and response time. The purpose of CPU Scheduling is to
make the system more efficient, faster, and fairer.

Criteria of CPU Scheduling

CPU scheduling criteria, such as turnaround time, waiting time, and


throughput, are essential metrics used to evaluate the efficiency of
scheduling algorithms.

1. CPU utilization

The main objective of any CPU scheduling algorithm is to keep the CPU as
busy as possible. Theoretically, CPU utilization can range from 0 to 100
but in a real-time system, it varies from 40 to 90 percent depending on
the load upon the system.

2. Throughput

A measure of the work done by the CPU is the number of processes being
executed and completed per unit of time. This is called throughput. The
throughput may vary depending on the length or duration of the
processes.
CPU Scheduling Criteria

3. Turnaround Time

For a particular process, an important criterion is how long it takes to


execute that process. The time elapsed from the time of submission of a
process to the time of completion is known as the turnaround time. Turn-
around time is the sum of times spent waiting to get into memory, waiting
in the ready queue, executing in CPU, and waiting for I/O.

Turn Around Time = Completion Time – Arrival Time.

4. Waiting Time

A scheduling algorithm does not affect the time required to complete the
process once it starts execution. It only affects the waiting time of a
process i.e. time spent by a process waiting in the ready queue.

Waiting Time = Turnaround Time – Burst Time.

5. Response Time

In an interactive system, turn-around time is not the best criterion. A


process may produce some output fairly early and continue computing
new results while previous results are being output to the user. Thus
another criterion is the time taken from submission of the process of the
request until the first response is produced. This measure is called
response time.

Response Time = CPU Allocation Time(when the CPU was allocated for the
first) – Arrival Time

6. Completion Time
The completion time is the time when the process stops executing, which
means that the process has completed its burst time and is completely
executed.

7. Priority

If the operating system assigns priorities to processes, the scheduling


mechanism should favor the higher-priority processes.

8. Predictability

A given process always should run in about the same amount of time
under a similar system load.

Importance of Selecting the Right CPU Scheduling Algorithm for


Specific Situations

It is important to choose the correct CPU scheduling algorithm because


different algorithms have different priorities for different CPU scheduling
criteria.Different algorithms have different strengths and weaknesses.
Choosing the wrong CPU scheduling algorithm in a given situation can
result in suboptimal performance of the system.

Example: Here are some examples of CPU scheduling algorithms that


work well in different situations.

Round Robin scheduling algorithm works well in a time-sharing system


where tasks have to be completed in a short period of time. SJF scheduling
algorithm works best in a batch processing system where shorter jobs
have to be completed first in order to increase throughput.Priority
scheduling algorithm works better in a real-time system where certain
tasks have to be prioritized so that they can be completed in a timely
manner.

Factors Influencing CPU Scheduling Algorithms

There are many factors that influence the choice of CPU scheduling
algorithm. Some of them are listed below.

 The number of processes.

 The processing time required.

 The urgency of tasks.

 The system requirements.

Selecting the correct algorithm will ensure that the system will use system
resources efficiently, increase productivity, and improve user satisfaction.

CPU Scheduling Algorithms


There are several CPU Scheduling Algorithms, that are listed below.

 First Come First Served (FCFS)

 Shortest Job First (SJF)

 Longest Job First (LJF)

 Priority Scheduling

 Round Robin (RR)

 Shortest Remaining Time First (SRTF)

 Longest Remaining Time First (LRTF)

Conclusion

In Conclusion, CPU scheduling criteria play an important role in improving


system performance. CPU scheduling techniques encourage efficient use
of system resource and effective task processing by analysing and
prioritising criteria such as CPU Utilization, Throughput, Turnaround Time,
Waiting Time, and Response Time. Selecting the appropriate algorithm for
a given situation is crucial for increasing system efficiency and production.

Question for Practice

Which of the following process scheduling algorithm may lead to


starvation?

(A) FIFO

(B) Round Robin

(C) Shortest Job Next

(D) None of the above

Correct option is (C)


Explanation: Shortest job next may lead to process starvation for
processes which will require
a long time to complete if short processes are continually added.

Frequently Asked Question on CPU Scheduling Criteria – FAQs

How does CPU utilization affect scheduling algorithms?

CPU utilization indicates the efficiency of utilizing the CPU’s processing


power. Scheduling algorithms aim to keep the CPU as busy as possible to
achieve high utilization. However, excessively high CPU utilization can
lead to poor system responsiveness and potential resource contention.

What is throughput in the context of scheduling algorithms?


Throughput refers to the number of processes that are completed and
leave the system within a given time frame. Scheduling algorithms that
maximize throughput often prioritize short processes or those that require
minimal CPU time, allowing more processes to be completed in a given
period.

Why is turnaround time an important criterion for scheduling


algorithms?

Turnaround time measures the overall time a process takes to complete,


from submission to termination. Lower turnaround time indicates efficient
process execution. Scheduling algorithms that minimize turnaround time
generally prioritize processes with shorter burst times or high priority.

What trade-offs are involved in selecting a scheduling algorithm?


Some trade-off may include that the improving in throughput may lead to
increment in waiting time.

Deadlock System model

Overview :
A deadlock occurs when a set of processes is stalled because each
process is holding a resource and waiting for another process to acquire
another resource. In the diagram below, for example, Process 1 is holding
Resource 1 while Process 2 acquires Resource 2, and Process 2 is waiting
for Resource 1.
System Model :

 For the purposes of deadlock discussion, a system can be modelled


as a collection of limited resources that can be divided into different
categories and allocated to a variety of processes, each with
different requirements.

 Memory, printers, CPUs, open files, tape drives, CD-ROMs, and other
resources are examples of resource categories.

 By definition, all resources within a category are equivalent, and any


of the resources within that category can equally satisfy a request
from that category. If this is not the case (i.e. if there is some
difference between the resources within a category), then that
category must be subdivided further. For example, the term
“printers” may need to be subdivided into “laser printers” and
“colour inkjet printers.”

 Some categories may only have one resource.

 The kernel keeps track of which resources are free and which are
allocated, to which process they are allocated, and a queue of
processes waiting for this resource to become available for all
kernel-managed resources. Mutexes or wait() and signal() calls can
be used to control application-managed resources (i.e. binary or
counting semaphores. )

 When every process in a set is waiting for a resource that is


currently assigned to another process in the set, the set is said to be
deadlocked.

Operations :
In normal operation, a process must request a resource before using it and
release it when finished, as shown below.

1. Request –
If the request cannot be granted immediately, the process must wait
until the resource(s) required to become available. The system, for
example, uses the functions open(), malloc(), new(), and request ().

2. Use –
The process makes use of the resource, such as printing to a printer
or reading from a file.

3. Release –
The process relinquishes the resource, allowing it to be used by
other processes.

Necessary Conditions :
There are four conditions that must be met in order to achieve deadlock
as follows.

1. Mutual Exclusion –
At least one resource must be kept in a non-shareable state; if
another process requests it, it must wait for it to be released.

2. Hold and Wait –


A process must hold at least one resource while also waiting for at
least one resource that another process is currently holding.

3. No pre-emption –
Once a process holds a resource (i.e. after its request is granted),
that resource cannot be taken away from that process until the
process voluntarily releases it.

4. Circular Wait –
There must be a set of processes P0, P1, P2,…, PN such that every
P[I] is waiting for P[(I + 1) percent (N + 1)]. (It is important to note
that this condition implies the hold-and-wait condition, but dealing
with the four conditions is easier if they are considered separately).

Methods for Handling Deadlocks :


In general, there are three approaches to dealing with deadlocks as
follows.

1. Preventing or avoiding deadlock by Avoid allowing the system to


become stuck in a loop.

2. Detection and recovery of deadlocks, When deadlocks are detected,


abort the process or preempt some resources.

3. Ignore the problem entirely.

4. To avoid deadlocks, the system requires more information about all


processes. The system, in particular, must understand what
resources a process will or may request in the future. ( Depending
on the algorithm, this can range from a simple worst-case maximum
to a complete resource request and release plan for each process. )

5. Deadlock detection is relatively simple, but deadlock recovery


necessitates either aborting processes or preempting resources,
neither of which is an appealing option.

6. If deadlocks are not avoided or detected, the system will gradually


slow down as more processes become stuck waiting for resources
that the deadlock has blocked and other waiting processes.
Unfortunately, when the computing requirements of a real-time
process are high, this slowdown can be confused with a general
system slowdown.

Deadlock Prevention :
Deadlocks can be avoided by avoiding at least one of the four necessary
conditions: as follows.

Condition-1 :
Mutual Exclusion :

 Read-only files, for example, do not cause deadlocks.

 Unfortunately, some resources, such as printers and tape drives,


require a single process to have exclusive access to them.

Condition-2 :
Hold and Wait :
To avoid this condition, processes must be prevented from holding one or
more resources while also waiting for one or more others. There are a few
possibilities here:
 Make it a requirement that all processes request all resources at the
same time. This can be a waste of system resources if a process
requires one resource early in its execution but does not require
another until much later.

 Processes that hold resources must release them prior to requesting


new ones, and then re-acquire the released resources alongside the
new ones in a single new request. This can be a problem if a process
uses a resource to partially complete an operation and then fails to
re-allocate it after it is released.

 If a process necessitates the use of one or more popular resources,


either of the methods described above can result in starvation.

Condition-3 :
No Preemption :
When possible, preemption of process resource allocations can help to
avoid deadlocks.

 One approach is that if a process is forced to wait when requesting a


new resource, all other resources previously held by this process are
implicitly released (preempted), forcing this process to re-acquire
the old resources alongside the new resources in a single request,
as discussed previously.

 Another approach is that when a resource is requested, and it is not


available, the system looks to see what other processes are
currently using those resources and are themselves blocked while
waiting for another resource. If such a process is discovered, some
of their resources may be preempted and added to the list of
resources that the process is looking for.

 Either of these approaches may be appropriate for resources whose


states can be easily saved and restored, such as registers and
memory, but they are generally inapplicable to other devices, such
as printers and tape drives.

Condition-4 :
Circular Wait :

 To avoid circular waits, number all resources and insist that


processes request resources is strictly increasing ( or decreasing)
order.

 To put it another way, before requesting resource Rj, a process must


first release all Ri such that I >= j.
 The relative ordering of the various resources is a significant
challenge in this scheme.

Deadlock Avoidance :

 The general idea behind deadlock avoidance is to avoid deadlocks


by avoiding at least one of the aforementioned conditions.

 This necessitates more information about each process AND results


in low device utilization. (This is a conservative approach.)

 The scheduler only needs to know the maximum number of each


resource that a process could potentially use in some algorithms. In
more complex algorithms, the scheduler can also use the schedule
to determine which resources are required and in what order.

 When a scheduler determines that starting a process or granting


resource requests will result in future deadlocks, the process is
simply not started or the request is denied.

 The number of available and allocated resources, as well as the


maximum requirements of all processes in the system, define a
resource allocation state.

Deadlock Detection :

 If deadlocks cannot be avoided, another approach is to detect them


and recover in some way.

 Aside from the performance hit of constantly checking for


deadlocks, a policy/algorithm for recovering from deadlocks must be
in place, and when processes must be aborted or have their
resources preempted, there is the possibility of lost work.

Recovery From Deadlock :


There are three basic approaches to getting out of a bind:

1. Inform the system operator and give him/her permission to


intervene manually.

2. Stop one or more of the processes involved in the deadlock.

3. Prevent the use of resources.

Approach of Recovery From Deadlock :


Here, we will discuss the approach of Recovery From Deadlock as follows.

Approach-1 :
Process Termination :
There are two basic approaches for recovering resources allocated to
terminated processes as follows.
1. Stop all processes that are involved in the deadlock. This does break
the deadlock, but at the expense of terminating more processes
than are absolutely necessary.

2. Processes should be terminated one at a time until the deadlock is


broken. This method is more conservative, but it necessitates
performing deadlock detection after each step.

In the latter case, many factors can influence which processes are
terminated next as follows.

1. Priorities in the process

2. How long has the process been running and how close it is to
completion.

3. How many and what kind of resources does the process have? (Are
they simple to anticipate and restore? )

4. How many more resources are required for the process to be


completed?

5. How many processes will have to be killed?

6. Whether the process is batch or interactive.

Approach-2 :
Resource Preemption :
When allocating resources to break the deadlock, three critical issues
must be addressed:

1. Selecting a victim –
Many of the decision criteria outlined above apply to determine
which resources to preempt from which processes.

2. Rollback –
A preempted process should ideally be rolled back to a safe state
before the point at which that resource was originally assigned to
the process. Unfortunately, determining such a safe state can be
difficult or impossible, so the only safe rollback is to start from the
beginning. (In other words, halt and restart the process.)

3. Starvation –
How do you ensure that a process does not go hungry because its
resources are constantly being preempted? One option is to use a
priority system and raise the priority of a process whenever its
resources are preempted. It should eventually gain a high enough
priority that it will no longer be preempted.
Memory Management

Paged Segmentation and Segmented Paging

INTRODUCTION:

Paged Segmentation and Segmented Paging are two different memory


management techniques that combine the benefits of paging and
segmentation.

1. Paged Segmentation is a memory management technique that


divides a process’s address space into segments and then divides
each segment into pages. This allows for a flexible allocation of
memory, where each segment can have a different size, and each
page can have a different size within a segment.

2. Segmented Paging, on the other hand, is a memory management


technique that divides the physical memory into pages, and then
maps each logical address used by a process to a physical page. In
this approach, segments are used to map virtual memory addresses
to physical memory addresses, rather than dividing the virtual
memory into pages.

3. Both Paged Segmentation and Segmented Paging provide the


benefits of paging, such as improved memory utilization, reduced
fragmentation, and increased performance. They also provide the
benefits of segmentation, such as increased flexibility in memory
allocation, improved protection and security, and reduced overhead
in memory management.

However, both techniques can also introduce additional complexity and


overhead in the memory management process. The choice between
Paged Segmentation and Segmented Paging depends on the specific
requirements and constraints of a system, and often requires trade-offs
between flexibility, performance, and overhead.

Major Limitation of Single Level Paging


A big challenge with single level paging is that if the logical address space
is large, then the page table may take up a lot of space in main memory.
For instance, consider that logical address is 32 bit and each page is 4 KB,
the number of pages will be 2^20 pages. The page table without
additional bits will be of the size 20 bits * 2 20 or 2.5 MB. Since each
process has its own page table, a lot of memory will be consumed when
single level paging is used. For a system with 64-bit logical address even a
page table of single process will not fit in main memory. For a process with
a large logical address space, a lot of its page table entries are invalid as a
lot of the logical address space goes unused.
Page table with invalid entries

Segmented Paging
A solution to the problem is to use segmentation along with paging to
reduce the size of page table. Traditionally, a program is divided into four
segments, namely code segment, data segment, stack segment and heap
segment.

Segments of a process

The size of the page table can be reduced by creating a page table for
each segment. To accomplish this hardware support is required. The
address provided by CPU will now be partitioned into segment no., page
no. and offset.
The memory management unit (MMU) will use the segment table which
will contain the address of page table(base) and limit. The page table will
point to the page frames of the segments in main memory.

Segmented Paging

Advantages of Segmented Paging

1. The page table size is reduced as pages are present only for data of
segments, hence reducing the memory requirements.

2. Gives a programmers view along with the advantages of paging.

3. Reduces external fragmentation in comparison with segmentation.

4. Since the entire segment need not be swapped out, the swapping
out into virtual memory becomes easier .

Disadvantages of Segmented Paging

1. Internal fragmentation still exists in pages.


2. Extra hardware is required

3. Translation becomes more sequential increasing the memory access


time.

4. External fragmentation occurs because of varying sizes of page


tables and varying sizes of segment tables in today’s systems.

Paged Segmentation

1. In segmented paging, not every process has the same number of


segments and the segment tables can be large in size which will
cause external fragmentation due to the varying segment table
sizes. To solve this problem, we use paged segmentation which
requires the segment table to be paged. The logical address
generated by the CPU will now consist of page no #1, segment no,
page no #2 and offset.

2. The page table even with segmented paging can have a lot of
invalid pages. Instead of using multi level paging along with
segmented paging, the problem of larger page table can be solved
by directly applying multi level paging instead of segmented paging.
Paged Segmentation

Advantages of Paged Segmentation

1. No external fragmentation

2. Reduced memory requirements as no. of pages limited to segment


size.

3. Page table size is smaller just like segmented paging,

4. Similar to segmented paging, the entire segment need not be


swapped out.

5. Increased flexibility in memory allocation: Paged Segmentation


allows for a flexible allocation of memory, where each segment can
have a different size, and each page can have a different size within
a segment.
6. Improved protection and security: Paged Segmentation provides
better protection and security by isolating each segment and its
pages, preventing a single segment from affecting the entire
process’s memory.
Increased program structure: Paged Segmentation provides a
natural program structure, with each segment representing a
different logical part of a program.

7. Improved error detection and recovery: Paged Segmentation


enables the detection of memory errors and the recovery of
individual segments, rather than the entire process’s memory.

8. Reduced overhead in memory management: Paged Segmentation


reduces the overhead in memory management by eliminating the
need to maintain a single, large page table for the entire process’s
memory.

9. Improved memory utilization: Paged Segmentation can improve


memory utilization by reducing fragmentation and allowing for the
allocation of larger blocks of contiguous memory to each segment.

Disadvantages of Paged Segmentation

1. Internal fragmentation remains a problem.

2. Hardware is complexer than segmented paging.

3. Extra level of paging at first stage adds to the delay in memory


access.

4. Increased complexity in memory management: Paged Segmentation


introduces additional complexity in the memory management
process, as it requires the maintenance of multiple page tables for
each segment, rather than a single page table for the entire
process’s memory.

5. Increased overhead in memory access: Paged Segmentation


introduces additional overhead in memory access, as it requires
multiple lookups in multiple page tables to access a single memory
location.

6. Reduced performance: Paged Segmentation can result in reduced


performance, as the additional overhead in memory management
and access can slow down the overall process.

7. Increased storage overhead: Paged Segmentation requires


additional storage overhead, as it requires additional data structures
to store the multiple page tables for each segment.
8. Increased code size: Paged Segmentation can result in increased
code size, as the additional code required to manage the multiple
page tables can take up valuable memory space.

9. Reduced address space: Paged Segmentation can result in a


reduced address space, as some of the available memory must be
reserved for the storage of the multiple page tables.

REFERENCE:

Some popular books on Operating Systems that discuss Paged


Segmentation include:

1. Operating System Concepts by Abraham Silberschatz, Peter Baer


Galvin, and Greg Gagne

2. Modern Operating Systems by Andrew S. Tanenbaum

3. Operating Systems: A Design-Oriented Approach by Charles Crowley

4. Understanding the Linux Kernel by Daniel P. Bovet and Marco Cesate

5. Operating Systems: Principles and Practice by Thomas Anderson


and Michael Dahlin.
These books provide a comprehensive discussion of Paged
Segmentation and its related concepts, as well as practical
examples and implementation details. They are considered essential
reading for anyone interested in the study of operating systems and
memory management techniques.

Allocation of frames in Operating System

An important aspect of operating systems, virtual memory is implemented


using demand paging. Demand paging necessitates the development of
a page-replacement algorithm and a frame allocation algorithm. Frame
allocation algorithms are used if you have multiple processes; it helps
decide how many frames to allocate to each process.

There are various constraints to the strategies for the allocation of frames:

 You cannot allocate more than the total number of available frames.

 At least a minimum number of frames should be allocated to each


process. This constraint is supported by two reasons. The first
reason is, as less number of frames are allocated, there is an
increase in the page fault ratio, decreasing the performance of the
execution of the process. Secondly, there should be enough frames
to hold all the different pages that any single instruction can
reference.

Frame allocation algorithms –


The two algorithms commonly used to allocate frames to a process are:

1. Equal allocation: In a system with x frames and y processes, each


process gets equal number of frames, i.e. x/y. For instance, if the
system has 48 frames and 9 processes, each process will get 5
frames. The three frames which are not allocated to any process can
be used as a free-frame buffer pool.

 Disadvantage: In systems with processes of varying sizes, it


does not make much sense to give each process equal frames.
Allocation of a large number of frames to a small process will
eventually lead to the wastage of a large number of allocated
unused frames.

2. Proportional allocation: Frames are allocated to each process


according to the process size.
For a process pi of size si, the number of allocated frames is ai =
(si/S)*m, where S is the sum of the sizes of all the processes and m
is the number of frames in the system. For instance, in a system
with 62 frames, if there is a process of 10KB and another process of
127KB, then the first process will be allocated (10/137)*62 = 4
frames and the other process will get (127/137)*62 = 57 frames.

 Advantage: All the processes share the available frames


according to their needs, rather than equally.

Global vs Local Allocation –


The number of frames allocated to a process can also dynamically change
depending on whether you have used global replacement or local
replacement for replacing pages in case of a page fault.

1. Local replacement: When a process needs a page which is not in


the memory, it can bring in the new page and allocate it a frame
from its own set of allocated frames only.

 Advantage: The pages in memory for a particular process


and the page fault ratio is affected by the paging behavior of
only that process.

 Disadvantage: A low priority process may hinder a high


priority process by not making its frames available to the high
priority process.
2. Global replacement: When a process needs a page which is not in
the memory, it can bring in the new page and allocate it a frame
from the set of all frames, even if that frame is currently allocated to
some other process; that is, one process can take a frame from
another.

 Advantage: Does not hinder the performance of processes


and hence results in greater system throughput.

 Disadvantage: The page fault ratio of a process can not be


solely controlled by the process itself. The pages in memory
for a process depends on the paging behaviour of other
processes as well.

Cache Memory

Cache memory is a special type of high-speed memory located close to


the CPU in a computer. It stores frequently used data and instructions, So
that the CPU can access them quickly, improving the overall speed and
efficiency of the computer.

It is a faster and smaller segment of memory whose access time is as


close as registers. In a hierarchy of memory, cache memory has access
time lesser than primary memory. Generally, cache memory is used as a
buffer.

In this article we will see cache memory in detail.

What is Cache Memory?

Data in primary memory can be accessed faster than secondary memory


but still, access times of primary memory are generally in a few
microseconds, whereas the CPU is capable of performing operations in
nanoseconds. Due to the time lag between accessing data and acting on
data performance of the system decreases as the CPU is not utilized
properly, it may remain idle for some time. In order to minimize this time
gap new segment of memory is Introduced known as Cache Memory.

It is based on principle of locality of reference, which refers to the


observation that program tries to access a relatively small portion of their
address space at any given time, and repeatedly tries to access some
portion of the memory. For ex: In fees department of your college,
transactions are accessed frequently to check on the dues.

Key Features of Cache Memory


1. Speed: Faster than the main memory (RAM), which helps the CPU
retrieve data more quickly.

2. Proximity: Located very close to the CPU, often on the CPU chip
itself, reducing data access time.

3. Function: Temporarily holds data and instructions that the CPU is


likely to use again soon, minimizing the need to access the slower
main memory.

Role of Cache Memory

The role of cache memory is explained below,

 Cache memory plays a crucial role in computer systems.

 It provide faster access.

 It acts buffer between CPU and main memory(RAM).

 Primary role of it is to reduce average time taken to access data,


thereby improving overall system performance.

Benefits of Cache Memory

Various benefits of the cache memory are,

1. Faster access: Faster than main memory. It resides closer to CPU ,


typically on same chip or in close proximity. Cache stores subset of
data and instruction.

2. Reducing memory latency: Memory access latency refers to time


taken for processes to retrieve data from memory. Caches are
designed to exploit principle of locality.

3. Lowering bus traffic: Accessing data from main memory involves


transferring it over system bus. Bus is shared resource and
excessive traffic can lead to congestion and slower data transfers.
By utilizing cache memory , processor can reduce frequency of
accessing main memory resulting in less bus traffic and improves
system efficiency.

4. Increasing effective CPU utilization: Cache memory allows CPU


to operate at a higher effective speed. CPU can spend more time
executing instruction rather than waiting for memory access. This
leads to better utilization of CPU’s processing capabilities and higher
overall system performance.

5. Enhancing system scalability: Cache memory helps improve


system scalability by reducing impact of memory latency on overall
system performance.
Working of Cache Memory

In order to understand the working of cache we must understand few


points:

 Cache memory is faster, they can be accessed very fast

 Cache memory is smaller, a large amount of data cannot be stored

Whenever CPU needs any data it searches for corresponding data in the
cache (fast process) if data is found, it processes the data according to
instructions, however, if data is not found in the cache CPU search for that
data in primary memory(slower process) and loads it into the cache. This
ensures frequently accessed data are always found in the cache and
hence minimizes the time required to access the data.

How does Cache Memory Improve CPU Performance?

Cache memory improves CPU performance by reducing the time it takes


for the CPU to access data. By storing frequently accessed data closer to
the CPU, it minimizes the need for the CPU to fetch data from the slower
main memory.

What is a Cache Hit and a Cache Miss?

Cache Hit: When the CPU finds the required data in the cache memory,
allowing for quick access.On searching in the cache if data is found, a
cache hit has occurred.

Cache Miss: When the required data is not found in the cache, forcing
the CPU to retrieve it from the slower main memory.On searching in the
cache if data is not found, a cache miss has occurred

Performance of cache is measured by the number of cache hits to the


number of searches. This parameter of measuring performance is known
as the Hit Ratio.

Hit ratio=(Number of cache hits)/(Number of searches)

Types of Cache Memory

1. L1 or Level 1 Cache: It is the first level of cache memory that is


present inside the processor. It is present in a small amount inside
every core of the processor separately. The size of this memory
ranges from 2KB to 64 KB.

2. L2 or Level 2 Cache: It is the second level of cache memory that


may present inside or outside the CPU. If not present inside the
core, It can be shared between two cores depending upon the
architecture and is connected to a processor with the high-speed
bus. The size of memory ranges from 256 KB to 512 KB.

3. L3 or Level 3 Cache: It is the third level of cache memory that is


present outside the CPU and is shared by all the cores of the CPU.
Some high processors may have this cache. This cache is used to
increase the performance of the L2 and L1 cache. The size of this
memory ranges from 1 MB to 8MB.

Difference Between Cache and RAM

Although Cache and RAM both are used to increase the performance of
the system there exists a lot of differences in which they operate to
increase the efficiency of the system.

RAM (Random Access


Feature Cache Memory Memory)

Connected to the CPU via


Location Located close to the CPU.
the memory bus.

Serves as the main


Stores frequently accessed
Purpose working memory for the
data and instructions.
CPU.

Fast, but slower than


Very fast, with access times cache memory, with
Speed
in nanoseconds. access times in tens of
nanoseconds.

Smaller in size, typically Larger in size, ranging


Size measured in kilobytes (KB) from gigabytes (GB) to
to a few megabytes (MB). terabytes (TB).

Uses SRAM (Static RAM), Uses DRAM (Dynamic


Type of
which is faster but more RAM), which is slower but
Memory
expensive. more cost-effective.

Accessibilit Extremely fast access times Slightly slower access


RAM (Random Access
Feature Cache Memory Memory)

times compared to cache


y due to proximity to the CPU.
memory.

More expensive per unit of Less expensive per unit of


Cost memory due to its speed memory compared to
and proximity to the CPU. cache memory.

Typically organized into


Single level, serving as the
multiple levels (L1, L2, L3),
Hierarchy primary working memory
with each level increasing in
for the CPU.
size and latency.

Acts as a buffer between the Used for storing data and


CPU and main memory instructions currently
Usage
(RAM), speeding up data being processed by the
access. CPU.

Larger capacity, providing


Limited capacity due to its
ample storage space for
Capacity small size and high-speed
running applications and
nature.
processes.

Conclusion

In conclusion, cache memory plays an important role in enhancing the


speed and efficiency of computer systems. By storing frequently accessed
data and instructions close to the CPU, cache memory minimizes the time
required for the CPU to access information, thereby reducing latency and
improving overall system performance.

Frequently Asked Questions on Cache Memory – FAQ’s

Why is cache memory faster than main memory?

Cache memory is faster than main memory because it uses high-speed


static RAM (SRAM) rather than the slower dynamic RAM (DRAM) used in
main memory. Its proximity to the CPU also reduces the time needed to
access data.

Can cache memory be upgraded?

Cache memory is typically built into the CPU and cannot be upgraded
separately. Upgrading the CPU can increase the amount and speed of
cache memory available.

What happens if the cache memory is full?

When the cache memory is full, it uses algorithms like Least Recently
Used (LRU) to replace old data with new data. The least recently accessed
data is removed to make space for the new data.

Why is multi-level cache used in modern CPUs?

Multi-level caches are used to balance speed and cost. L1 cache is the
f.astest and most expensive per byte, so it’s small. L2 and L3 caches are
progressively larger and slower, providing a larger total cache size while
managing costs and maintaining reasonable speed.

Memory Management in Operating System

The term memory can be defined as a collection of data in a specific


format. It is used to store instructions and process data. The memory
comprises a large array or group of words or bytes, each with its own
location. The primary purpose of a computer system is to execute
programs. These programs, along with the information they access,
should be in the main memory during execution. The CPU fetches
instructions from memory according to the value of the program counter.

To achieve a degree of multiprogramming and proper utilization of


memory, memory management is important. Many memory management
methods exist, reflecting various approaches, and the effectiveness of
each algorithm depends on the situation.

What is Main Memory?

The main memory is central to the operation of a Modern Computer. Main


Memory is a large array of words or bytes, ranging in size from hundreds
of thousands to billions. Main memory is a repository of rapidly available
information shared by the CPU and I/O devices. Main memory is the place
where programs and information are kept when the processor is
effectively utilizing them. Main memory is associated with the processor,
so moving instructions and information into and out of the processor is
extremely fast. Main memory is also known as RAM (Random Access
Memory). This memory is volatile. RAM loses its data when a power
interruption occurs.

Main Memory

What is Memory Management?

Memory management mostly involves management of main memory. In a


multiprogramming computer, the Operating System resides in a part of
the main memory, and the rest is used by multiple processes. The task of
subdividing the memory among different processes is called Memory
Management. Memory management is a method in the operating system
to manage operations between main memory and disk during process
execution. The main aim of memory management is to achieve efficient
utilization of memory.

Why Memory Management is Required?

 Allocate and de-allocate memory before and after process


execution.
 To keep track of used memory space by processes.

 To minimize fragmentation issues.

 To proper utilization of main memory.

 To maintain data integrity while executing of process.

read more about – Requirements of Memory Management System

Now we are discussing the concept of Logical Address Space and Physical
Address Space

Logical and Physical Address Space

 Logical Address Space: An address generated by the CPU is


known as a “Logical Address”. It is also known as a Virtual
address. Logical address space can be defined as the size of the
process. A logical address can be changed.

 Physical Address Space: An address seen by the memory unit


(i.e. the one loaded into the memory address register of the
memory) is commonly known as a “Physical Address”. A Physical
address is also known as a Real address. The set of all physical
addresses corresponding to these logical addresses is known as
Physical address space. A physical address is computed by MMU.
The run-time mapping from virtual to physical addresses is done by
a hardware device Memory Management Unit(MMU). The physical
address always remains constant.

Static and Dynamic Loading

Loading a process into the main memory is done by a loader. There are
two different types of loading :

 Static Loading: Static Loading is basically loading the entire


program into a fixed address. It requires more memory space.

 Dynamic Loading: The entire program and all data of a process


must be in physical memory for the process to execute. So, the size
of a process is limited to the size of physical memory. To gain proper
memory utilization, dynamic loading is used. In dynamic loading, a
routine is not loaded until it is called. All routines are residing on
disk in a relocatable load format. One of the advantages of dynamic
loading is that the unused routine is never loaded. This loading is
useful when a large amount of code is needed to handle it
efficiently.

Static and Dynamic Linking


To perform a linking task a linker is used. A linker is a program that takes
one or more object files generated by a compiler and combines them into
a single executable file.

 Static Linking: In static linking, the linker combines all necessary


program modules into a single executable program. So there is no
runtime dependency. Some operating systems support only static
linking, in which system language libraries are treated like any other
object module.

 Dynamic Linking: The basic concept of dynamic linking is similar


to dynamic loading. In dynamic linking, “Stub” is included for each
appropriate library routine reference. A stub is a small piece of code.
When the stub is executed, it checks whether the needed routine is
already in memory or not. If not available then the program loads
the routine into memory.

Swapping

When a process is executed it must have resided in memory. Swapping is


a process of swapping a process temporarily into a secondary memory
from the main memory, which is fast compared to secondary memory. A
swapping allows more processes to be run and can be fit into memory at
one time. The main part of swapping is transferred time and the total time
is directly proportional to the amount of memory swapped. Swapping is
also known as roll-out, or roll because if a higher priority process arrives
and wants service, the memory manager can swap out the lower priority
process and then load and execute the higher priority process. After
finishing higher priority work, the lower priority process swapped back in
memory and continued to the execution process.
swapping in memory management

Memory Management Techniques

Memory management techniques are methods used by an operating


system to efficiently allocate, utilize, and manage memory resources for
processes. These techniques ensure smooth execution of programs and
optimal use of system memory

Different Memory Management techniques are:

Memory Management with Monoprogramming (Without


Swapping)
This is the simplest memory management approach the memory is
divided into two sections:

 One part of the operating system

 The second part of the user program

Fence Register

operating user
system program

 In this approach, the operating system keeps track of the first and
last location available for the allocation of the user program

 The operating system is loaded either at the bottom or at top

 Interrupt vectors are often loaded in low memory therefore, it makes


sense to load the operating system in low memory

 Sharing of data and code does not make much sense in a single
process environment

 The Operating system can be protected from user programs with the
help of a fence register.

Multiprogramming with Fixed Partitions (Without Swapping)

 A memory partition scheme with a fixed number of partitions was


introduced to support multiprogramming. this scheme is based on
contiguous allocation

 Each partition is a block of contiguous memory

 Memory is partitioned into a fixed number of partitions.

 Each partition is of fixed size

Example: As shown in fig. memory is partitioned into 5 regions the region


is reserved for updating the system the remaining four partitions are for
the user program.

Fixed Size Partitioning


Operating
System

p1

p2

p3

p4

Partition Table

Once partitions are defined operating system keeps track of the status of
memory partitions it is done through a data structure called a partition
table.

Sample Partition Table

Starting Address of Size of


Partition Partition Status

allocate
0k 200k
d

200k 100k free

300k 150k free

allocate
450k 250k
d

Logical vs Physical Address

An address generated by the CPU is commonly referred to as a logical


address. the address seen by the memory unit is known as the physical
address. The logical address can be mapped to a physical address by
hardware with the help of a base register this is known as dynamic
relocation of memory references.

Contiguous Memory Allocation

Contiguous memory allocation is a memory management method where


each process is given a single, continuous block of memory. This means all
the data for a process is stored in adjacent memory locations.

Partition Allocation Methods

To gain proper memory utilization, memory allocation must be allocated


efficient manner. One of the simplest methods for allocating memory is to
divide memory into several fixed-sized partitions and each partition
contains exactly one process. Thus, the degree of multiprogramming is
obtained by the number of partitions.

 Fixed partition allocation: Memory is divided into fixed-sized


partitions during system initialization. Each partition can hold only
one process.

 Dynamic Partition Allocation: In this allocation strategy, Memory


is divided into variable-sized partitions based on the size of the
processes.

When it is time to load a process into the main memory and if there is
more than one free block of memory of sufficient size then the OS decides
which free block to allocate.
There are different Placement Algorithm:

1. First Fit

2. Best Fit

3. Worst Fit

4. Next Fit

 read more about – Fixed (or static) Partitioning in Operating System

 read more about – Variable (or Dynamic) Partitioning in Operating


System

 read more about – Partition Allocation Methods in Memory


Management

Non-Contiguous Memory Allocation

Non-contiguous memory allocation is a memory management method


where a process is divided into smaller parts, and these parts are stored in
different, non-adjacent memory locations. This means the entire process
does not need to be stored in one continuous block of memory.

Techniques of Non-Contiguous Memory Allocation are:

 Paging

 Segmentation

read more about – Non-Contiguous Memory Allocation

Fragmentation

Fragmentation is defined as when the process is loaded and removed after


execution from memory, it creates a small free hole. These holes can not
be assigned to new processes because holes are not combined or do not
fulfill the memory requirement of the process. In the operating systems
two types of fragmentation are:

 Internal fragmentation: Internal fragmentation occurs when


memory blocks are allocated to the process more than their
requested size. Due to this some unused space is left over and
creating an internal fragmentation problem. Example: Suppose
there is a fixed partitioning used for memory allocation and the
different sizes of blocks 3MB, 6MB, and 7MB space in memory. Now
a new process p4 of size 2MB comes and demands a block of
memory. It gets a memory block of 3MB but 1MB block of memory is
a waste, and it can not be allocated to other processes too. This is
called internal fragmentation.
 External fragmentation: In External Fragmentation, we have a
free memory block, but we can not assign it to a process because
blocks are not contiguous. Example: Suppose (consider the above
example) three processes p1, p2, and p3 come with sizes 2MB, 4MB,
and 7MB respectively. Now they get memory blocks of size 3MB,
6MB, and 7MB allocated respectively. After allocating the process p1
process and the p2 process left 1MB and 2MB. Suppose a new
process p4 comes and demands a 3MB block of memory, which is
available, but we can not assign it because free memory space is
not contiguous. This is called external fragmentation.

read more about – Fragmentation

Frequently asked Questions on Memory Management in Operating


System – FAQ

What is a memory leak, and how does it affect system


performance?

A memory leak occurs when a program fails to release memory that it no


longer needs, resulting in wasted memory resources. Over time, if
memory leaks accumulate, the system’s available memory diminishes,
leading to reduced performance and possibly system crashes.

Can memory fragmentation be prevented in an operating system?

While it is challenging to completely eliminate memory fragmentation,


certain techniques can help minimize its impact. One approach is to use
memory allocation algorithms that focus on reducing external
fragmentation, such as buddy systems or slab allocation. Additionally,
techniques like compaction can be employed to reduce internal
fragmentation.

What are the advantages and disadvantages of using virtual


memory?

Virtual memory provides several benefits, including the ability to run


larger programs than the available physical memory, increased security
through memory isolation, and simplified memory management for
applications. However, using virtual memory also introduces additional
overhead due to page table lookups and potential performance
degradation if excessive swapping occurs.

Real Storage

Real storage in an operating system is the physical memory of a computer


that stores data. It's also known as central storage or processor storage.

Explanation
 Internal and external storage: Computers have two types of
physical storage: internal and external.

 Volatile and non-volatile storage: Volatile storage loses its


contents when the power is removed, while non-volatile storage
does not.

 Primary storage: This is where documents, images, and other files


are stored on a hard drive or external drive.

 Mass storage: This includes devices with removable and non-


removable media, such as smartphones, computers, enterprise
servers, and data centres.

 Optical storage: This includes compact disks (CDs) and digital


versatile disks (DVDs).

Bare Machine and Resident Monitor

The Bare Machine and Resident Monitor are not directly related to the
operating system but while we study about memory management these
components are really important to study, so let’s study them one by one
and then their working. In this article, we are going to talk about two
important part of the computer system, that is Bare machine and Resident
monitor.

What is Bare Machine?

Bare machine is logical hardware which is used to execute the program in


the processor without using the operating system. As of now, we have
studied that we can’t execute any process without the Operating system.
But yes with the help of the Bare machine we can do that.

Initially, when the operating systems are not developed, the execution of
an instruction is done by directly on hardware without using any
interfering hardware, at that time the only drawback was that the Bare
machines accepting the instruction in only machine language, due to this
those person who has sufficient knowledge about Computer field are able
to operate a computer. so after the development of the operating system
Bare machine is referred to as inefficient.

What is Resident Monitor?


The Resident Monitor is a code that runs on Bare Machines. The resident
monitor works like an operating system that controls the instructions and
performs all necessary functions. It also works like job sequencer because
it also sequences the job and sends them to the processor.

After scheduling the job Resident monitors loads the programs one by one
into the main memory according to their sequences. One most important
factor about the resident monitor is that when the program execution
occurred there is no gap between the program execution and the
processing is going to be faster.

The Resident monitors are divided into 4 parts as:

1. Control Language Interpreter

2. Loader

3. Device Driver

4. Interrupt Processing
Parts of Resident Monitor

 Control Language Interpreter: The first part of the Resident


monitor is control language interpreter which is used to read and
carry out the instruction from one level to the next level.

 Loader: The second part of the Resident monitor which is the main
part of the Resident Monitor is Loader which Loads all the necessary
system and application programs into the main memory.

 Device Driver: The third part of the Resident monitor is Device


Driver which is used to manage the connecting input-output devices
to the system. So basically it is the interface between the user and
the system. it works as an interface between the request and
response. request which user made, Device driver responds that the
system produces to fulfill these requests.

 Interrupt Processing: The fourth part as the name suggests, it


processes the all occurred interrupt to the system.

Conclusion

In conclusion, a Bare machine is a basic model of a computer that focuses


on its essential components and operations, like memory and simple
instructions. It helps us understand fundamental computing concepts
without any extra features. On the other hand, a resident monitor is a
more advanced system that manages the computer’s resources and
allows multiple programs to run efficiently. It handles tasks like memory
allocation and input/output operations, making it easier for users to
interact with the computer.

Frequently Asked Questions on Bare Machine and Resident


Monitor – FAQs

Why is the Bare Machine Important?

The bare machine is important for understanding the fundamental


concepts of computing, like how data is processed and stored, without
distractions from modern features.

What are the Benefits of a Resident Monitor?

A resident monitor allows for efficient multitasking, better resource


management, and smoother user experiences by handling multiple
programs simultaneously.

Are They Used in Real Computers?


The bare machine is mostly a theoretical concept for learning, while
resident monitors are used in operating systems to help manage
computer functions and resources.

Can I Run Programs on a Bare Machine?

No, a bare machine doesn’t support running complex programs directly. It


only shows basic operations. In contrast, a resident monitor allows you to
run and manage multiple programs effectively.

Fixed (or static) Partitioning in Operating System

Fixed partitioning, also known as static partitioning, is one of the earliest


memory management techniques used in operating systems. In this
method, the main memory is divided into a fixed number of partitions at
system startup, and each partition is allocated to a process. These
partitions remain unchanged throughout system operation, ensuring a
simple, predictable memory allocation process. Despite its simplicity, fixed
partitioning has several limitations, such as internal fragmentation and
inflexible handling of varying process sizes. This article delves into the
advantages, disadvantages, and applications of fixed partitioning in
modern operating systems.

What is Fixed (or static) Partitioning in the Operating System?

Fixed (or static) partitioning is one of the earliest and simplest memory
management techniques used in operating systems. It involves dividing
the main memory into a fixed number of partitions at system startup, with
each partition being assigned to a process. These partitions remain
unchanged throughout the system’s operation, providing each process
with a designated memory space. This method was widely used in early
operating systems and remains relevant in specific contexts like
embedded systems and real-time applications. However, while fixed
partitioning is simple to implement, it has significant limitations, including
inefficiencies caused by internal fragmentation.

1. In fixed partitioning, the memory is divided into fixed-size chunks,


with each chunk being reserved for a specific process. When a
process requests memory, the operating system assigns it to the
appropriate partition. Each partition is of the same size, and the
memory allocation is done at system boot time.
2. Fixed partitioning has several advantages over other memory
allocation techniques. First, it is simple and easy to implement.
Second, it is predictable, meaning the operating system can ensure
a minimum amount of memory for each process. Third, it can
prevent processes from interfering with each other’s memory space,
improving the security and stability of the system.

3. However, fixed partitioning also has some disadvantages. It can lead


to internal fragmentation, where memory in a partition remains
unused. This can happen when the process’s memory requirements
are smaller than the partition size, leaving some memory unused.
Additionally, fixed partitioning limits the number of processes that
can run concurrently, as each process requires a dedicated partition.

Overall, fixed partitioning is a useful memory allocation technique in


situations where the number of processes is fixed, and the memory
requirements for each process are known in advance. It is commonly used
in embedded systems, real-time systems, and systems with limited
memory resources.

In operating systems, Memory Management is the function responsible for


allocating and managing a computer’s main memory. Memory
Management function keeps track of the status of each memory location,
either allocated or free to ensure effective and efficient use of Primary
Memory.

There are two Memory Management Techniques:

1. Contiguous

2. Non-Contiguous

Contiguous Memory Allocation:

In contiguous memory allocation, each process is assigned a single


continuous block of memory in the main memory. The entire process is
loaded into one contiguous memory region.

In Contiguous Technique, executing process must be loaded entirely in the


main memory.

Contiguous Technique can be divided into:

 Fixed (or static) partitioning

 Variable (or dynamic) partitioning


Fixed Partitioning:
This is the oldest and simplest technique used to put more than one
process in the main memory. In this partitioning, the number of partitions
(non-overlapping) in RAM is fixed but the size of each partition may
or may not be the same. As it is a contiguous allocation, hence no
spanning is allowed. Here partitions are made before execution or during
system configure.

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 (as spanning is not allowed). Hence, 7MB becomes part of
External Fragmentation.

Advantages of Fixed Partitioning

 Easy to implement: The algorithms required are simple and


straightforward.

 Low overhead: Requires minimal system resources to manage,


ideal for resource-constrained systems.
 Predictable: Memory allocation is predictable, with each process
receiving a fixed partition.

 No external fragmentation: Since the memory is divided into


fixed partitions and no spanning is allowed, external fragmentation
is avoided.

 Suitable for systems with a fixed number of processes: Ideal


for systems where the number of processes and their memory
requirements are known in advance.

 Prevents process interference: Ensures that processes do not


interfere with each other’s memory, improving system stability.

 Efficient memory use: Particularly in systems with fixed, known


processes and batch processing scenarios.

 Good for batch processing: Works well in environments where


the number of processes remains constant over time.

 Better control over memory allocation: The operating system


has clear control over how memory is allocated and managed.

 Easy to debug: Fixed Partitioning is easy to debug since the size


and location of each process are predetermined.

Disadvantages of Fixed Partitioning

1. Internal Fragmentation: Main memory use is inefficient. Any


program, no matter how small, occupies an entire partition. This can
cause internal fragmentation.

2. Limit process size: Process of size greater than the size of the
partition in Main Memory cannot be accommodated. The partition
size cannot be varied according to the size of the incoming process
size. Hence, the process size of 32MB in the above-stated example
is invalid.

3. Limitation on Degree of Multiprogramming: Partitions in Main


Memory are made before execution or during system configure.
Main Memory is divided into a fixed number of partitions. Suppose if
there are partitions in RAM and are the number of processes,
then n2<=n1 n2<=n1 condition must be fulfilled. Number of
processes greater than the number of partitions in RAM is invalid in
Fixed Partitioning.

Clarification:
Internal fragmentation is a notable disadvantage in fixed partitioning,
whereas external fragmentation is not applicable because processes
cannot span across multiple partitions, and memory is allocated in fixed
blocks.

Non-Contiguous Memory Allocation:

In non-contiguous memory allocation, a process is divided into multiple


blocks or segments that can be loaded into different parts of the memory,
rather than requiring a single continuous block.

Key Features:

Divided memory blocks: A process is divided into smaller chunks


(pages, segments) and placed in available memory blocks, which can be
located anywhere in the memory.

Paging and Segmentation:

 Paging: Divides memory into fixed-size blocks called pages. Pages


of a process can be placed in any available memory frames.

 Segmentation: Divides memory into variable-sized segments


based on logical sections of a program, like code, data, and stack.

Conclusion

Fixed partitioning, though straightforward and easy to manage, presents


several challenges, particularly in the form of internal fragmentation and
limited flexibility in handling varying process sizes. This memory allocation
technique works well in environments where memory requirements are
predictable and stable. However, for modern systems with dynamic
workloads and varying memory demands, more flexible techniques like
dynamic partitioning or non-contiguous allocation methods have become
preferable. Nonetheless, understanding fixed partitioning is crucial for
grasping the evolution of memory management in operating systems and
its applications in specialized environments.

Frequently Asked Questions on Fixed Partitioning in OS -FAQs

How does internal fragmentation occur in Fixed Partitioning?

Internal fragmentation occurs when a process’s size is smaller than the


allocated partition. The unused memory within the partition is wasted,
leading to inefficient memory usage.

Why is Fixed Partitioning not widely used in modern systems?


Due to its inflexibility in handling varying process sizes and the
inefficiency caused by internal fragmentation, fixed partitioning is not
suitable for modern systems with dynamic workloads.

How is internal fragmentation different from external


fragmentation in memory management?

Internal fragmentation occurs when allocated memory exceeds the


memory required by a process, leaving unused space within a partition.
External fragmentation, on the other hand, refers to the wasted space
outside of allocated partitions, which is not applicable in fixed partitioning
since partitions are predetermined and cannot span.

Can processes larger than the partition size be accommodated in


Fixed Partitioning?

No, in fixed partitioning, a process larger than the partition size cannot be
accommodated because partitions are of fixed size and cannot
dynamically adjust to a process’s memory requirements.

What types of systems benefit from Fixed Partitioning?

Systems with a fixed number of processes and predictable memory


requirements, such as embedded systems, real-time systems, and batch
processing systems, benefit from fixed partitioning due to its simplicity
and low overhead.

Why does Fixed Partitioning limit the degree of


multiprogramming?

Since the number of partitions in memory is fixed, only a limited number


of processes can be loaded into memory simultaneously. This restricts the
degree of multiprogramming, as processes are confined to the number of
available partitions.

Is Fixed Partitioning still used in modern systems?

While fixed partitioning is not commonly used in modern general-purpose


systems, it still finds use in specialized environments such as embedded
systems, where predictable and stable memory allocation is crucial.

What alternatives to Fixed Partitioning exist for memory


management?

Alternatives include dynamic partitioning, where partition sizes can adjust


to process requirements, and non-contiguous memory allocation methods
like paging and segmentation, which allow processes to be loaded into
non-contiguous memory blocks, reducing fragmentation.
Variable (or Dynamic) Partitioning in Operating System

In operating systems, Memory Management is the function responsible for


allocating and managing a computer’s main memory. The memory
Management function keeps track of the status of each memory location,
either allocated or free to ensure effective and efficient use of Primary
Memory.

Below are Memory Management Techniques.

 Contiguous

 Non-Contiguous

In the Contiguous Technique, the executing process must be loaded


entirely in the main memory. The contiguous Technique can be divided
into.

 Fixed (static) partitioning

 Variable (dynamic) partitioning

What is Variable (Dynamic) Partitioning?

It is a part of the Contiguous allocation technique. It is used to alleviate


the problem faced by Fixed Partitioning. In contrast with fixed partitioning,
partitions are not made before the execution or during system
configuration. Various features associated with variable Partitioning-

 Initially, RAM is empty and partitions are made during the run-time
according to the process’s need instead of partitioning during
system configuration.

 The size of the partition will be equal to the incoming process.

 The partition size varies according to the need of the process so that
internal fragmentation can be avoided to ensure efficient utilization
of RAM.

 The number of partitions in RAM is not fixed and depends on the


number of incoming processes
and the Main Memory’s size.
Advantages of Variable(Dynamic) Partitioning

 No Internal Fragmentation: In variable Partitioning, space in the


main memory is allocated strictly according to the need of the
process, hence there is no case of internal fragmentation. There will
be no unused space left in the partition.

 No restriction on the Degree of Multiprogramming: More


processes can be accommodated due to the absence of internal
fragmentation. A process can be loaded until the memory is empty.

 No Limitation on the Size of the Process: In Fixed partitioning,


the process with a size greater than the size of the largest partition
could not be loaded and the process can not be divided as it is
invalid in the contiguous allocation technique. Here, In variable
partitioning, the process size can’t be restricted since the partition
size is decided according to the process size.

Disadvantages of Variable(Dynamic) Partitioning

 Difficult Implementation: Implementing variable Partitioning is


difficult as compared to Fixed Partitioning as it involves the
allocation of memory during run-time rather than during system
configuration.

 External Fragmentation: There will be external


fragmentation despite the absence of internal fragmentation. For
example, suppose in the above example- process P1(2MB) and
process P3(1MB) completed their execution. Hence two spaces are
left i.e. 2MB and 1MB. Let’s suppose process P5 of size 3MB comes.
The space in memory cannot be allocated as no spanning is allowed
in contiguous allocation. The rule says that the process must be
continuously present in the main memory to get executed. Hence it
results in External Fragmentation.
No Internal Fragmentation

Now P5 of size 3 MB cannot be accommodated despite the required


available space because in contiguous no spanning is allowed.

Key Points On Variable (Dynamic) Partitioning in Operating


Systems

 Variable (or dynamic) partitioning is a memory allocation technique


that allows memory partitions to be created and resized dynamically
as needed.

 The operating system maintains a table of free memory blocks or


holes, each of which represents a potential partition. When a
process requests memory, the operating system searches the table
for a suitable hole that can accommodate the requested amount of
memory.

 Dynamic partitioning reduces internal fragmentation by allocating


memory more efficiently, allows multiple processes to share the
same memory space, and is flexible in accommodating processes
with varying memory requirements.

 However, dynamic partitioning can also lead to external


fragmentation and requires more complex memory
management algorithms, which can make it slower than fixed
partitioning.

 Understanding dynamic partitioning is essential for operating


system design and implementation, as well as for system-level
programming.
FAQs on Dynamic (Variable) Partitioning

Q.1: What is the basic difference between Fixed Partitioning and


Variable Partitioning?

Answer:

Fixed Partitioning helps in creating memory of identical sizes whereas


dynamic partitioning helps in creating memory of variable sizes.

Q.2: Which algorithms work best for Dynamic Partitioning?

Answer:

The Worst Fit Algorithm works best for Dynamic Partitioning.

Q.3: What is Data Partitioning?

Answer:

The process of dividing up data among several tables, drives, or locations


in order to enhance database manageability or query processing speed is
known as data partitioning.

Memory Allocation Techniques | Mapping Virtual Addresses to


Physical Addresses

Memory Allocation Techniques:


To store the data and to manage the processes, we need a large-sized
memory and, at the same time, we need to access the data as fast as
possible. But if we increase the size of memory, the access time will also
increase and, as we know, the CPU always generates addresses for
secondary memory, i.e. logical addresses. But we want to access the main
memory, so we need Address translation of logical address into physical
address.
The main memory interacts with both the user processes and the
operating system. So we need to efficiently use the main memory. Main
memory is divided into non-overlapping memory regions called partitions.

The main memory can be broadly allocated in two ways –

1. Contiguous memory allocation

2. Non-Contiguous memory allocation

Contiguous memory allocation can be categorized into two ways :

1. Fixed partition scheme


2. Variable partition scheme.

Different Partition Allocation methods are used in Contiguous


memory allocations –

1. First Fit

2. Best Fit

3. Worst Fit

4. Next Fit

Non-Contiguous memory allocation can be categorized into many


ways :

1. Paging

2. Multilevel paging

3. Inverted paging

4. Segmentation

5. Segmented paging

MMU(Memory Management Unit) :


The run time mapping between Virtual address and Physical Address is
done by a hardware device known as MMU.
In memory management, the Operating System will handle the processes
and move the processes between disk and memory for execution . It
keeps track of available and used memory.

MMU scheme :

CPU------- MMU------Memory
Dynamic relocation using a relocation register.

1. CPU will generate logical address for eg: 346

2. MMU will generate a relocation register (base register) for eg: 14000

3. In memory, the physical address is located eg:(346+14000= 14346)

The value in the relocation register is added to every address generated


by a user process at the time the address is sent to memory. The user
program never sees the real physical addresses. The program can create
a pointer to location 346, store it in memory, manipulate it, and compare
it with other addresses—all like the number 346.
The user program generates only logical addresses. However, these
logical addresses must be mapped to physical addresses before they are
used.

Address binding :
Address binding is the process of mapping from one address space to
another address space. Logical address is an address generated by the
CPU during execution, whereas Physical Address refers to the location in
the memory unit(the one that is loaded into memory).The logical address
undergoes translation by the MMU or address translation unit in particular.
The output of this process is the appropriate physical address or the
location of code/data in RAM.

An address binding can be done in three different ways :


Compile Time –
If you know that during compile time, where process will reside in
memory, then an absolute address is generated. i.e The physical address
is embedded to the executable of the program during compilation.
Loading the executable as a process in memory is very fast. But if the
generated address space is preoccupied by other processes, then the
program crashes and it becomes necessary to recompile the program to
change the address space.

Load time –
If it is not known at the compile time where the process will reside, then a
relocatable address will be generated. The loader translates the
relocatable address to an absolute address. The base address of the
process in main memory is added to all logical addresses by the loader to
generate an absolute address. In this, if the base address of the process
changes, then we need to reload the process again.

Execution time –
The instructions are in memory and are being processed by the CPU.
Additional memory may be allocated and/or deallocated at this time. This
is used if a process can be moved from one memory to another during
execution(dynamic linking-Linking that is done during load or run time).
e.g – Compaction.
Mapping Virtual Addresses to Physical Addresses :
In Contiguous memory allocation mapping from virtual addresses to
physical addresses is not a difficult task, because if we take a process
from secondary memory and copy it to the main memory, the addresses
will be stored in a contiguous manner, so if we know the base address of
the process, we can find out the next addresses.

The Memory Management Unit is a combination of 2 registers –

1. Base Register (Relocation Register)

2. Limit Register.
Base Register – contains the starting physical address of the process.
Limit Register -mentions the limit relative to the base address on the
region occupied by the process.

The logical address generated by the CPU is first checked by the limit
register, If the value of the logical address generated is less than the
value of the limit register, the base address stored in the relocation
register is added to the logical address to get the physical address of the
memory location.
If the logical address value is greater than the limit register, then the CPU
traps to the OS, and the OS terminates the program by giving fatal error.

In Non Contiguous Memory allocation, processes can be allocated


anywhere in available space. The address translation in non-contiguous
memory allocation is difficult.
There are several techniques used for address translation in non
contiguous memory allocation like Paging, Multilevel paging, Inverted
paging, Segmentation, Segmented paging. Different data structures and
hardware support like TLB are required in these techniques.

You might also like