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

Memory Management

Memory Management

Uploaded by

Srinivasa Rao
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Memory Management

Memory Management

Uploaded by

Srinivasa Rao
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Swapping in OS

Swapping is a memory management technique for swapping data between main memory and secondary
memory for better memory utilization.

Swapping is moving data between physical memory (RAM) and secondary memory. In computing, virtual
memory is a management technique that combines a computer’s hard disk space with its random access
memory (RAM) to create a larger virtual address space. This can be useful if you have too many
processes running on your system and not enough physical memory to store them.

While performing swapping the operating system needs to allocate a block of memory. It finds
the first vacant block of physical memory.

As each new block of memory is allocated, it replaces the oldest block in physical memory.
When a program attempts to access a page that has been swapped out, the operating system
copies the page from the disk into physical memory and updates the page table entry.

The purpose of operating system swapping is to increase the degree of multiprogramming and
increase main memory usage.

There are two steps to changing the operating system:

1. Swap-in: A swap-in process in which a process moves from secondary storage / hard
disk to main memory (RAM).
2. Swap out: Swap out takes a process out of the main memory and places it in secondary
memory.

Need of swapping in operating system


The main purpose of swapping in memory management is to allow more available memory than
the computer hardware. Physical memory may be allocated, and the process may require
additional memory. Rather than constraining the system to use only memory based on physical
RAM, memory swapping allows the operating system and its users to extend the memory to disk.

Conclusion
If swapping is done correctly, it can be incredibly effective in keeping your computer running
smoothly. However, if not done correctly, it can lead to decreased performance, and even system
crashes.

Contiguous Memory Allocation in OS

Contiguous memory allocation in OS is a memory allocation process in which each process is


allocated a contiguous block of memory, meaning that the memory locations for a process are
consecutive.

Contiguous memory allocation is one of these memory allocation strategies. We use this
technique to allocate contiguous blocks of memory to each process, as the name suggests.
Therefore, we allot a continuous segment from the entirely empty space to the process based on
its size whenever a process requests to enter the main memory.

There are mainly two contiguous memory allocation techniques, which can be used to allocate
the contiguous memory.

 Fixed-size partition schema


 Variable-size partition schema

Fixed-size Partition Schema:

Each process in this method of contiguous memory allocation is given a fixed size continuous
block in the main memory. This means that the entire memory will be partitioned into continuous
blocks of fixed size, and each time a process enters the system, it will be given one of the
available blocks. Because each process receives a block of memory space that is the same size,
regardless of the size of the process. Static partitioning is another name for this approach.

.
Flexible Partitioning Method

No fixed blocks or memory partitions are created while using this style of contiguous memory
allocation technique. Instead, according on its needs, each process is given a variable-sized
block. This indicates that if space is available, this amount of RAM is allocated to a new process
whenever it requests it. As a result, each block's size is determined by the needs and
specifications of the process that uses it.

Advantages of Contiguous Memory Management


 It’s simple to monitor how many memory blocks are still available for use, which
determines how many more processes can be allocated RAM.
 Considering that the complete file can be read from the disc in a single session,
contiguous memory allocation offers good read performance.
 Contiguous allocation is simple to set up and functions well.

Paging in OS
Paging is a storage mechanism used in OS to retrieve processes from secondary storage to the
main memory as pages. The primary concept behind paging is to break each process into
individual pages. Thus the primary memory would also be separated into frames.

One page of the process must be saved in one of the given memory frames. These pages can be
stored in various memory locations, but finding contiguous frames/holes is always the main goal.
Process pages are usually only brought into the main memory when they are needed; else, they
are stored in the secondary storage.

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.

Example of Paging in OS
For example, if the main memory size is 16 KB and Frame size is 1 KB. Here, the main memory
will be divided into the collection of 16 frames of 1 KB each.

There are 4 separate processes in the system that is A1, A2, A3, and A4 of 4 KB each. Here, all
the processes are divided into pages of 1 KB each so that operating system can store one page in
one frame.

At the beginning of the process, all the frames remain empty so that all the pages of the
processes will get stored in a contiguous way.

Advantages of Paging
Here, are advantages of using Paging method:

 Easy to use memory management algorithm


 No need for external Fragmentation
 Swapping is easy between equal-sized pages and page frames.

Disadvantages of Paging
Here, are drawback/ cons of Paging:

 May cause Internal fragmentation


 Page tables consume additional memory.
 Multi-level paging may lead to memory reference overhead.

What is Segmentation?
Segmentation method works almost similarly to paging, only difference between the two is that
segments are of variable-length whereas, in the paging method, pages are always of fixed size.

A program segment includes the program’s main function, data structures, utility functions, etc.
The OS maintains a segment map table for all the processes. It also includes a list of free
memory blocks along with its size, segment numbers, and its memory locations in the main
memory or virtual memory.

Advantages of Segmentation
Here, are pros/benefits of Segmentation

 Offer protection within the segments


 You can achieve sharing by segments referencing multiple processes.
 Not offers internal fragmentation
 Segment tables use lesser memory than paging

Disadvantages of Segmentation
Here are cons/drawback of Segmentation

 In segmentation method, processes are loaded/ removed from the main memory. Therefore,
the free memory space is separated into small pieces which may create a problem of external
fragmentation
 Costly memory management algorithm.

Summary
 Paging is a storage mechanism that allows OS to retrieve processes from the secondary storage
into the main memory in the form of pages.
 The paging process should be protected by using the concept of insertion of an additional bit
called Valid/Invalid bit.
 The biggest advantage of paging is that it is easy to use memory management algorithm
 Paging may cause Internal fragmentation
 Segmentation method works almost similarly to paging, only difference between the two is that
segments are of variable-length whereas, in the paging method, pages are always of fixed size.
 You can achieve sharing by segments referencing multiple processes.
 Segmentation is costly memory management algorithm
What is Virtual Memory in OS

Virtual Memory is a storage scheme that provides user an illusion of having a very big main
memory. This is done by treating a part of secondary memory as the main memory.

In this scheme, User can load the bigger size processes than the available main memory by
having the illusion that the memory is available to load the process.

Instead of loading one big process in the main memory, the Operating System loads the different
parts of more than one process in the main memory.

By doing this, the degree of multiprogramming will be increased and therefore, the CPU
utilization will also be increased.

How Virtual Memory Works?


In modern word, virtual memory has become quite common these days. In this scheme,
whenever some pages needs to be loaded in the main memory for the execution and the memory
is not available for those many pages, then in that case, instead of stopping the pages from
entering in the main memory, the OS search for the RAM area that are least used in the recent
times or that are not referenced and copy that into the secondary memory to make the space for
the new pages in the main memory.

Since all this procedure happens automatically, therefore it makes the computer feel like it is
having the unlimited RAM.

When talking about the differences between virtual and physical memory, the biggest distinction
commonly made is to speed. RAM is considerably faster than virtual memory. RAM, however,
tends to be more expensive.

When a computer requires storage, RAM is the first used. Virtual memory, which is slower, is
used only when the RAM is filled.

Advantages of Virtual Memory

1. The degree of Multiprogramming will be increased.


2. User can run large application with less real RAM.
3. There is no need to buy more memory RAMs.

Disadvantages of Virtual Memory

1. The system becomes slower since swapping takes time.


2. It takes more time in switching between applications.
3. The user will have the lesser hard disk space for its use.
Virtual Memory: https://www.youtube.com/watch?v=sRUq_uaZ5f0

Demand paging: https://www.youtube.com/watch?v=8HZGh7S1lJo

Thrashing: https://www.youtube.com/watch?v=IyWaK8pbN6A

You might also like