Chapter-3 MSc-cs
Chapter-3 MSc-cs
That means if we have a program line written as int α = 10 then the computer converts
it into the binary language and then store it into the memory blocks.
well, we can enlarge this range by using unsigned int. in that case, the bit which is now
storing the sign will also store the bit value and therefore the range will be 0 to 65,535.
Let's consider,
Process Size = 4 MB
Main memory size = 4 MB
The process can only reside in the main memory at any time.
If the time for which the process does IO is P,
Then,
Then
Therefore, we can state that the CPU utilization will be increased if the memory size
gets increased.
Swapping:
Swapping is a memory management scheme in which any process can be temporarily
swapped from main memory to secondary memory so that the main memory can be
made available for other processes. It is used to improve main memory utilization. In
secondary memory, the place where the swapped-out process is stored is called swap
space.
The purpose of the swapping in operating system is to access the data present in the
hard disk and bring it to RAM so that the application programs can use it. The thing
to remember is that swapping is used only when data is not present in RAM.
Although the process of swapping affects the performance of the system, it helps to
run larger and more than one process. This is the reason why swapping is also referred
to as memory compaction.
The concept of swapping has divided into two more concepts: Swap-in and Swap-out.
Example: Suppose the user process's size is 2048KB and is a standard hard disk where
swapping has a data transfer rate of 1Mbps. Now we will calculate how long it will take
to transfer from main memory to secondary memory.
Now taking swap-in and swap-out time, the process will take 4000 milliseconds.
Advantages of Swapping
1. It helps the CPU to manage multiple processes within a single main memory.
2. It helps to create and use virtual memory.
3. Swapping allows the CPU to perform multiple tasks simultaneously. Therefore,
processes do not have to wait very long before they are executed.
4. It improves the main memory utilization.
Disadvantages of Swapping
1. If the computer system loses power, the user may lose all information related to the
program in case of substantial swapping activity.
2. If the swapping algorithm is not good, the composite method can increase the number
of Page Fault and decrease the overall processing performance.
It is obvious that under this system, the number of continuous blocks into which the
memory will be partitioned will be determined by the amount of space each block
covers, and this, in turn, will determine how many processes can remain in the main
memory at once.
The degree of multiprogramming refers to the number of processes that can run
concurrently in memory. Therefore, the number of blocks formed in the RAM
determines the system's level of multiprogramming.
Advantages
o This strategy is easy to employ because each block is the same size. Now all
that is left to do is allocate processes to the fixed memory blocks that have been
divided up.
o It is simple to keep track of how many memory blocks are still available, which
determines how many further processes can be allocated memory.
o This approach can be used in a system that requires multiprogramming since
numerous processes can be maintained in memory at once.
Disadvantages
Although the fixed-size partitioning strategy offers numerous benefits, there are a few
drawbacks as well:
o We won't be able to allocate space to a process whose size exceeds the block
since the size of the blocks is fixed.
o The amount of multiprogramming is determined by block size, and only as
many processes can run simultaneously in memory as there are available blocks.
o We must assign the process to this block if the block's size is more than that of
the process; nevertheless, this will leave a lot of free space in the block. This
open area might have been used to facilitate another procedure.
This method is also known as dynamic partitioning because the blocks' sizes are
flexible and determined as new processes start.
Advantages
Disadvantages
Despite the variable-size partition scheme's many benefits, there are a few drawbacks
as well:
o This method is dynamic, hence it is challenging to implement a variable-size
partition scheme.
o It is challenging to maintain record of processes and available memory space.
Continuous blocks of memory assigned to processes cause the main memory to always
be full. A procedure, however, leaves behind an empty block termed as a hole after it
is finished. A new procedure could potentially be implemented in this area. As a result,
there are processes and holes in the main memory, and each one of these holes might
be assigned to a new process that comes in.
First-Fit
This is a fairly straightforward technique where we start at the beginning and assign
the first hole, which is large enough to meet the needs of the process. The first-fit
technique can also be applied so that we can pick up where we left off in our previous
search for the first-fit hole.
Best-Fit
The goal of this greedy method, which allocates the smallest hole that meets the needs
of the process, is to minimise any memory that would otherwise be lost due to internal
fragmentation in the event of static partitioning. Therefore, in order to select the
greatest match for the procedure without wasting memory, we must first sort the holes
according to their diameters.
Worst-Fit
The Best-Fit strategy is in opposition to this one. The largest hole is chosen to be
assigned to the incoming process once the holes are sorted based on size. The theory
behind this allocation is that because the process is given a sizable hole, it will have a
lot of internal fragmentation left over. As a result, a hole will be left behind that can
house a few additional processes.
o The number of memory blocks remaining, which affects how many further
processes can be given memory space, is easy to keep track of.
o Contiguous memory allocation has good read performance since the entire file
can be read from the disc in a single process.
o The contiguous allocation works well and is easy to set up.
Disadvantages
o Fragmentation is not an issue because each new file can be written to the disk's
end after the preceding one.
o In order to choose the proper hole size while creating a new file, it needs know
its final size.
o The extra space in the holes would need to be compressed or used once the
diskis full.
Paging:
Paging is a storage mechanism 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 process is to be stored in one of the frames of the memory. The pages
can be stored at the different locations of the memory but the priority is always to find
the contiguous frames or holes.
Pages of the process are brought into the main memory only when they are required
otherwise they reside in the secondary storage.
Different operating system defines different frame sizes. The sizes of each frame must
be equal. Considering the fact that the pages are mapped to the frames in Paging,
page size needs to be as same as frame size.
Structure of the 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.
In this situation, a unit named as Memory Management Unit comes into the picture. It
converts the page number of the logical address to the frame number of the physical
address. The offset remains same in both the addresses.
To perform this task, Memory Management unit needs a special kind of mapping
which is done by page table. The page table stores all the Frame numbers
corresponding to the page numbers of the page table.
In other words, the page table maps the page number to its actual location (frame
number) in the memory.
In the image given below shows, how the required word of the frame is accessed with
the help of offset.
Segmentation:
In Operating Systems, Segmentation is a memory management technique in which the
memory is divided into the variable size parts. Each part is known as a segment which
can be allocated to a process.
The details about each segment are stored in a table called a segment table. Segment
table is stored in one (or many) of the segments.
Operating system doesn't care about the User's view of the process. It may divide the
same function into different pages and those pages may or may not be loaded at the
same time into the memory. It decreases the efficiency of the system.
It is better to have segmentation which divides the process into the segments. Each
segment contains the same type of functions such as the main function can be
included in one segment and the library functions can be included in the other
segment.
1. Segment Number
2. Offset
For Example:
Suppose a 16 bit address is used with 4 bits for the segment number and 12 bits for
the segment offset so the maximum segment size is 4096 and the maximum number
of segments that can be refereed is 16.
When a program is loaded into memory, the segmentation system tries to locate space
that is large enough to hold the first segment of the process, space information is
obtained from the free list maintained by memory manager. Then it tries to locate
space for other segments. Once adequate space is located for all the segments, it loads
them into their respective areas.
The operating system also generates a segment map table for each program.
With the help of segment map tables and hardware assistance, the operating system
can easily translate a logical address into physical address on execution of a program.
The Segment number is mapped to the segment table. The limit of the respective
segment is compared with the offset. If the offset is less than the limit then the address
is valid otherwise it throws an error as the address is invalid.
In the case of valid addresses, the base address of the segment is added to the offset
to get the physical address of the actual word in the main memory.
The above figure shows how address translation is done in case of segmentation.
Advantages of Segmentation
1. No internal fragmentation
2. Average Segment Size is larger than the actual page size.
3. Less overhead
4. It is easier to relocate segments than entire address space.
5. The segment table is of lesser size as compared to the page table in paging.
Disadvantages
1. It can have external fragmentation.
2. it is difficult to allocate contiguous memory to variable sized partition.
3. Costly memory management algorithms.
Demand Paging
Advantages
Disadvantages
When the page that was selected for replacement and was paged
out, is referenced again, it has to read in from disk, and this
requires for I/O completion. This process determines the quality
of the page replacement algorithm: the lesser the time waiting
for page-ins, the better is the algorithm.
Reference String
However, the Copy on Write mechanism is not without its drawbacks. One
potential issue is the overhead associated with creating a new copy of a page.
This overhead can become significant when many processes are modifying the
same page frequently. Additionally, the increased memory usage associated
with creating multiple copies of a page can be a concern in some scenarios.
Because the Copy on Write mechanism allows new processes to share memory
pages with existing processes, the time needed to create a new process is
reduced. This can be particularly beneficial in scenarios where many processes
need to be created and destroyed frequently, such as in web servers or cloud
computing environments.
The Copy on Write mechanism is not without its drawbacks. One potential issue
is the overhead associated with creating a new copy of a page. This overhead
can become significant when many processes are modifying the same page
frequently. Additionally, the increased memory usage associated with creating
multiple copies of a page can be a concern in some scenarios. The major
drawbacks of this mechanism are as follows −
If multiple processes modify the same page frequently, the Copy on Write
mechanism may create multiple copies of the page, which can lead to
increased memory usage. This can become a concern in scenarios where
memory usage is limited or where many processes are frequently modifying
the same pages.
3. Complexity of implementation
Allocation Of Frames:
The main memory of the operating system is divided into various frames. The process
is stored in these frames, and once the process is saved as a frame, the CPU may run
it. As a result, the operating system must set aside enough frames for each process. As
a result, the operating system uses various algorithms in order to assign the frame.
here are mainly five ways of frame allocation algorithms in the OS. These are as follows:
1. Equal Frame Allocation
2. Proportional Frame Allocation
3. Priority Frame Allocation
4. Global Replacement Allocation
5. Local Replacement Allocation
Disadvantage
In a system with processes of varying sizes, assigning equal frames to each process makes
little sense. Many allotted empty frames will be wasted if many frames are assigned to a
small task.
The allocated frames for a process pi of size si are ai = (si/S)*m, in which S represents the
total of all process sizes, and m represents the number of frames in the system.
Disadvantage
The only drawback of this algorithm is that it doesn't allocate frames based on priority.
Priority frame allocation solves this problem.
Disadvantages
The process itself may not solely control the page fault ratio of a process. The paging
behavior of other processes also influences the number of pages in memory for a process.
Advantages
The paging behavior of a specific process has an effect on the pages in memory and
the page fault ratio.
Disadvantages
A low priority process may obstruct a high priority process by refusing to share its
frames.