Actual Methodology/procedure Followed:-
ABSTRACT
Memory is the important part of the computer that is used to store the
data. Its management is critical to the computer system because the amount of
main memory available in a computer system is very limited. At any time,
many processes are competing for it. Moreover, to increase performance, sever
al processes are executed simultaneously. For this, we must keep several proce
sses in the main memory, so it is even more important to manage them
effectively.
INTRODUCTION
Memory Management is the process of controlling and coordinating
computer memory, assigning portions known as blocks to various running
programs to optimize the overall performance of the system.
It is the most important function of an operating system that manages
primary memory. It helps processes to move back and forward between the
main memory and execution disk. It helps OS to keep track of every memory
location, irrespective of whether it is allocated to some process or it remains
free.
Memory Management
What is memory ?
The main memory is central to the operation of a modern computer.
Main Memory is a large array of words or bytes, ranging in size from hundreds
of thousands to billions. Main memory is a repository of rapidly available
information shared by the CPU and I/O devices. Main memory is the place
where programs and information are kept when the processor is effectively
utilizing them. Main memory is associated with the processor, so and
information into and out of the processor is extremely fast.Main memory is
also known as RAM(Random Access Memory). This memory is a volatile
memory. RAM lost its data when a power interruption occurs.
What is Memory Management ?
In a multiprogramming computer, the operating system resides in a part of
memory and the rest is used by multiple processes. The task of subdividing
the memory among different processes is called memory management.
Memory Management is a method in the operating manage operations
between main memory and disk during process execution. The mainaim of
memory management is to achieve efficient utilization of memory.
Why Memory Management is Required :
Allocate and de-allocate memory before and after process execution.
To keep track of used memory space by processes.
To minimize fragmentation issues.
To proper utilization of main memory.
To maintain data integrity while executing of process.
Now we are discussing the concept of logical address space and Physical
address space:
Virtual and Physical Address Space:-
Virtual Addresses Space:-
A virtual address is a program-generated address representing an abstraction
of physical memory. Every process uses the virtual memory address space as
dedicated memory.
An address generated by the CPU is known as a “Logical Address”. It is also
known as a Virtual address. Logical address space can be defined as the size of
the process. A logical address can be changed
Virtual addresses do not match physical memory locations. Programs read and
create virtual addresses, unaware of the physical address space. The main
memory unit (MMU) maps virtual to physical addresses to ensure valid
memory access.
Physical Address space:-
An address seen by the memory unit (i.e the one loaded into the memory
address register of the memory) is commonly known as a “Physical Address”. A
Physical address is also known as a Real address. The set of all physical
addresses corresponding to these logical addresses is known as Physical
address space. A physical address is computed by MMU. The run-time mapping
from virtual to physical addresses is done by a hardware device Memory
Management Unit(MMU). The physical address always remains constant.
Static and Dynamic Loading:-
To load a process into the main memory is done by a loader. There are two
different types of loading :
Static loading:-
loading the entire program into a fixed address. It requires more memory
space.
Static loading allocates memory and addresses during program launch. It has
predictable but inefficient resource usage where a program loads into memory
along with all the necessary resources in advance. System utilities and
applications use static loading to simplify program distribution. Executable files
require compilation and are typically larger files. Real-time operating systems,
bootloaders, and legacy systems utilize static loading.
Dynamic loading:-
The entire program and all data of a process must be in physical memory for
the process to execute. So, the size of a process is limited to the size of physical
memory. To gain proper memory utilization, dynamic loading is used. In
dynamic loading, a routine is not loaded until it is called. All routines are
residing on disk in a relocatable load format. One of the advantages of dynamic
loading is that unused routine is never loaded. This loading is useful when a
large amount of code is needed to handle it efficiently.
Dynamic loading allocates memory and address resolutions during program
execution, and a program requests resources as needed. Dynamic loading
reduces memory consumption and enables a multi-process environment.
Executable files are smaller but have added complexity due to memory leaks,
overhead, and runtime errors. Modern operating systems (Linux, macOS,
Windows), mobile operating systems (Android, iOS), and web browsers use
dynamic loading.
Static and Dynamic linking:-
To perform a linking task a linker is used. A linker is a program that takes one or
more object files generated by a compiler and combines them into a single
executable file.
Static linking:
In static linking, the linker combines all necessary program modules into a
single executable program. So, there is no runtime dependency. Some
operating systems support only static linking, in which system language
libraries are treated like any other object module.
Dynamic linking:
The basic concept of dynamic linking is similar to
dynamic loading. In dynamic linking, “Stub” is included for each appropriate
library routine reference. A stub is a small piece of code. When the stub is
executed, it checks whether the needed routine is already in memory or not. If
not available then the program loads the routine into memory.
Swapping:-
Swapping is a method in which the process should be swapped temporarily
from the main memory to the backing store. It will be later brought back into
the memory for continue execution.
Backing store is a hard disk or some other secondary storage device that should
be big enough in order to accommodate copies of all memory images for all
users. It is also capable of offering direct access to these memory images.
Benefits of Swapping
Here, are major benefits/pros of swapping:
It offers a higher degree of multiprogramming.
Allows dynamic relocation. For example, if address binding at execution
time is being used, then processes can be swap in different locations.
Else in case of compile and load time bindings, processes should be
moved to the same location.
It helps to get better utilization of memory.
Minimum wastage of CPU time on completion so it can easily be applied
to a priority-based scheduling method to improve its performance.
Fragmentation:-
Fragmentation is defined as when the process is loaded and removed after
execution from memory, it creates a small free hole. These holes cannot be
assigned to new processes because holes are not combined or do not fulfill the
memory requirement of the process. To achieve a degree ofmultiprogramming,
we must reduce the waste of memory or fragmentation problems. In the
operating systems two types of fragmentation:
a .Internal Fragmentation
b .External Fragmentation
Internal fragmentation requires design changes. The typical resolution is
through the paging and segmentation mechanism.
External fragmentation requires the operating system to
periodically deframnet and free up unused space.
Paging :-
Paging is a memory management scheme that eliminates the need for
contiguous allocation of physical memory. This scheme permits the physical
address space of a process to be non-contiguous.
Logical Address or Virtual Address (represented in bits): An address
generated by the CPU
Logical Address Space or Virtual Address Space (represented in words or
bytes): The set of all logical addresses generated by a program
Physical Address (represented in bits): An address actually available on a
memory unit
Physical Address Space (represented in words or bytes): The set of
all physical addresses corresponding to the logical addresses