Day 97 - Memory Management Basics

Memory is one of the main parts of a computer. Without memory we cannot store programs and execute instructions. Memory consists of a large array of bytes each with its own address. The CPU fetches instructions from the memroy and executest them according to the value of the program counter.

A typical instruction-execution cycle first fetches instruction from the memory and then decodes the instruction which may fetches operands. and after the instructions are executed the results may again be restored back into the memory.

Basic Hardware

Main memory and registers are the only general-purpose storage that the CPU can access directly. The machine instructions can only take memory addresses as arguments but not the disk addresses. So any instruction that is being executed and the data being used by the executing instruction must be in main meory for the CPU to do computation on it.

Registers that are built into the CPU take one clock cycle to be fetched but that not the same for the registers that are in the main memory. Main memory registers can take many clock cycles to be fetch since they are being fetched through a memory bus that connects the CPU with the main memory. In such cases the processor is normally stalled since it does not have any data to complete the execution of the current instruction.

To solve this stalling of the processor a faster memory is provided to the CPU called a cache that is bulit into the CPU. The Hardware automatically speeds up the memory access without any operating system control to manage this cache.

Without main memroy process cannot be executed and no computation will be achieved. This module in the Operating Systems covers how we manage main memory efficiently and solve the problems that we face during this memroy management.

Why Manage Memory

Some issues can occur when we don't manage memory efficeintly during the execution of the processes.

  • An Operating System run many processes at the same time.
  • The data and code of a process must reside in the memory in order for it to complete its execution.
  • Each process's data must be protected so that no other process can change or access it.
  • Process must share and access code of other processes if they have the right permissions.
  • All the processes cannot reside in the memory at the same time because there is not enough memory for them.

All these issues are solved in the Memory Management Module of the Operating System so that all the process can share memory efficiently.


zainscizainsci