Open In App

Best Ways for Operating System Memory Management

Last Updated : 14 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – Partition Allocation Methods

Contiguous Memory Allocation :
Probably the least difficult technique for the memory portion is to isolate memory into a few fixed partitions. Each partition contains precisely one process. The level of multi-programming relies upon the number of partitions. In the different partition technique, when a partition is free, the process is chosen from the info line and is stacked in to free partition of memory. At the point when a process ends, the memory partition opens up for another process. Batch OS utilizes the fixed size partition conspire.

Here are some of the best ways for operating system memory management:

  1. Virtual Memory: This is one of the most important techniques used for memory management in modern operating systems. It allows the computer to use more memory than is physically available by temporarily transferring data from the RAM to the hard drive.
  2. Paging: This technique divides memory into small fixed-size pages and swaps them in and out of physical memory as needed. This helps to optimize memory usage and minimize page faults.
  3. Segmentation: This technique divides memory into segments of varying sizes based on the program’s memory requirements. Each segment is treated as a separate unit and is allocated or deallocated as needed.
  4. Memory Compression: This technique compresses the memory pages to reduce their size and make more room in physical memory.
  5. Memory Pooling: This technique uses a pool of pre-allocated memory blocks of fixed sizes to reduce memory fragmentation and optimize memory allocation and deallocation.
  6. Garbage Collection: This technique automatically frees up memory that is no longer being used by the program. It helps to reduce memory leaks and improves memory efficiency.
  7. Memory Protection: This technique helps prevent unauthorized access to memory by setting access permissions for different processes and users.

By using these memory management techniques, an operating system can optimize memory usage, minimize page faults, reduce memory fragmentation, and prevent unauthorized access to memory. This can result in improved system performance, stability, and security.

The OS keeps a table demonstrating which a piece of the memory is free and is involved. At the point when the process enters the framework, it will be stacked into the info line. The OS monitors the memory prerequisite of each process and the measure of memory accessible and figures out which process to designate the memory too. At the point when a process demands, the OS looks for the huge hole for this process, the hole is a huge square of free memory accessible. If the hole is too huge, it is part into two. One section is dispensed to the mentioning process and the other is gotten back to the arrangement of holes. The arrangement of holes is looked at to figure out which hole is ideal to dispense. There are three methodologies to choose a free hole:

First Bit
Allocates the primary hole that is adequately large. This algorithm examines memory from the starting and chooses the most readily accessible square that is adequately huge to hold the process.

Best Bit
It picks the hole i.e., nearest in size to the solicitation. It allocates the littlest hole i.e., sufficiently large to hold the process.

Worst Fit
It picks the hole i.e., nearest in size to the solicitation. It allocates the littlest hole i.e., sufficiently large to hold the process.

Operating Systems :
First, fit and best fit are the most mainstream algorithms for dynamic memory designation. The first fit is by and large quicker. The best fit looks for the whole rundown to locate the littlest hole i.e., adequately huge. The worst fit decreases the pace of creation of the littlest holes. Every one of these algorithms experiences the ill effects of fragmentation.

Memory Protection :
Memory protection infers protecting the OS from the user process and protecting the process from one another. Memory protection is given by utilizing a re-location register, with a breaking point register. The re-location register contains the values of the littlest actual address and the cutoff points register contains a scope of logical addresses.

(Re-location = 100040 and limit = 74600). The logical address should be not exactly the breaking point register; the MMU maps the logical address dynamically by adding the incentive in the relocation register. At the point when the CPU scheduler chooses a process for execution, the dispatcher stacks the re-location and cutoff register with correct values as a piece of the setting switch. Since each address created by the CPU is checked against these registers we can secure the OS and other users’ programs and data from being altered.

Fragmentation :
Memory fragmentation can be of two sorts – Internal Fragmentation and External Fragmentation. In Internal Fragmentation, there is squandered space inside a segment because the square of data stacked is more modest than the partition. Example – If there is a square of 50kb and if the process requests 40kb and on the off chance that the square is allotted to the process, at that point there will be 10kb of memory left.

Outer Fragmentation exists when there is sufficient memory space exists to fulfill the request, however, it is not bordering i.e., stockpiling is divided into an enormous number of little holes. Outer Fragmentation might be either minor or a significant issue. One answer for beating outside fragmentation is compaction. The objective is to move all the free memory together to frame a huge square. Compaction is beyond the realm of imagination consistently. On the off chance that the relocation is static and is done at load time, at that point compaction is beyond the realm of imagination. Another conceivable answer for the outer fragmentation issue is to allow the logical address space of a process to be non-bordering, in this way permitting the process to be dispensed actual memory at whatever point the last is accessible.

Segmentation :
Most users do not consider memory a straight array of bytes rather the users considers memory a 55 an assortment of variable-sized segments that are devoted to a specific utilize. Example – code, data, stack, pile, and so on. A logical address is an assortment of segments. The address determines both the segment name and the offset inside the segments. The users indicate address by utilizing two amounts: a segment name and an offset. For effortlessness, the segments are numbered and referred to by a segment number. So the logical address comprises <segment number, offset>.

Here are some advantages and disadvantages of using these memory management techniques:

Advantages:

  1. Virtual Memory allows programs to use more memory than is physically available, which can improve system performance.
  2. Paging helps to optimize memory usage by only loading pages that are needed into physical memory, reducing page faults.
  3. Segmentation allows for more efficient memory allocation and deallocation, which can help reduce memory fragmentation.
  4. Memory Compression can help reduce the amount of memory needed to store data, improving overall memory usage.
  5. Memory Pooling can improve memory allocation and deallocation performance, reducing memory fragmentation.
  6. Garbage Collection helps prevent memory leaks, ensuring that memory is properly freed up when no longer needed.
  7. Memory Protection helps to prevent unauthorized access to memory, improving system security.

Disadvantages:

  1. Virtual Memory can slow down system performance if there is heavy swapping between RAM and the hard drive.
  2. Paging can lead to increased system overhead due to page swapping.
  3. Segmentation can be inefficient if the program requires memory that is not available in the existing segment.
  4. Memory Compression can slow down system performance if there is heavy compression and decompression of memory pages.
  5. Memory Pooling can waste memory if blocks are allocated but never used.
  6. Garbage Collection can cause performance issues if it runs too frequently or if there are too many objects to be garbage collected.
  7. Memory Protection can be complex to implement and maintain, leading to potential security vulnerabilities if not properly managed.

Overall, the advantages of using memory management techniques far outweigh the disadvantages, as they are necessary for efficient and secure operation of modern operating systems.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads