Operating System Three easy pieces Remzi H ArpaciDusseau
- Slides: 44
Operating System : Three easy pieces Remzi H. Arpaci-Dusseau Andrea C. Arpaci-Dusseau Beyond Physical Memory: Mechanisms Seong. Jae Park (sjpark@dcslab. snu. ac. kr) School of Computer Science and Engineering Seoul National University
We dreamed a dream § I dreamed a dream § Every address space of every running process fits into physical memory § The life have killed the dream § Physical memory is smaller than address space, usually § For 32 bits system, 4 Gi. B address space § I have a dream! § Wish to support many concurrently-running large address spaces § TL; DR: Place to stash away portions of address spaces that currently aren’t in great demand § When, how the pages be stashed and be inserted to memory again? Operating System : Three easy pieces 2
Swap Space § Be reserved on the storage that larger, slower than main memory § Usually Hard Disk Drive § Space to stash away portions of address spaces § Swap pages out of memory to swap space, and swap pages into memory from swap space when necessary Operating System : Three easy pieces 3
Swap Space § Be reserved on the storage that larger, slower than main memory § Usually Hard Disk Drive § Space to stash away portions of address spaces § Swap pages out of memory to swap space, and swap pages into memory from swap space when necessary Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 1 [VPN 2] Proc 1 [VPN 3] Proc 2 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Proc 0 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Proc 1 [VPN 1] Proc 3 [VPN 0] Operating System : Three easy pieces 4
Swap Space § 4 pages in Memory Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 0 [VPN 1] Proc 0 [VPN 2] Free Block 0 Block 1 Block 2 Block 3 Block 4 Free Free Operating System : Three easy pieces 5
Swap Space § 4 pages in Memory Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 0 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Free Free Operating System : Three easy pieces 6
Swap Space § 4 pages in Memory Proc 1 needs second page Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 0 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Free Free Operating System : Three easy pieces 7
Swap Space § 4 pages in Memory Swap out vpn 1 of proc 0 Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Free Proc 0 [VPN 2] Proc 1 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Proc 0 [VPN 1] Free Operating System : Three easy pieces 8
Swap Space § 4 pages in Memory Load VPN 1 of Proc 1 Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 1 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Proc 0 [VPN 1] Free Operating System : Three easy pieces 9
The Present Bit § A bit in PTE(Page Table Entry) § Represents whether the page is in memory or not § If not, page fault will be incurred § The fault will be handled by page fault handler in OS Page table of Proc 0 Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 1 [VPN 2] Proc 1 [VPN 3] Proc 2 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Proc 0 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Proc 1 [VPN 1] Proc 3 [VPN 0] Operating System : Three easy pieces VPN Present 0 1 1 0 2 0 10
The Page Fault § Page Fault Handler in OS will service the case § Swap the page into memory from swap space § How will the OS know where to find the page? § Bits in PTE, usually PFN(Page Frame Number) Proc 0 VPN 1. . Oops! Page table of Proc 0 Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 1 [VPN 2] Proc 1 [VPN 3] Proc 2 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Proc 0 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Proc 1 [VPN 1] Proc 3 [VPN 0] Operating System : Three easy pieces VPN Present 0 1 1 0 2 0 11
What If Memory Is Full? § What if there are no page to be swapped in? § Page out one or more pages to make room for the new page § Follows page-replacement policy § Good page-replacement policy is important • Wrong decision cause a program to run at disk-like speeds(10, 000 x – 100, 000 x slower) Physical Memory Swap Space PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 0 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Proc 1 needs second page Block 0 Block 1 Block 2 Block 3 Block 4 Free Free Operating System : Three easy pieces 12
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . Operating System : Three easy pieces 13
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . Virtual Address VPN Operating System : Three easy pieces Offset 14
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . TLB(Translation Lookaside Buffer) Operating System : Three easy pieces VPN Tlb. Entry 0 0 xaabbc 5 0 xababb … … 15
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . TLB(Translation Lookaside Buffer) Hit!! Operating System : Three easy pieces VPN Tlb. Entry 0 0 xaabbc 5 0 xababb … … 16
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . TLB(Translation Lookaside Buffer) Operating System : Three easy pieces VPN Tlb. Entry 0 0 xaabbc 5 0 xababb … … Accessible!! 17
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . Virtual Address VPN Operating System : Three easy pieces Offset 18
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . Physical Address PFN Operating System : Three easy pieces Offset 19
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . Operating System : Three easy pieces 20
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . Operating System : Three easy pieces VPN Tlb. Entry 0 0 xaabbc 5 0 xababb … … Not Accessible!! 21
Page Fault Control Flow VPN = (Virtual. Address & VPN_MASK) >> SHIFT (Success, Tlb. Entry) = TLB_Lookup(VPN) if (Success == True) // TLB Hit if (Can. Access(Tlb. Entry. Protect. Bits) == True) Offset = Virtual. Address & OFFSET_MASK Phys. Addr = (Tlb. Entry. PFN << SHIFT) | Offset Register = Access. Memory(Phys. Addr) else Rasie. Exception(PROTECTION_FAULT) else. . . $. /protection_fault_program Segmentation fault (core dumped) $ Operating System : Three easy pieces 22
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 23
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 24
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 25
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 26
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 27
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 28
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 29
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 30
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 31
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 32
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 33
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 34
Page Fault Control Flow if (Success == True) // TLB Hit. . . else PTEAddr = PTBR + (VPN * sizeof(PTE)) PTE = Access. Memory(PTEAddr) if (PTE. Valid == False) Raise. Exception(SEGMENTATION_FAULT) else if (Can. Access(PTE. Protect. Bits) == False) Raise. Exception(PROTECTION_FAULT) else if (PTE. Present == True) TLB_Insert(VPN, PTE. PFN, PTE. Protect. Bits) Retry. Instruction() else if (PTE. Present == False) Raise. Exception(PAGE_FAULT) Operating System : Three easy pieces 35
Page Fault Control Flow PFN = Find. Free. Physical. Page() If (PFN == -1) PFN = Evict. Page() Disk. Read(PTE. Disk. Addr, pfn) PTE. present = True PTE. PFN = PFN Retry. Instruction() Operating System : Three easy pieces 36
Page Fault Control Flow PFN = Find. Free. Physical. Page() If (PFN == -1) PFN = Evict. Page() Disk. Read(PTE. Disk. Addr, pfn) PTE. present = True PTE. PFN = PFN Retry. Instruction() Operating System : Three easy pieces 37
Page Fault Control Flow PFN = Find. Free. Physical. Page() If (PFN == -1) PFN = Evict. Page() Disk. Read(PTE. Disk. Addr, pfn) PTE. present = True PTE. PFN = PFN Retry. Instruction() PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Proc 0 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Proc 1 [VPN 1] Free Physical Memory Swap Space Operating System : Three easy pieces 38
Page Fault Control Flow PFN = Find. Free. Physical. Page() If (PFN == -1) PFN = Evict. Page() Disk. Read(PTE. Disk. Addr, pfn) PTE. present = True PTE. PFN = PFN Retry. Instruction() PFN 0 PFN 1 PFN 2 PFN 3 Proc 0 [VPN 0] Free Proc 0 [VPN 2] Proc 1 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Proc 1 [VPN 1] Proc 0 [VPN 1] Free Physical Memory Swap Space Operating System : Three easy pieces 39
Page Fault Control Flow PFN = Find. Free. Physical. Page() If (PFN == -1) PFN = Evict. Page() Disk. Read(PTE. Disk. Addr, pfn) PTE. present = True PTE. PFN = PFN Retry. Instruction() Physical Memory Swap Space Will transit to wait status until the IO completes Proc 0 [VPN 0] Proc 1 [VPN 1] Proc 0 [VPN 2] Proc 1 [VPN 0] Block 0 Block 1 Block 2 Block 3 Block 4 Free Proc 0 [VPN 1] Free Operating System : Three easy pieces 40
Page Fault Control Flow PFN = Find. Free. Physical. Page() If (PFN == -1) PFN = Evict. Page() Disk. Read(PTE. Disk. Addr, pfn) PTE. present = True PTE. PFN = PFN Retry. Instruction() Operating System : Three easy pieces 41
Page Fault Control Flow PFN = Find. Free. Physical. Page() If (PFN == -1) PFN = Evict. Page() Disk. Read(PTE. Disk. Addr, pfn) PTE. present = True PTE. PFN = PFN Retry. Instruction() Operating System : Three easy pieces 42
When Replacements Really Occur § OS waits until memory is entirely full, and then evicts a page to make room for some other page § Unrealistic § Keep high watermark and low watermark § Start swap daemon if free memory < low watermark § Stop swap daemon if free memory > high watermark Operating System : Three easy pieces 43
Summary § Introduced the notion of accessing more memory than is physically present within a system § Requires more complexity in page-table structures § Present bit in PTE represents whether the page is in memory or not § If present bit == 0, page fault occur to give control to page-fault handler in OS § Actions all take place transparently to the process § Process is just accessing its own private, contiguous virtual memory § In the worst case, a single instruction could consume few milliseconds to complete Operating System : Three easy pieces 44
- Remzi h arpaci-dusseau
- Operating system three easy pieces
- Operating systems three easy pieces solution
- Inductive vs deductive reasoning
- Every quiz has been easy. therefore, the test will be easy.
- Every quiz has been easy. therefore, the quiz will be easy
- Remzi h arpaci-dusseau
- Remzi kulen youtube
- Remzi h. arpaci-dusseau
- Remzi h. arpaci-dusseau
- Remzi kulen
- Remzi can aksoy
- Greg remzi
- The three main parts of an essay
- Buddy system memory
- File system in operating system
- File system in operating system
- File system in operating system
- Easy access system ii
- Windows preemptive multitasking
- Integral subsystem
- ____________ is an example of operating system. *
- Benefits of operating system
- Multi tasking operating system
- Kernel block diagram
- Trusted operating system
- Tiny os
- System design principles
- Temple operating system
- Stand alone operating system
- Single user and multi user operating system
- Singularity operating system
- The operating system manages
- Gpos and rtos
- Security and protection in operating system
- System.net.peertopeer
- Components of operating systems
- Communication primitives in distributed operating system
- Virtual memory
- Process management in operating system
- Layered structure in os
- Threads in operating system
- Xv6 operating system
- P operating system
- Virtual memory in operating system