MEMORY BY
SNEHA G
MANAGEMENT ASSIATANT PROFESSOR
[Link]
INTRODUCTION
Memory management is the functionality of an operating system which handles or
manages primary memory and moves processes back and forth between main memory and
disk during execution.
Memory management keeps track of each and every memory location, regardless of either
it is allocated to some process or it is free.
It checks how much memory is to be allocated to processes.
It decides which process will get memory at what time.
It tracks whenever some memory gets freed or unallocated and correspondingly it updates
the status.
LOGICAL AND PHYSICAL ADDRESS IN OS
logical and physical addresses are used to manage and access memory.
Logical address:
oA logical address, also known as a virtual address, is an address generated by the CPU
during program execution.
o It is the address seen by the process and is relative to the program’s address space.
oThe process accesses memory using logical addresses, which are translated by the
operating system into physical addresses.
Physical address:
oA physical address is the actual address in main memory where data is stored.
oIt is a location in physical memory, as opposed to a virtual address.
oPhysical addresses are used by the memory management unit (MMU) to translate logical
addresses into physical addresses.
LOGICAL AND PHYSICAL ADDRESS IN
OS
The translation from logical to physical addresses is performed by the operating system’s memory management
unit.
The MMU uses a page table to translate logical addresses into physical addresses.
The page table maps each logical page number to a physical frame number.
NOTE:
The use of logical addresses provides a layer of abstraction that allows processes to access memory without
knowing the physical memory location.
Logical addresses are mapped to physical addresses using a page table. The page table contains information
about the mapping between logical and physical addresses.
The MMU translates logical addresses into physical addresses using the page table. This translation is transparent
to the process and is performed by hardware.
The use of logical and physical addresses allows the operating system to manage memory more efficiently by
using techniques such as paging and segmentation.
SWAPPING
Swapping is a mechanism in which a process can be swapped temporarily out of main
memory (or move) to secondary storage (disk) and make that memory available to other
processes.
At some later time, the system swaps back the process from the secondary storage to main
memory.
Swapping is also known as a technique for memory compaction Because effects
performance , allow multiple process to run
SWAPPING
REASON:
COMPLETED ITS TASKS TERMINATED
ABNORMAL TERMINATION
PROCESS IS IN INACTIVE STATE I/0
CHECK BEFORE SWAPPING:
1. IS PROCESS MODIFIED, THEN WRITE
BACK PROCESS TO DISK
2. ONLY READ THEN DO NOTHING, LET
OTHER PROCESS CAN OVERWRITE
3. CONSIDERABLE TIME OF CPU NEW
PROCESS
PAGING • CPU LA
• LA = (p,d)
LOGICAL • p = PAGE NO, d = OFFSET
PA
ADDRESS • p = L DIV P = QUOTIENT
• d = L MOD P = REMAINDER
• PA = f * P + d
SEGMENTATION
Purpose:
1. To achieve the user's view of memory allocation similarly
when paging does not bother where programs start and end and
it simply divides the program into pages.
2. Segmentation is mainly useful to maintain the modular
structure of a program
A process is divided into Segments.
Segments need not be of same size
Segmentation uses Variable partitioning technique
One segment = One complete memory block
SEGMENTATION
Segmentation table
contains 2 entity
•Base Address: It contains
the starting physical address
where the segments reside in
memory.
•Segment Limit: Also
known as segment offset. It
specifies the length of the
segment.
SEGMENTATION
Translation of Two-dimensional Logical Address to Dimensional Physical Address.
SEGMENTATION
Advantages:
No internal fragmentation
Sharing of code is easy
Segmentation table Consumes less spaces compare to paging table in paging
As a complete module is loaded all at once, segmentation improves CPU utilization.
The user specifies the segment size, whereas, in paging, the hardware determines the page size.
Flexibility
Protection: Segmentation provides a level of protection between segments, preventing one
process from accessing or modifying another process’s memory segment. This can help increase
the security and stability of the system.
SEGMENTATION
Disadvantages:
External Fragmentation is there
Costly memory management technique
Memory is not being utilized efficiently
When the segments are of different sizes they cannot undergo the process of
swapping.
More complex to implement and manage than paging
Overhead: Using a segment table can increase overhead and reduce
performance. Each segment table entry requires additional memory, and
accessing the table to retrieve memory locations can increase the time needed
for memory operations.
VIRTUAL MEMORY
A virtual memory is what its name indicates- it is an illusion of a memory
that is larger than the real memory.
Virtual memory software component as a virtual memory manager.
Noncontiguous memory allocation model.
It removes some components from memory to make room for other
components.
It is a technique that is implemented using both hardware and software. It
maps memory addresses used by a program, called virtual addresses, into
physical addresses in computer memory.
VIRTUAL MEMORY
Advantages: When entire program is not required to be loaded fully in main memory
Programmer should not worry about the size of available physical memory
Bigger size Program easily executed
Reduces the external fragmentation
Each user program could take less physical memory, more programs could be run the same
time, with a corresponding increase in CPU utilization and throughput.
Amount of the space in used by a process maybe varied during its memory residence
Degree of multiprogramming increased
Virtual Memory implemented by Demand Paging
VIRTUAL MEMORY
DEMAND PAGING
Demand paging can be described as a memory management technique that is used in operating
systems to improve memory usage and system performance.
Demand paging is a technique used in virtual memory systems where pages enter main
memory only when requested or needed by the CPU.
In demand paging, the operating system loads only the necessary pages of a program into
memory at runtime, instead of loading the entire program into memory at the start.
A page fault occurred when the program needed to access a page that is not currently in
memory. The operating system then loads the required pages from the disk into memory and
updates the page tables accordingly.
This process is transparent to the running program and it continues to run as if the page had
always been in memory.
DEMAND PAGING
Pure demand paging is a specific implementation of demand paging.
The operating system only loads pages into memory when the program needs them.
In on-demand paging only, no pages are initially loaded into memory when the program
starts, and all pages are initially marked as being on disk.
WORKING DEMAND PAGING
Program Execution: Upon launching a program, the
operating system allocates a certain amount of memory to
the program and establishes a process for it.
Creating page tables: To keep track of which program
pages are currently in memory and which are on disk, the
operating system makes page tables for each process.
Handling Page Fault: When a program tries to access a
page that isn’t in memory at the moment, a page fault
happens. In order to determine whether the necessary page is
on disk, the operating system pauses the application and
consults the page tables.
Page Fetch: The operating system loads the necessary
page into memory by retrieving it from the disk if it is there.
WORKING DEMAND PAGING
The page’s new location in memory is then reflected in the page table.
Resuming the program: The operating system picks up where it left off when the
necessary pages are loaded into memory.
Page replacement: If there is not enough free memory to hold all the pages a program
needs, the operating system may need to replace one or more pages currently in memory
with pages currently in memory. on the disk. The page replacement algorithm used by the
operating system determines which pages are selected for replacement.
Page cleanup: When a process terminates, the operating system frees the memory
allocated to the process and cleans up the corresponding entries in the page tables.
WHAT IS PAGE FAULT?
The term “page miss” or “page fault” refers to a situation where a referenced page is not
found in the main memory.
The missed page must be accessed by the CPU from the secondary memory.
The system’s effective access time will increase significantly if there are a lot of page
faults.
THRASHING
Thrashing in OS is a phenomenon that occurs in
computer operating systems when the system
spends an excessive amount of time swapping data
between physical memory (RAM) and virtual
memory (disk storage) due to high memory demand
and low available resources.
Causes of thrashing:
[Link] degree of multiprogramming.
[Link] of frames.
[Link] replacement policy.
ALLOCATION OF
FRAMES
The absolute minimum number of frames that a process must be allocated is dependent on
system architecture.
The maximum number is defined by the amount of available physical memory.
ALLOCATION ALGORITHMS
After loading of OS, there are two ways in which the allocation of frames can be done to the
processes.
Equal Allocation- If there are m frames available and n processes to share them, each
process gets m / n frames, and the left over’s are kept in a free-frame buffer pool.
Proportional Allocation - Allocate the frames proportionally depending on the size of the
process. If the size of process i is Si, and S is the sum of size of all processes in the system,
then the allocation for process Pi is ai= m * Si/ S. where m is the free frames available in the
ALLOCATION OF FRAMES
Example : Consider a system with a 1KB frame size. If a small student process of 10 KB and
an interactive database of 127 KB are the only two processes running in a system with 62 free
frames.
SOLUTION:
With proportional allocation, we would split 62 frames between two processes, as follows
m=62, S = (10+127)=137
Allocation for process 1 = 62 X 10/137 ~ 4 Allocation for process 2 = 62 X 127/137 ~57
Thus allocates 4 frames and 57 frames to student process and database respectively.
NOTE: Variations on proportional allocation could consider priority of process rather than just
their size.
ALLOCATION OF FRAMES
GLOBAL VERSUS LOCAL ALLOCATION
Page replacement can occur both at local or global level.
With local replacement, the number of pages allocated to a process is fixed, and page
replacement occurs only amongst the pages allocated to this process.
With global replacement, any page may be a potential victim, whether it currently
belongs to the process seeking a free frame or not.
Local page replacement allows processes to better control their own page fault rates,
and leads to more consistent performance of a given process over different system load
levels
Global page replacement is over all more efficient, and is the more commonly used
approach.
THANK YOU