6-10 Flashcards
(157 cards)
What is memory virtualization?
(3)…
- OS virtualizes its physical memory
- OS provides an illusion of memory space per each process
- It is as if each process can access the entire memory space
Memory virtualization benefits:
(3)…
• Ease of use in programming
• Memory efficiency in terms of time and space
• The guarantee of isolation for processes as well as OS
- Protection from errant accesses of other processes
Early OSes:
• Load __ in memory
- Poor utilization and efficiency
only one process
Multiprogramming and Time Sharing: Load multiple processes in memory: (3)... Causes an important protection issue: ...
- Execute one for a short while
- Switch processes between them in memory
- Increase utilization and efficiency;
• Errant memory accesses from other processes
Address Space:
The OS creates an __ of physical memory
• The address space contains all the information about a running process
- program code, heap, stack and etc.
Address Space: Code: (1)... Heap: (1)... Stack: (2)...
1. Code • Where instructions live 2. Heap • Dynamically allocate memory - malloc in C - new in Java 3. Stack • Store return addresses or values • Contain local variables and arguments to functions
Virtual Address:
Every address in a running program is __.
OS translates the __ to __.
virtual;
virtual address;
physical address
—
#include [LTS]stdio.h>
#include [LTS]stdlib.h>
// Compile with: gcc -Og -no-pie -o print_address print_address.c
int main(int argc, char *argv[]){
int x = 3; // allocated on the stack frame of main()
printf(“location of code : %p\n”, (void *) main);
printf(“location of heap : %p\n”, (void *) malloc(1));
printf(“location of stack : %p\n”, (void *) &x);
return x; // so compiler doesn’t optimize x away
}
• The output in 64-bit Linux machine:
9/23/2019 CMPU 335 – Operating Systems 8
location of code : 0x4005c7
location of heap : 0x1623670
location of stack : 0x7fff633fbe54
Memory Virtualization Overview:
(4)…
• Just like the CPU, memory is virtualized
• Every address generated by a user program is a virtual address
• Virtual memory provides the illusion of a large private address space to
programs
- For instructions and data
• The OS, with help from the hardware translates each virtual memory
address to an actual physical address
- Protects and isolates processes from each other
- And from the kernel
Memory Virtualizing with Efficiency and Control:
In memory virtualizing, efficiency and control are attained by __.
• E.g., registers, TLB (Translation Look-aside Buffer)s, page-table
• Control means no process is allowed to access any memory but its own
Address Translation:
Mechanism: __
• Hardware transforms __
• The desired information is actually stored in a __
hardware-based address translation;
a virtual address to a physical address;
physical address
The OS must get involved at key points to set up the hardware
• The OS manages __
• Keeps track of __
memory;
which locations are free and which are in use
Example: Address Translation
void func() int x = 3000; x = x + 3; // this is the line of code we are interested in ...
(3)…
- Load a value from memory
- Increment it by three
- Store the value back into memory
Example: Address Translation
void func() int x = 3000; x = x + 3; // this is the line of code we are interested in
Assembly:
…
128 : movl 0x0(%ebx), %eax ; load 0+ebx into eax
132 : addl $0x03, %eax ; add 3 to eax register
135 : movl %eax, 0x0(%ebx) ; store eax back to mem
• Presume that the address of ‘x’ has been place in ebx register
• Load the value at that address into eax register
• Add 3 to eax register
• Store the value in eax back into memory
—
5 memory references just to add 3 to a number!:
• Fetch instruction at address 128
• Execute this instruction (load from address 15KB)
• Fetch instruction at address 132
• Execute this instruction (no memory reference)
• Fetch the instruction at address 135
• Execute this instruction (store to address 15 KB)
- Base and bounds also called __
* Bounds register also called __
dynamic relocation;
limit register
Dynamic (Hardware base) Relocation:
When a program starts running, the OS decides __.
• Sets the base register accordingly
𝑝ℎ𝑦si𝑐𝑎𝑙 𝑎𝑑𝑑𝑟𝑒𝑠𝑠 = __
• Every virtual address must not be greater than __
where in physical memory a process should be loaded;
𝑣𝑖𝑟𝑡𝑢𝑎𝑙 𝑎𝑑𝑑𝑟𝑒𝑠𝑠 + 𝑏𝑎𝑠e;
bound and negative:
0 ≤ 𝑣𝑖𝑟𝑡𝑢𝑎𝑙 𝑎𝑑𝑑𝑟𝑒𝑠𝑠 < 𝑏𝑜𝑢𝑛𝑑s
Relocation and Address Translation:
128 : movl 0x0(%ebx), %eax
(2)…
• Fetch instruction at address 128 (virtual address):
32896 = 128 + 32𝐾𝐵(𝑏𝑎𝑠𝑒)
• Execute this instruction
- Load from address 15KB (virtual address)
47𝐾𝐵 = 15𝐾𝐵 + 32𝐾𝐵(𝑏𝑎𝑠𝑒)
Two ways to check Bounds:
(2)…
- Either hold the size of the address space or the physical address of the end of the address space
- Depends on whether you bounds check before or after translation
The OS must take action to implement base-and-bounds approach
• Three critical junctures:
(3)…
• When a process starts running:
- Finding space for address space in physical memory
• When a process is terminated:
- Reclaiming the memory for use
• When context switch occurs:
- Saving and storing the base-and-bounds pair
OS Issues: When a Process Starts Running
- The OS must find __
- free list : __
a room for a new address space;
A list of the range of the physical memory which are not in use
OS Issues: When a Process Is Terminated
• The OS must __
put the memory back on the free list
OS Issues: When Context Switch Occurs:
• The OS must __
- In __
save and restore the base-and-bounds pair;
process structure or process control block (PCB)
Address Translation Overview:
- Extend limited direct execution with address translation
(1) … - Hardware support is necessary
(2) … - Base and bounds is efficient and offers protection
(2) …
- Extend limited direct execution with address translation
• Can control each and every memory access from a process - Hardware support is necessary
• Process has no idea memory references are being translated
• Part of the memory management unit (MMU) of a processor - Base and bounds is efficient and offers protection
• Suffers from internal fragmentation due to fixed-sized slots
• This leads us to segmentation, a generalization of base and bounds
Inefficiency of the Base and Bound Approach:
(3)…
- Big chunk of “free” space
- “free” space takes up physical memory
- Hard to run when an address space does not fit into physical memory
Segment is just a __.
contiguous portion of the address space of a particular length
• Logically-different segments: code, stack, heap