TCBs and Address-Space Layouts Universität Karlsruhe, System Architecture Group

Similar documents
µ-kernel Construction (12)

µ-kernel Construction

Microkernels. Overview. Required reading: Improving IPC by kernel design

2 nd Half. Memory management Disk management Network and Security Virtual machine

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

VIRTUAL MEMORY II. Jo, Heeseung

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

8/09/2006. µ-kernel Construction. Fundamental Abstractions. Thread Switch A B. Thread Switch A B. user mode A kernel. user mode A

Multiprocessor Solution

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

CS533 Concepts of Operating Systems. Jonathan Walpole

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

Microkernels and Portability. What is Portability wrt Operating Systems? Reuse of code for different platforms and processor architectures.

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Operating Systems, Fall

SE-292 High Performance Computing. Memory Hierarchy. R. Govindarajan

Address spaces and memory management

CSE 120 Principles of Operating Systems

MICROKERNEL CONSTRUCTION 2014

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

Virtual Memory 3. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. P & H Chapter 5.4

Memory Addressing. Pradipta De

Threads, System Calls, and Thread Switching

143A: Principles of Operating Systems. Lecture 6: Address translation. Anton Burtsev January, 2017

CS 318 Principles of Operating Systems

EECS 482 Introduction to Operating Systems

Virtual Memory. Samira Khan Apr 27, 2017

Virtual Memory: From Address Translation to Demand Paging

µ-kernel Construction

238P: Operating Systems. Lecture 5: Address translation. Anton Burtsev January, 2018

Virtual Memory. P & H Chapter 5.4 (up to TLBs) Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

Virtual Memory. CS 3410 Computer System Organization & Programming

Lecture 7. Xen and the Art of Virtualization. Paul Braham, Boris Dragovic, Keir Fraser et al. 16 November, Advanced Operating Systems

14 May 2012 Virtual Memory. Definition: A process is an instance of a running program

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

CSE 120 Principles of Operating Systems Spring 2017

Operating Systems. Week 9 Recitation: Exam 2 Preview Review of Exam 2, Spring Paul Krzyzanowski. Rutgers University.

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Virtual Memory 1. Virtual Memory

Virtual Memory 1. Virtual Memory

3.6. PAGING (VIRTUAL MEMORY) OVERVIEW

Virtual Memory. Robert Grimm New York University

Faculty of Computer Science, Operating Systems Group. The L4Re Microkernel. Adam Lackorzynski. July 2017

Cute Tricks with Virtual Memory

Chapter 8 Memory Management

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Topic 18: Virtual Memory

Main Memory: Address Translation

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Virtual Memory Review. Page faults. Paging system summary (so far)

Protection and System Calls. Otto J. Anshus

CS399 New Beginnings. Jonathan Walpole

a process may be swapped in and out of main memory such that it occupies different regions

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Virtual memory Paging

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

Topic 18 (updated): Virtual Memory

آنستیتیوت تکنالوجی معلوماتی و مخابراتی ICTI

Operating System Labs. Yuanbin Wu

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

Virtual Memory. CS61, Lecture 15. Prof. Stephen Chong October 20, 2011

IA32 Intel 32-bit Architecture

CS162 Operating Systems and Systems Programming Lecture 14. Caching (Finished), Demand Paging

CS 5523 Operating Systems: Memory Management (SGG-8)

19/09/2008. µ-kernel Construction. Fundamental Abstractions. user mode A kernel. user mode A kernel. user mode A kernel. user mode A kernel

Virtual memory - Paging

The process. one problem

Machines and Virtualization. Systems and Networks Jeff Chase Spring 2006

Memory Management Part 1. Operating Systems in Depth XX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

Chapter 8: Main Memory

x86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT

1. Creates the illusion of an address space much larger than the physical memory

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

Interrupts and System Calls

CPSC 213. Introduction to Computer Systems. The Operating System. Unit 2e

Enabling Hybrid Parallel Runtimes Through Kernel and Virtualization Support. Kyle C. Hale and Peter Dinda

Emulation 2. G. Lettieri. 15 Oct. 2014

Xen and the Art of Virtualization. CSE-291 (Cloud Computing) Fall 2016

Chapter 8: Memory-Management Strategies

Virtual Memory. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Memory management. Single process. Multiple processes. How to: All memory assigned to the process Addresses defined at compile time

CS 537 Lecture 2 Computer Architecture and Operating Systems. OS Tasks

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

CS399 New Beginnings. Jonathan Walpole

CS 153 Design of Operating Systems Winter 2016

Caching. From an OS Perspective. COMP /S2 Week 3

Memory Management. Dr. Yingwu Zhu

CS5460: Operating Systems

ECE 571 Advanced Microprocessor-Based Design Lecture 12

Transcription:

µ-kernel Construction (3) TCBs and Address-Space Layouts 1

Thread Control Blocks (TCBs) 2

Fundamental Abstractions Thread Address space What is a thread? How to implement it? 3

Construction Conclusion Thread state must be saved/restored on thread switch We need a Thread Control Block (TCB) per thread TCBs must be kernel objects TCBs implement threads We need to find Any thread s TCB using its global ID The currently executing thread s TCB (per processor) 4

TCB Structure MyselfGlobal MyselfLocal State Resources KernelStackPtr Scheduling ReadyList TimesliceLength RemainingTimeslice TotalQuantum Priority WakeupList Space PDirCache Stack[]??? Thread Id Local Id = &UTCB??? All threads ready to execute Round Robin Scheduler Address Space Optimization IA-32: %CR3 5

Construction Conclusion Thread state must be saved/restored on thread switch We need a Thread Control Block (TCB) per thread TCBs must be kernel objects TCBs implement threads We need to find Any thread s TCB using its global ID The currently executing thread s TCB (per processor) 6

Thread ID Thread number To find the TCB Thread version number To make thread IDs unique in time Thread No Version 7

Thread ID TCB Indirect via Table movl thread_id, %eax movl %eax, %ebx andl mask_thread_no, %eax movl thread_table(, %eax, 4), %eax cmpl Off_TCB_Myself(%eax), %ebx jnz invalid_thread_id id Thread Table Kernel User %eax Off_TCB_Myself(%eax) VersionTCB pointer Thread No %ebx If different, Thread ID is outdated 8

Thread ID TCB Direct Address movl thread_id, %eax movl %eax, %ebx andl mask_thread_no, %eax addl offset, %eax cmpl Off_TCB_Myself(%eax), %ebx jnz invalid_thread_id id Kernel TCB area User %eax Off_TCB_Myself(%eax) Ver 1 Thread TCB pointer No Ver 2 %ebx offset If different, Thread ID is outdated 9

Thread ID TCB Direct Address movl thread_id, %eax movl %eax, %ebx andl mask_version, %eax shrl threadno_shift, %eax addl offset, %eax Kernel TCB area User %eax Thread TCB NopointerVersion Mask out lower bits Bitshift Add offset offset 10

Thread ID Translation Via Table No MMU required Table access per TCB Many TCBs per TLB entry (TCBs on superpages) TLB entry for table TCB pointer array requires 1M virtual memory for 256k potential threads Examples: 4 kb pages, 4 kb TCBs 1 TCB per TLB entry 16 kb pages, 2 kb TCBs 8 TCBs per TLB entry Via Computation Requires MMU No table access Few TCBs per TLB entry (sparsely populated area) Virtual TCB array may require 256M virtual memory for 256k potential TCBs 11

0-Mapping Trick Indirect Addressing TCB Pointer Array (virtual memory) n m p q r 0 Physical Memory Frames containing pointers to/virtual addresses of TCBs. TCB pointer array requires 1M virtual memory for 256k potential threads s cmpl Off_TCB_Myself(%eax), %ebx jnz invalid_thread_id Allocate physical parts of table on demand Dependent on the max. number of allocated TCBs Map unused parts to a 0-filled read-only (r/o) page Any access to unused threads will result in a NULL pointer Requires extra check à la cmpl %eax, 0; jnz invalid Or: Map unused parts to a r/o page filled with pointers to a 0-filled r/o page Any access to unused threads will result in an invalid thread ID (0) Avoids additional check 12

0-Mapping Trick Direct Addressing Allocate physical memory for TCBs on demand Dependent on the max. number of allocated TCBs Map all remaining TCBs to a 0-filled read-only page Any access to unused threads will result in invalid thread ID (0) Avoids additional check TCB Array (virtual memory) n m p q r 0 Physical Memory Frames containing TCBs. Virtual TCB array may require 256M virtual memory for 256k potential TCBs s 13

Current State (IA-32) Virtual TCB array 18 bit TIDs, 14 bit version number Max. 256k concurrent threads 2 kb per TCB Includes kernel stack Only ~256 B for the TCB proper 512 MB virtual memory 50% of the kernel address space 14

Basic Address-Space Layout 15

Address-Space Layout 32 bit, Virtual TCB Array User regions Shared system regions Per-space system regions Other kernel tables Physical memory Kernel code TCBs phys mem 16

Shared Region Synchronization We have Regions shared among all address spaces Separate page table per address space Updates occur in dynamic region May lead to inconsistencies We need Some form of synchronization within dynamic region Make sure valid virtual memory mappings are synchronized phys mem Dynamic region Static region 17

TCB Area Synchronization Basic Algorithm Dedicate one table as master Synchronize with master table on page faults Page fault algorithm: if (master entry valid) { copy entry from master } else { create new entry in master copy entry from master } Master Table Dynamic region Static region 18

TCB Area Synchronization Algorithm with 0-Mappings Use 0-mappings for invalid TCBs Thread creation requires TCB modification Create 0-mappings on read faults Create TCB mappings on write faults if (master entry not valid) { create if (read new fault) entry { in master } create 0-mapping in master copy } entry else { from master create TCB entry in master } } copy entry from master Master Table Dynamic region Static region 19

TCB Area Synchronization Modifying Mappings Removing or modifying mappings can not be handled lazily Must be handled brute force Avoid removing mappings (i.e., do not remove TCB mappings) Potential problem Create 0-Mappings (invalid TCBs) Operation incorrectly fails 0 0 0 Create a real TCB mapping 0-Mappings must now be updated 0 Master Table 0 Dynamic region Static region 20

TCB Area Synchronization Modifying Mappings Page tables have multiple levels IA-32: page directories and page tables We only synchronize top level (page directory) Modifications in lower levels visible iibl in all spaces ptab 0 ll ptab ptab Conclusion: Synchronization of pdirs solves the modification problem pdir pdir 21

Processor-Specific Memory Certain objects and variables should be processor local Ready queues, CPU ID, etc. Prevents cache conflicts Will require frequent access Solution: per-cpu memory regions Same virtual address Different backing store Avoids indirection table (i.e., no extra memory access) 22

Processor-Specific Memory One page table per CPU Most content identical Requires synchronization (eagerly or lazily) Synchronization at page directory level Small memory region is CPU specific Physical Memory 23

Limitations 32 bit, Virtual TCBs L4Ka::Pistachio/IA-32 TCB area size 256k threads 256 MB physical memory window Accessible at virtual address = physical address + offset Remaining physical memory not directly kernelaccessible Available for users and paged kernel data (e.g., TCBs) 3 GB 256 MB 512 MB 256 MB phys mem 24

Physical Memory Window Used by the kernel for Page tables Kernel memory Kernel debugger Only when kernel accesses physical addresses Limit valid physical range to remap size (256 MB) Or Map and unmap Copy IPC Address spaces (TCBs) KDB output Mem Dump 25

Physical-to-Virtual Pagetable Remap kernel-used pages Obtain virtual from physical address Walk physical-to-virtual ptab in software Access physical memory via virtual address Costs? Cache, TLB, runtime 26

Kernel Debugger (not performance critical) Might want/need to access memory (maybe in different address space) Walk page table in software Remap on demand (4 MB) Optimization: check if already mapped phys mem 27

Booting 28

OS Booting irq0 irq1 OS root L4 init L4 OS L4 init L4 tables 29

Microkernel Booting Microkernel initialization L4 init L4 OS L4 init L4 tables 30

Microkernel Booting Boot loader (e.g., Grub) Microkernel initialization Basic memory Basic VM Exception handling Processor (+ coprocessor) Hardware interrupts TCBs Dispatching Create 0 & root task Release memory of init code Start 0 & root Build boot Pagetable Switch to virtual mode IDT KDebug Check features GDT MSRs (sysenter/sysexit) FPU Local timer interrupt CPU-local pagetable IO-APIC/PIC Initialize first TCB switch_to Init ready list Init wakeup list 31

Case study: IA-64 Address Space Layout and Memory Management 32

IA-64 Address Space Layout 63 61 60 Virtual Address 0 Unimplemented bits Region Registers rr 0 rr 7 Selects various region settings Region ID Address Space Identifier (ASID) Avoids TLB flushing 33

IA-64 Address Space Layout 63 61 60 Virtual Address 0 Region Registers rr 0 User memory (task A) B) Copy area (later lecture) rr 7 TCB memory Uncacheable phys. memory Kernel/physical memory 34

IA-64 Address Translation 63 61 60 Virtual Address 0 Region Registers rr 0 RID vaddr RID vaddr paddr rights attrib size No need to flush TLB kern A rr 7 B kern A TCB B Translation Lookaside Buffer 63 Physical Address 0 35

IA-64 TLB Pinning 63 61 60 Virtual Address 0 Region Registers rr 0 rr 7 Translation Lookaside Buffer RID vaddr paddr rights attrib size kern A B kern A TCB B No TLB faults on kernel memory tr 0 tr 1 tr n 36

IA-64 Kernel Region Distance may be too far 7 2 61 2 64 n fixed idempotent mappings Fixed mapping for CPU-local memory paddr = vaddr 7 2 61 37

IA-64 Kernel Region May overlap with existing mapping 7 2 61 2 64 n fixed idempotent mappings 38

IA-64 Kernel Region Syscall page 7 2 61 2 64 offset n fixed idempotent mappings paddr = vaddr 7 2 61 offset 39