Skip to main content

OPERATING SYSTEM || UNIT III || Memory Management - Basic Concept of Memory - Address Binding - Logical & Physical Address Space

 OPERATING SYSTEM
UNIT III




Memory Management

·         Memory Management is the process of coordinating and controlling the memory in a computer, Blocks are assigning portions that are assigned to various running programs in order to optimize the overall performance of the system.

Computer Memory

·         Computer memory can be defined as a collection of some data represented in the binary format.

·         On the basis of various functions, memory can be classified into various categories. We will discuss each one of them later in detail.

·         A computer device that is capable to store any information or data temporally or permanently is called storage device.

Need for Memory Management in OS

Memory management technique is needed for the following reasons:

  • 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.

Basic Concepts of Memory Management

The main memory can be allocated with two ways –

1.       Contiguous memory allocation

2.      Non-Contiguous memory allocation 

Contiguous memory allocation can be done in two ways:

1.       Fixed partition scheme

2.      Variable partition scheme.

Different Partition Allocation methods are used in Contiguous memory allocations –

1.       First Fit

2.      Best Fit 

3.      Worst Fit

4.      Next Fit

MMU (Memory Management Unit):

·         The run time mapping between Virtual address and Physical Address is done by a hardware device known as MMU.

·         In memory management, the Operating System will handle the processes and move the processes between disk and memory for execution. It keeps track of available and used memory.

MMU scheme:

1.       CPU will generate logical address (for example: 346)

2.      MMU will generate a relocation register (base register) (for example: 14000)

3.      In memory, the physical address is located [for example:(346+14000= 14346)]

 Memory Management in Operating System

  • The value in the relocation register is added to every address generated by a user process at the time the address is sent to memory. 
  • The user program never sees the real physical addresses.
  • The program can create a pointer to location 346, store it in memory, manipulate it, and compare it with other addresses—all like the number 346. 
  • The user program generates only logical addresses & these logical addresses must be mapped to physical addresses before they are used. 

Address binding:

·         Address binding is the process of mapping from one address space to another address space.

·         Logical address is an address generated by the CPU during execution, whereas Physical Address refers to the location in the memory unit (the one that is loaded into memory).

·         The logical address undergoes translation by the MMU or address translation unit in particular. The output of this process is the appropriate physical address or the location of code/data in RAM.

An address binding can be done in three different ways:

1.       Compile Time

2.      Load Time

3.      Execution Time

Compile Time:

·         The physical address is embedded to the executable of the program during compilation.

·         Loading the executable as a process in memory is very fast.

·         But if the generated address space is preoccupied by other processes, then the program crashes and it becomes necessary to recompile the program to change the address space.

Load time:

·         If the physical address is not known at the compile time where the process will reside, then a relocatable address will be generated. The loader translates the relocatable address to an absolute address.

·         The base address of the process in main memory is added to all logical addresses by the loader to generate an absolute address.

·          If the base address of the process changes, then we need to reload the process again.

 Execution time:

·         The instructions are in memory and are being processed by the CPU.

·         Additional memory may be allocated and/or deallocated at this time.

·         The address binding will be done during execution time. This method is used, if a process moved from one memory to another during execution. (Example: Compaction)


Address Mapping:

·         In Contiguous memory allocation mapping from virtual addresses to physical addresses is not a difficult task, because if we take a process from secondary memory and copy it to the main memory, the addresses will be stored in a contiguous manner, so if we know the base address of the process, we can find out the next addresses. 

·         The Memory Management Unit is a combination of 2 registers – 

1.       Base Register (Relocation Register) 

2.      Limit Register. 

Base Register :
                             Contains the starting physical address of the process.
Limit Register :
                              Mentions the limit relative to the base address on the region occupied by the process. 

 



·         The logical address generated by the CPU is first checked by the limit register, If the value of the logical address generated is less than the value of the limit register, the base address stored in the relocation register is added to the logical address to get the physical address of the memory location.

·         If the logical address value is greater than the limit register, then the CPU traps to the OS, and the OS terminates the program by giving fatal error.


Logical and Physical Address Space:

Logical Address space: 

ü  An address generated by the CPU is known as “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.

Physical Address space: 

ü  An address seen by the memory unit 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:

  1. Static loading:-
    • In static loading load the entire program into a fixed address. It requires more memory space.
  2. 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.

 

Popular posts from this blog

EVOLVING ROLE OF SOFTWARE

EVOLVING ROLE OF SOFTWARE Software is both a product and a vehicle for delivering a product.

Operating System || Unit I || Process Management

  Operating System Unit I Process Management Introduction to Process: A program in execution is called a process. The execution of a process must progress in a sequential fashion. In order to complete its task, process needs the computer resources. A process can be defined as an entity which represents the basic unit of work to be implemented in the system. The operating system has to manage all the processes which require the same resource at the same time , in a convenient and efficient way. The Process Management Involves, Scheduling processes and threads on the CPUs. Creating and deleting both user and system processes. Suspending and resuming processes. Providing mechanisms for process synchronization. Providing mechanisms for process communication. Process Architecture A program becomes a process, when it is loaded into the memory. A process in memory can be divided in 4 sect...