Memory Management
Operating System
Contents
1
Memory Management
1.1 Memory Protection . . . . . . . . . . . . . . . . . . . .
1.2 Logical versus Physical Address Space . . . . . . . . . .
1.3 Swapping . . . . . . . . . . . . . . . . . . . . . . . . .
1.4 Memory Allocation . . . . . . . . . . . . . . . . . . . .
1.4.1 Multiple-Partition Allocation . . . . . . . . . . .
1.5 Paging . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.5.1 Paging with Translation Look-aside Boffer (TLB)
1.5.2 Protection in Paging . . . . . . . . . . . . . . .
1.5.3 shared Pages in Paging . . . . . . . . . . . . . .
1.6 Segmentation . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
1
2
3
3
3
4
6
6
6
7
Chapter 1
Memory Management
Memory is central to the operation of a modern computer system. Memory is a large array of
words or bytes, each with its own address.
A program resides on a disk as a binary executable file. The program must be brought
into memory and placed within a process for it to be executed Depending on the memory
management in use the process may be moved between disk and memory during its execution.
The collection of processes on the disk that are waiting to be brought into memory for execution
forms the input queue. i.e. selected one of the process in the input queue and to load that process
into memory.
1.1
Memory Protection
Figure 1.1: A pair of base and limit registers define the logical address space
For example, if the base register holds 300040 and the limit register is 120900, then the
program can legally access all addresses from 300040 through 420939(inclusive).
Figure 1.2: Hardware address protection with Base and Limit Registers
1.2
Memory Management Unit (MMU) is a runtime mapping for logical to physical address.
1.3. SWAPPING
1.3
Swapping
A process, can be swapped temporarily out of memory to a backing store, and then
brought back into memory for continued execution.
Switching a process from main memory to backing store is called swap out. Switching
a process from disk to main memory is called swap in.
The swap out and swap in process is called as swapping.
Swapping increases context switch.
1.4
Memory Allocation
The main memory must accommodate both the operating system and the various user
processes. The memory is usually divided into two partitions, one for the resident operating
system, and one for the user processes. Memory allocation takes place in any of the fallowing
ways.
1. Single-Partition Allocation
2. Multiple-Partition Allocation
Single-Partition Allocation: If the operating system is residing in low memory, and the
user processes are executing in high memory.
1.4.1
Multiple-Partition Allocation
1.5. PAGING
1.5
Paging
Paging is a memory-management scheme that permits the physical address space of a process
to be noncontiguous. External fragmentation is avoided by using paging.
Basic Method of Paging
The physical memory is broken into blocks of the same size called pages. The logical
memory breaks into blocks of same size called pages.
4
1.5. PAGING
1.5.1
The TLB contains only a few of the page-table entries. When a logical address is generated by the CPU, its page number is presented to the TLB.
If the page number is found, its frame number is immediately available and is used to
access memory. Finding a page number in TLB is known as TLB Hit.
5
1.5. PAGING
1.5.2
Protection in Paging
1.6. SEGMENTATION
frame. When the bit is set to"invalid," the cpu cant access the respective frame.
1.5.3
When more then one process can share the same code (same pages), it is called sa shared pages.
Reentrant code It is non self modifying code. It never changes during execution. Hence
reentrant code can be shared among various processes.
1.6
Segmentation
Every program is a collection of various segments like code, global variable, stack used,
standard library, user defined unctions, etc.
Segmentation is a memory-management scheme that supports this user view of memory.
A logical address space is a collection of segments.The logical address is consist of two
parts: segment id and an offset.
The segment table consist of segment base and a segment limit. The segment base contains the starting physical address where the segment resides in memory, whereas the
segment limit specifies the length of the segment.
1.6. SEGMENTATION