Memory Management in Operating System - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Memory Management in Operating System

Share This

Memory is a valuable resource that requires careful management. 


The memory manager is a component of the operating system that controls the memory hierarchy. Its duties include monitoring which portions of memory are being used and which are not, allocating memory to processes as needed and releasing it when they are finished, and managing to swap between main memory and disk when main memory is insufficient to accommodate all of the processes.


"Main memory" describes a physical memory that serves as the computer's internal memory. It is distinguished from external mass storage devices like disk drives using the word main. RAM is a second name for main memory. Only data in the main memory can be changed by the computer. As a result, each application we run and each file we access must first be copied into the main memory from a storage device.


The main memory has been loaded with all the applications for use. Sometimes a whole program is loaded into memory, while other times a specific section or routine is only loaded into main memory when it is called by the program. This method is referred to as dynamic loading, and it improves performance.


Additionally, there are situations when one software depends on another. In this scenario, the CPU links the dependent programs to the main executing program as necessary rather than loading all of the dependent applications. Dynamic Linking is the name of this method.


Swapping


For a process to run, memory is a requirement. However, there are situations when a timesharing system's main memory is not large enough to accommodate all of the running processes. 


As a result, extra processes are retained on disk and introduced for dynamic operation. Bringing each process into the main memory, running it for a while, and then putting it back on the disk is known as swapping.


Contiguous Memory Allocation


Each process is allocated a single contiguous block of memory in a continuous memory allocation. There are numerous fixed-size partitions used to divide up memory. Exact one process is present in each partition. 


A process is chosen from the input queue and loaded into a partition when it becomes available. Memory "holes" are the available empty blocks. 


To choose the best hole to allocate, the collection of holes is searched.


Memory Protection


Memory protection is a phenomenon that allows us to manage a computer's memory access privileges. Its primary goal is to stop processes from accessing RAM that hasn't been assigned to them. 


As a result, it stops a process's flaw from harming other processes or the operating system as a whole and sends a segmentation fault or storage violation exception to the offending process, which usually kills it.


Memory Allocation


Memory allocation is a process by which computer programs are assigned memory or space. It is of three types:

First Fit: The first hole that is big enough is allocated to the program.

Best Fit: The smallest hole that is big enough is allocated to the program.

Worst Fit: The largest hole that is big enough is allocated to the program.


Fragmentation


In a dynamic memory allocation system, fragmentation happens when the majority of the available free blocks are too tiny to accommodate any request.


It is commonly referred to as a failure to utilize the available memory. Processes are loaded and unloaded from memory in this scenario. As a result, there are free holes that can satisfy a request but they are not contiguous, meaning that the memory is broken up into a lot of little holes. External fragmentation is the term for this phenomenon.


Additionally, memory is allotted in units of block sizes and the actual memory is occasionally divided into fixed-size blocks. The memory allotted to a place could be a little bit bigger than the amount that was requested. Internal fragmentation, or memory that is internal to a partition but is useless, is the difference between allocated and necessary memory.


Paging


Paging is a possible solution to the fragmentation issue. A memory management technique called paging makes a process's physical address area possible to be non-contagious


Here, physical memory is separated into Pages, which are equal-sized chunks. A specific process's pages are loaded into the available memory frames.


Page Table


The data structure that a computer operating system uses to record the mapping between a virtual address and a physical address is called a page table. 


The CPU creates the virtual address, sometimes called a logical address. 

The address that actually resides in memory is called the physical address.


Segmentation


Another memory management strategy that helps the user's perception of memory is segmentation. 

By using segmentation, it is possible to divide the virtual address space of a single process into pieces that can be put in physically separate regions of memory.


Segmentation with Paging


Paging and segmentation have benefits and drawbacks; it is preferable to mix the two strategies to enhance each. 'Page the Elements' is the name of the combined design. 

In this method, each segment is broken up into pages and kept in a page table. 

Consequently, the logical address is split into the following 3 components: 

  • Segment numbers (S), 
  • Page Number (P), and 
  • the offset or displacement number (D).



Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.