Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Memory Management

Operating Systems
Approaches to Memory Management

• Contiguous allocation

• Paging
Contiguous Allocation
• Memory to each process is allocated
contiguously
• Each process gets one big block of memory

• Contiguous allocation is simple


• However, suffers from fragmentation
Paging
• A process can be allocated chunks of memory
scattered across the RAM

• There is no fragmentation

• Paging is complex, and may need hardware


support
Basic Functions of a Memory Manager

• Memory protection

• Address translation
Memory Protection

• Operating system checks for illegal memory


access

• A process cannot access memory of any other


process
Address Translation
• Operating system converts logical (relative)
addresses into physical (absolute) addresses

• Addresses in each memory-referencing


instruction (load, store, etc) need to be translated

• Hardware support is required for efficient


translation
Logical Addresses
• When compiler translates a high-level
program into machine code, it cannot know
the exact location at run-time

• Compiler generates logical addresses

• Logical addressing is a simple numbering of


each byte of a program
Example
• char c; // address 0
• char d; // address 1
• char e; // address 2
• ... // ...
Physical Addresses
• Physical addresses are actual addresses in
RAM

• Physical addresses can be different for each


run

• Depend upon location of the available


memory
Example – Physical Addresses
Variable Address Address
c 10 55
d 11 56
e 12 57
Contiguous Allocation
• How address is translated in contiguous
allocation?

• How memory is protected?


Address Translation in Contiguous Allocation

• A base address is added to each logical


address
• Base address is the starting address of the
location

Physical address = Logical address + Starting address


Memory Protection in Contiguous Allocation

• The system checks whether a given address is


within limit

• This check needs to be performed for every


memory-referencing instruction

• Hardware support is required for efficiency


Memory Management Unit
• MMU is a piece of hardware that helps in
– Address translation
– Memory protection
• It has two registers
– Base register (relocation register)
– Limit register
• Operating systems sets these registers during
a context switch
Base and Limit Registers

Source: Operating Systems by Silberschatz et al


Memory Management Unit ...
• During execution of each memory-referencing
instruction
– MMU checks address for limit
– MMU performs address translation
Memory Management Unit ...

Source: Operating Systems by Silberschatz et al


How MMU Protects Memory

Source: Operating Systems by Silberschatz et al


Summary
• Contiguous allocation

• Address translation

• Memory protection

• Memory management unit


Upcoming next ...
• Paging
– Introduction
– Memory protection
– Address translation
– TLB
The End

You might also like