memory allocation in os
memory allocation in os

Memory Allocation in OS

Memory allocation in os is an important function of operating system. Every user’s program need memory space in RAM in order to execute. Operating system keeps track of how much memory is available at any instant of time. Operating system is responsible for deallocation of memory from process after it’s completion.
 
Computer science student should have the knowledge about memory management basics concepts and memory management techniques. Some questions are always asked form memory allocation in os in GATE(CS/IT) or UGC NET exam.
 

This tutorial is specially written for computer science students to provide them knowledge about memory allocation in os. In this tutorial we will learn about introduction of memory allocation and different methods of memory allocation such as contiguous and non contiguous memory allocation in os.

Advantages and disadvantages of  contiguous and non contiguous memory allocation in os are also explained here in this tutorial with example.

Questions and Answers

By the end of this tutorial computer science students will be able to answer the following questions

  • What is memory ?
  • Explain memory management function of operating system.
  • What is contiguous memory allocation in os
  • What is non contiguous memory allocation?
  • Write the difference between contiguous and non contiguous memory allocation.
  • What is process?
  • How to protect memory in contiguous memory allocation?
  • What is memory management unit?

Contiguous Memory Allocation in OS

In contiguous memory allocation in os every process is allotted one contiguous space in memory. Process should exist during a single block or partition of a contiguous address house.  It is not possible sometime to possess giant enough block for the process. Low overhead.

Some facts about contiguous memory allocation are as follow :

  • Contiguous memory allocation may be a classical memory allocation model that assigns process consecutive memory blocks (that is, memory blocks having consecutive addresses).
  • Contiguous memory allocation is one in every of the oldest memory allocation schemes. once process must execute. The scale of the process is compared with the number of contiguous main memory offered to execute the process.
  • If comfortable contiguous memory is found, the process is allotted memory to start out its execution. Otherwise, it’s further to a queue of waiting processes till comfortable free contiguous memory is offered.
  • The contiguous memory allocation theme will be enforced in operational systems with the assistance of 2 registers, referred to as the bottom and limit registers. Once a process is corporal punishment in main memory, its base register contains the beginning address of the memory location wherever the process is corporal punishment, whereas the number of bytes consumed by the process is keep within the limit register.
  •  A process doesn’t directly sit down with the particular address for a corresponding memory location. Instead, it uses a relative address with regard to its base register. All addresses referred by a program  thought-about as virtual addresses.

The central processing unit generates the logical or virtual address, that is born-again into an actual address with the assistance of the memory management unit (MMU). the bottom address register is employed for address translation by the MMU. Thus, a physical address is calculated by adding the Base register address and logical or virtual address.

The address of Any memory location documented by a process is checked to make sure that it doesn’t sit down with an address of a neighboring process. This process security is handled by the underlying software system.

One disadvantage of contiguous memory allocation is that the degree of instruction execution is reduced thanks to processes expecting free memory.

Several problems associated with contiguous memory allocation are Memory Protection, Relocation and fragmentation. Faces the matter of memory fragmentation. Apply techniques of memory compaction and recycle in dynamic. Compaction needs , Swapping techniques are used.

memory allocation in os

 

Non Contiguous Memory Allocation in OS

In the Non-contiguous memory organization, the Complete program is split into chunks referred to as sections, and every segment will be placed in several elements or blocks of memory. It is easier to find the opening or house during which it will be matched.

In context to memory organization, non-contiguous memory allocation suggests that the offered memory house is scattered here and there. It suggests that all the free offered memory house is not alone in one place. Reduces external fragmentation.

 Memory Allocation in OS Example

Consider the scenario given in the figure.
memory allocation in c
 
Let us understand the above example for the both contiguous and non contiguous memory allocation.

In case of Contiguous Memory Allocation Process P1, P2 and P3 are placed in blocks of memory which has sufficient space available to hold these process p1 .

To understand the concept of Non Contiguous memory Allocation consider that After Placing the process p1, p2 and p3 suppose a new process P is arrived and size of p is 60 KB. But we don’t have 60 Kb free space continuously ( as shown in figure c) we have 60 KB free space in scattered manner 20 KB after process p3 and 40 Kb after process D.

 So we can use this scattered space to allocate  the this  new process p . We divide the process P in two chunks one of 20 Kb and another of 40 Kb and places these chunks of process P in available spaces of 20 KB nd 40 Kb,

Two approaches are used in non-contiguous memory allocation techniques first is paging, and the second is segmentation. Paging consists of fixed-size pages. However, external fragmentation occurred in this technique. The second technique is segmentation. It avoids external fragmentation  

Conclusion and Summary

In this memory allocation in the os-based tutorial, we discussed contiguous memory allocation and non-contiguous memory allocation. I hope that this tutorial will be helpful to students in understanding these concepts. If you have any problem or query related to the topic, then please ask in the comments. Your suggestion and questions are really valuable for us.

Please give your feedback or leave a comment to improve and provide you a good quality tutorial

Previous Tutorial – Swapping in Memory Management

Next Tutorial – Introduction to Fragmentation

If you find this page useful then please Like and Share the post on Facebook, Twitter, LinkedIn through their icons as given below.

 

Leave a Reply

Your email address will not be published. Required fields are marked *