To make it as simple as possible for programs to find space to be loaded and executed
Memory is divided into:
Logical addresses - an address generated by the CPU
Physical address - an address that can be seen by the memory unit, it is loaded into the memory address register
What is fragmentation
It is when memory spaces are used in such a way that there are small pieces of memory left unused
Virtual memory
Acts as a backup storage for a computer's main memory. This helps the computer run programs that require more memory than it actually has
Implemented using demand paging/segmentation
What is paging
When a process is being executed, its pages are loaded into any available memory frame from the backing store
In the physical memory, it is a small block sized memory called a frame
In the logical memory, it is called a page
What is demand paging?
When a process needs to be executed, it is paged into the memory. The whole process is not paged, only pages that are needed are brought in
What is demand segmentation?
It is when segments of a program are brought into the memory only when they are needed, if they are not used it can be removed from the memory.
A segment is a logical unit of a programs address space
When does a page fault occur?
A page fault is an error that occurs when a program tries to access a page in the virtual memory that is not currently in the main memory
Steps to handling a page fault:
Locate the missing page in the memory
Find free memory frame (if there is no free memory, make a free space)
Copy it into the physical memory
Reset the page table
Restart the instructions
What if there are no free frames? PAGE REPLACEMENT
...
Find a frame that is not being used and free it
Use a page replacement algorithm to find a free frame
How to free a frame:
Find a frame that isn't being used
Copy its contents to the disk
Change the page table to indicate the page is no longer in memory
Newly free frame can be used to store the page that resulted in the page fault
Page replacement algorithms
...
First in first out - oldest page is replaced
Optimal - replaces the page that will not be used for the longest time
Least recently used - replaces the page that has not been used for the longest time
What is thrashing?
A condition where there is high page replacement activity.Process spends more time replacing pages rather than processing, which causes CPU utilization to drop