Lec 3: Virtualization & Containerization Flashcards
What are the relevant OS concepts?
Process scheduling
Virtual memory
What is a process?
A process is a program that is executed. It is a basic unit of execution in an OS.
What is process scheduling (time-sharing)?
-Each process is scheduled and executed within their time share.
-The number of processes can be much larger than that of the CPUs.
What are the different queues in process scheduling?
Job Queue
Ready Queue
I/O Waiting Queue > I/O
(then CPU > Exit)
Kernel mode: Ring number
Ring 0, most privileged
User mode: Ring number
Ring 3
Other: Ring 1 & 2
How many protection levels (rings) or CPU privilege levels (CPLs) does x86 has?
four: Ring 0 (most privileged) to 3
Modern OS (Linux, Windows, MacOS) only use ring 0 and 3
Kernel mode vs user mode: executing processes
When CPU is in the user mode, it cannot execute sensitive/privileged instructions (e.g., HLT = halt / stop the processor’s operations)
User Mode = User Processes
Kernel Mode = Process Scheduling
What is involved in a virtual memory implementation?
Process A
Virtual memory
Memory map
Physical memory
Disk
What is on-demand paging?
Only when there is a need to access code / data that the OS will allocate a physical page, otherwise the code / data will just be stored in the disk
What is swapping in / out?
The least recently used pages are swapped out from physical memory to the disk
What are the three steps to execute a process for the first time?
- CPU allocates a physical page based on the memory map
- CPU loads the corresponding data / code from disk to the allocated page
- CPU executes the code by fetching code from the allocated page
What is a memory map?
A memory map maintains the mapping between virtual and physical memory
What is a shared memory?
Two processes from virtual memory uses the same physical page, allowing exchanging of data
Memory map implementation
Page table
In a modern OS, the OS uses a set of page tables to map virtual memory within a process to their corresponding physical memory in main memory.
Used to map virtual memory within a process to a corresponding physical memory in main memory
Used to implement the memory map
Established by the memory management unit MMU (a hardware component)
All mappings are maintained as page tables
Virtual address VA
pointing to a page-aligned memory location in a virtual page.
Physical address PA
pointing to a page-aligned memory location in a physical page
What is MMU?
Memory management unit
Page tables reside in MMU
What is a page-aligned address?
In a page-aligned address, VA is mapped to PA via MMU.
Additional note: VA points to the base address of the virtual page
If VA = 0x60001000, then PA = 0x70001000
If VA1 = 0x60001800, then PA1 = 0x70001800 (same last 3 digits)
Memory map implementation: x86-32
Page table:
In a modern OS, the OS uses a set of page tables to map virtual memory within a process to their corresponding physical memory in main memory.
Has 2-level page tables: page directory + page table
32-bit version of x86, known as IA-32 (Intel Architecture 32-bit), where 32-bit virtual/linear addresses are used.
Division of the 32 bits:
31-22 (10 bits): index page directory; 2^10
21-12 (10 bits): index page table; 2^10
11-0 (12 bits): index physical page; will be the same last 12 bit of the physical page; the physical page is mapped to the virtual page where the linear address resides
size of entries: 2^12 / 2^10 = 2^2 = 4 bytes for a single entry
Memory map implementation: x86-64
63-48: sign-extended, same bit as bit47; allowed entries are 2^9
47-39: page map level 4 offset
38-30: page-directory pointer offset
29-21: page-directory offset
20-12: page-table offset
11-0: physical-page offset
size of entries: 2^12 / 2^9 = 2^3 = 8 bytes for a single entry
What is CR3?
Control register 3 stores the physical address of the base of the Page Directory (in x86-32) or the base of the Page-Map Level 4 (PML4) table (in x86-64).
This is essential because the memory management unit (MMU) starts its translation of a virtual address by referring to this base address.
What is virtualization?
Virtualization is the ability to run multiple operating systems on a single physical system and share the underlying hardware resources
Allows one computer software (called Virtual Machine Monitor or Hypervisor) to provide the appearance of many computers (called virtual machines).
What are the goals of virtualization?
Provide flexibility for users
Amortize hardware costs
Isolate completely separate users