Faculty of Computer Science Institute for System Architecture, Operating Systems Group. Memory. Björn Döbel. Dresden,

Similar documents
Memory, IPC, and L4Re

µ-kernel Construction (12)

MICROKERNEL CONSTRUCTION 2014

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

Microkernel-based Operating Systems - Introduction

Microkernel-based Operating Systems - Introduction

Microkernel Construction. Introduction. Michael Hohmuth. Lars Reuther. TU Dresden Operating Systems Group

Microkernel-based Operating Systems - Introduction

Practical Exercise Inter-Process Communication

Microkernel Construction

Inter-Process Communication

The SawMill Framework for Virtual Memory Diversity

Faculty of Computer Science Institute for System Architecture, Operating Systems Group. Complex Lab Operating Systems 2016 Winter Term.

L4Env An Environment for L4 Applications

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

Inter-Process Communication

Systems Design and Implementation II.1 L4 API Crash Course Part I

DRAFT. 27th July :43. L4 User Manual API Version X.2. Ihor Kuz

L4 User Manual API Version X.2

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

RESOURCE MANAGEMENT MICHAEL ROITZSCH

Virtual Memory Paging

RESOURCE MANAGEMENT MICHAEL ROITZSCH

Fundamental Concepts. L4 Programming Introduction. Root Task. KernelInterface. Kernel Information Page. Drivers at User Level

Falling in Love with EROS (Or Not) Robert Grimm New York University

L4 User Manual NICTA L4-embedded API

CSE 120 Principles of Operating Systems

CSE 560 Computer Systems Architecture

Pintos Virtual Memory

@2010 Badri Computer Architecture Assembly II. Virtual Memory. Topics (Chapter 9) Motivations for VM Address translation

Fakultät Informatik Institut für Systemarchitektur, Betriebssysteme THE NOVA KERNEL API. Julian Stecklina

Inter-Process Communication

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

Faculty of Computer Science Institute for System Architecture, Operating Systems Group. Memory Management & Program Loading

Virtual Memory Nov 9, 2009"

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

CS533 Concepts of Operating Systems. Jonathan Walpole

virtual memory Page 1 CSE 361S Disk Disk

Virtual Memory Oct. 29, 2002

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

CS162 - Operating Systems and Systems Programming. Address Translation => Paging"

CISC 360. Virtual Memory Dec. 4, 2008

Management of Revocable Resources. Romain Treboux

Computer Architecture Background

stack Two-dimensional logical addresses Fixed Allocation Binary Page Table

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

Complex Lab Operating Systems 2015/16 Winter Term. Sessions & Dynamic Memory

Lecture 19: Virtual Memory: Concepts

Faculty of Computer Science Institute for System Architecture, Operating Systems Group. Virtualization. Henning Schild. Dresden,

CS 152 Computer Architecture and Engineering. Lecture 11 - Virtual Memory and Caches

Recap: Memory Management

Microkernel Construction

Operating System. Operating System Overview. Structure of a Computer System. Structure of a Computer System. Structure of a Computer System

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

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

Threads (light weight processes) Chester Rebeiro IIT Madras

Processes & Threads. Recap of the Last Class. Layered Structure. Virtual Machines. CS 256/456 Dept. of Computer Science, University of Rochester

Operating System Architecture. CS3026 Operating Systems Lecture 03

Virtual Memory. Robert Grimm New York University

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

Stub-Code Performance is Becoming Important

Memory management, part 3: outline

6.033 Spring Lecture #6. Monolithic kernels vs. Microkernels Virtual Machines spring 2018 Katrina LaCurts

Linux Memory Management

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

Memory System Case Studies Oct. 13, 2008

INFLUENTIAL OPERATING SYSTEM RESEARCH: SECURITY MECHANISMS AND HOW TO USE THEM CARSTEN WEINHOLD

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018

Pentium/Linux Memory System March 17, 2005

CS140 Project 3: Virtual Memory. TA: Diveesh Singh

L4 Nucleus Version X Reference Manual. x86

Microkernel Design A walk through selected aspects of

IPC Functionality & Interface Universität Karlsruhe, System Architecture Group

Memory management, part 3: outline

Virtual Memory, Address Translation

Advanced Operating Systems. COMP9242 Introduction

CSE 120 Principles of Operating Systems Spring 2017

Staff. Advanced Operating Systems. Why are you here? What can you expect?

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

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Intel P6 (Bob Colwell s Chip, CMU Alumni) The course that gives CMU its Zip! Memory System Case Studies November 7, 2007.

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

G Virtual Memory. Robert Grimm New York University

CIS Operating Systems Memory Management Cache and Demand Paging. Professor Qiang Zeng Spring 2018

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

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

Outline. 1 Details of paging. 2 The user-level perspective. 3 Case study: 4.4 BSD 1 / 19

Intel P The course that gives CMU its Zip! P6/Linux Memory System November 1, P6 memory system. Review of abbreviations

Memory management. Knut Omang Ifi/Oracle 10 Oct, 2012

ECE331: Hardware Organization and Design

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical Memory

Hardware OS & OS- Application interface

P6/Linux Memory System Nov 11, 2009"

Project 2! CSE 421/521 - Operating Systems! Virtual Memory in Pintos

Operating Systems Overview. Chapter 2

Today. Process Memory Layout. CSCI 4061 Introduction to Operating Systems. Where does the memory come from?

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2017

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Microkernels and Client- Server Architectures

Transcription:

Faculty of Computer Science Institute for System Architecture, Operating Systems Group Memory Björn Döbel Dresden, 2013-11-05

So far... Introduction Monolithic vs. microkernels L4 concepts: Threads and IPC Fiasco.OC/TUDOS introduction Today: Memory Management Task creation Page-fault handling Flexpages Hierarchical pagers Region manager Dataspaces TU Dresden, 2013-11-05 MOS - Memory Slide 2 / 47

Task Creation TU Dresden, 2013-11-05 MOS - Memory Slide 3 / 47

Address Space Layout 4GB 3GB Kernel Area Thread needs to access code/data/stack/ to execute Stack ESP 0 Code Data EIP Moe Root Task Sigma0 Root Pager Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 4 / 47

Create Task and Thread /* Create a new task. */ l4_msgtag_t L4::Factory::create_task (Cap< Task > const & task_cap, ) l4_fpage_t const & l4_utcb_t utcb_area, *utcb = l4_utcb() /* Create a new thread. */ l4_msgtag_t L4::Factory::create_thread (Cap< Thread > const & target_cap, l4_utcb_t *utcb = l4_utcb() ) TU Dresden, 2013-11-05 MOS - Memory Slide 5 / 47

Start new Thread /* Commit the given thread-attributes object. */ l4_msgtag_t L4::Thread::control (Attr const & attr) /* Exchange basic thread registers. */ l4_msgtag_t L4::Thread::ex_regs (l4_addr_t ip, /* instruction pointer */ ) l4_addr_t sp, /* stack pointer */ l4_umword_t flags, l4_utcb_t *utcb = l4_utcb() TU Dresden, 2013-11-05 MOS - Memory Slide 6 / 47

L4::Thread::ex_regs 4GB 3GB Kernel Area ESP EIP 0 L4::Thread::ex_regs Moe Root Task Sigma0 Root Pager Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 7 / 47

First thread executes... 4GB 3GB Kernel Area CPU tries to fetch instruction Page fault exception at EIP ESP EIP 0 Moe Root Task Sigma0 Root Pager Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 8 / 47

Page Fault Handling TU Dresden, 2013-11-05 MOS - Memory Slide 9 / 47

Page-fault handling EIP Application s address space Page fault exception is caught by kernel page-fault handler No management of user memory in kernel Invoke user-level memory management Pager Fiasco.OC Microkernel Page Fault Handler TU Dresden, 2013-11-05 MOS - Memory Slide 10 / 47

Pager Thread which is invoked on page fault Fiasco.OC: each thread has a (potentially different) pager assigned Application s address space Pager s address space Pager Memory Pager Code Fiasco.OC Microkernel Page Fault Handler TU Dresden, 2013-11-05 MOS - Memory Slide 11 / 47

Pager Invocation Communication with pager thread using IPC Kernel page fault handler sets up IPC to pager Pager sees faulting thread as sender of IPC Application s address space Pager s address space Pager Memory Pager Code call(fault address, fault eip) Fiasco.OC Microkernel Page Fault Handler TU Dresden, 2013-11-05 MOS - Memory Slide 12 / 47

Page-fault IPC UTCB[0] fault address / 4 (30) w p UTCB[1] faulting EIP (32) w = 0 w = 1 p = 0 p = 1 read page fault write page fault no page present page present TU Dresden, 2013-11-05 MOS - Memory Slide 13 / 47

Pager's Reply Pager maps pages of it's own address space to the application's address space Flexpage IPC enables these mappings Application s address space Pager s address space Pager Memory Pager Code Fiasco.OC Microkernel Page Fault Handler TU Dresden, 2013-11-05 MOS - Memory Slide 14 / 47

Page Mapping map() creates an entry in the receiver's address space pointing to the same page frame In hardware: page table entry Only valid pager address space entries can be mapped Application s address space Pager s address space map Virtual memory Virtual memory Physical memory Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 15 / 47

Page Granting Special case: grant pages (flag: L4_FPAGE_GRANT) Removes mapping from sender's address space Application s address space Pager s address space grant Virtual memory Virtual memory Physical memory Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 16 / 47

Page Granting Special case: grant pages (flag: L4_FPAGE_GRANT) Removes mapping from sender's address space ATTENTION: aliases remain Application s address space Pager s address space grant Virtual memory Virtual memory Physical memory Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 17 / 47

Page Unmap Removes entries to a page frame (fpage is specified in invoker's address space) Dedicated system call: do not need partner's consent Kernel tracks mappings in a database unmap Application s address space Pager s address space Virtual memory Virtual memory Physical memory Fiasco.OC Microkernel Mapping database TU Dresden, 2013-11-05 MOS - Memory Slide 18 / 47

Flexpages TU Dresden, 2013-11-05 MOS - Memory Slide 19 / 47

Flexpage Types Flexpages represent resources attached to an address space Flexpages in Fiasco.OC are used to describe: Memory pages I/O ports Capabilities Today: only flexpages for memory TU Dresden, 2013-11-05 MOS - Memory Slide 20 / 47

Flexpage IPC in Detail Size-aligned Size 2 size, smallest is hardware page Source and target area of a map IPC are described by flexpages Sender s Address Space l4_ipc_receive( ) page address (20) size (6) ~ (2) rights (4) Receiver s Address Space Receive Window send base (32) page address (20) size (6) ~ (2) rights (4) l4_ipc_send( ) TU Dresden, 2013-11-05 MOS - Memory Slide 21 / 47

Flexpage Offset Send flexpage is smaller than the receive window Target position is derived from send flexpage alignment and send base l4_ipc_send( ) l4_ipc_receive( ) send base (32) page address (20) size (6) ~ (2) rights (4) page address (20) size (6) ~ (2) rights (4) TU Dresden, 2013-11-05 MOS - Memory Slide 22 / 47

Flexpage Offset Send flexpage is larger than receive window Target position is derived from receive flexpage alignment and send base Send base depends on information about the receiver l4_ipc_send( ) l4_ipc_receive( ) send base (32) page address (20) size (6) ~ (2) rights (4) page address (20) size (6) ~ (2) rights (4) TU Dresden, 2013-11-05 MOS - Memory Slide 23 / 47

Page fault in detail Kernel page fault handler sets receive window to whole address space Pager can map more than just one page, where the page fault happened to the client Application's Address Space send base pf address page address (20) size (6) ~ (2) rights (4) Pager s Address Space Fiasco.OC Microkernel Page Fault Receive Window whole space Page Fault Handler TU Dresden, 2013-11-05 MOS - Memory Slide 24 / 47

Root task: Initial Pager Pages are mapped as they are needed demand paging Application s address space Root Task s address space esp Stack Memory eip Code Data App Code Section App Data Section Roottask Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 25 / 47

Basic Memory Management Initial pager can only implement basic memory management No knowlegde about application requirements Different requirements at the same time Missing services for advanced memory management e.g. no disk driver for swapping Build more advanced pagers on top of the initial one Pager hierarchy TU Dresden, 2013-11-05 MOS - Memory Slide 26 / 47

Hierarchical Pagers TU Dresden, 2013-11-05 MOS - Memory Slide 27 / 47

Pager Hierarchy Application Application Pager 3 Disk Driver Pager 1 Pager 2 Phys. Memory 1-to-1 mapped Root Task Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 28 / 47

Real World Example L 4 Linux implements Linux paging policy RT pager implements real-time paging policy (e.g. no swapping) L 4 Linux Applications L 4 Linux Applications Real-Time Applications Real-Time Applications Linux Swap Linux Paging L 4 Linux Kernel Server RT Pager Phys. Memory 1-to-1 mapped Initial Address Space Fiasco.OC Microkernel TU Dresden, 2013-11-05 MOS - Memory Slide 29 / 47

Region Mapper TU Dresden, 2013-11-05 MOS - Memory Slide 30 / 47

Virtual Memory Management Pager has to specify send base Pager needs to know client's address space layout No problems with only one pager (e.g. L 4 Linux) Possible conflicts if more than one pager manages an address space: Application Application Pager 3 Disk Driver Pager 1 Pager 2 Phys. Memory 1-to-1 mapped Initial Address Space Fiasco.OC Microkernel Virtual memory must be managed independent of pagers TU Dresden, 2013-11-05 MOS - Memory Slide 31 / 47

Region Map Per address space map that keeps track which part of the address space is managed by which pager Address space Region Map VM Region Pager Pager 1 Pager 2 <start, end> Pager 1 <start, end> Pager 2 <start, end> Pager 2 Pager 2 TU Dresden, 2013-11-05 MOS - Memory Slide 32 / 47

Region Mapper Intermediate pager that identifies which pager should handle a page fault Resides in the application's address space Region mapper is the pager of all threads of a task Application VM Region Pager Pager 1 Region Mapper Pager 1 <start, end> Pager 1 <start, end> Pager 2 <start, end> Pager 2 Pager Memory Pager 2 Pager 2 call( region mapper, pf addr, pf eip, ) Pager Code Fiasco.OC Microkernel Page-Fault Handler TU Dresden, 2013-11-05 MOS - Memory Slide 33 / 47

Region Mapper Region mapper calls the pager that is responsible Receive window gets restricted to the area managed by that pager No interference between different pagers Application VM Region Pager Pager 1 Region Mapper Pager 1 Pager 2 Pager 2 <start, end> Pager 1 <start, end> Pager 2 <start, end> Pager 2 Call(pager1, pf addr, pf eip, receive window,...) Pager Memory Pager Code Fiasco.OC Microkernel Page-Fault Handler TU Dresden, 2013-11-05 MOS - Memory Slide 34 / 47

High-level Memory Abstraction Memory management in terms of pages so far Application s view to memory: code / data sections memory mapped files anonymous memory (heaps, stacks, ) network / file system buffers Abstraction to map this view to low-level memory management TU Dresden, 2013-11-05 MOS - Memory Slide 35 / 47

Dataspaces TU Dresden, 2013-11-05 MOS - Memory Slide 36 / 47

Dataspaces Dataspace: unstructured data container Abstraction for anything that contains data: Files Anonymous memory I/O adapter memory Dataspaces are implemented by Dataspace Managers Dataspaces can be attached to regions of an address space TU Dresden, 2013-11-05 MOS - Memory Slide 37 / 47

Dataspace Manager DS Manager determines the semantic of a dataspace Each DS is the pager for its dataspaces Implements the paging policy (page replacement etc.) Dataspaces Dataspace Manager s Address Space ds 1 ds 2 Dataspace Manager s Memory TU Dresden, 2013-11-05 MOS - Memory Slide 38 / 47

Dataspaces & Region Mapper Region map keeps track which dataspaces are attached to which virtual memory regions Region mapper translates page faults to dataspace offsets Application s Address Space Dataspaces Dataspace Manager s Address Space Dataspace Manager 1 Dataspace 1 ds 1 Dataspace Manager 2 Dataspace 1 ds 2 Dataspace Manager s Memory Dataspace Manager 2 Dataspace 2 Region Map VM Region Dataspace <start, end> Dataspace Manager 1, 1 <start, end> Dataspace Manager 2, 1 <start, end> Dataspace Manager 2, 2 TU Dresden, 2013-11-05 MOS - Memory Slide 39 / 47

Dataspaces & Region mapper Region mapper propagates fault to dataspace manager's fault handler Dataspace fault (ds_manager_id, ds_id, offset) Application s Address Space Dataspaces Dataspace Manager s Address Space Dataspace Manager 1 Dataspace 1 ds 1 Dataspace Manager 2 Dataspace 1 ds 2 Dataspace Manager s Memory Dataspace Manager 2 Dataspace 2 Region Map VM Region Dataspace <start, end> Dataspace Manager 1, 1 <start, end> Dataspace Manager 2, 1 <start, end> Dataspace Manager 2, 2 TU Dresden, 2013-11-05 MOS - Memory Slide 40 / 47

Application's View on Dataspaces allocate / free dataspaces create / destroy dataspace semantic depends on dataspace type: anonymous memory: open (size) file: open (filename, mode, )... attach / detach dataspace create / remove entry in region map Makes dataspace contents accessible to application propagate capability grant access rights to other applications very easy shared memory implementation TU Dresden, 2013-11-05 MOS - Memory Slide 41 / 47

Application Address Spaces Application address spaces are constructed from several dataspaces: Application s Address Space Mmap ed File File System Files-System Buffers Code RO Data Data BSS Memory Manager Stack Memory TU Dresden, 2013-11-05 MOS - Memory Slide 42 / 47

Further Issues Page Allocation Algorithms List-based algorithms, bitmaps, trees, Page Replacement Algorithms Least-Recently-Used (LRU) Working Sets Clock Page allocation and replacement are implemented by dataspace managers Can have different strategies for the dataspaces of an application TU Dresden, 2013-11-05 MOS - Memory Slide 43 / 47

Memory sharing Memory sharing important for Shared libraries Data transfer between system components Different types of sharing Full sharing: all clients see modifications easy to implement, pager / dataspace manager grants access rights to pages / dataspaces Lazy copying of dataspaces copy-on-write TU Dresden, 2013-11-05 MOS - Memory Slide 44 / 47

Summary Closer look on tasks/threads: Creation Page-fault handling Flexpages Memory pages, I/O ports, Capabilities Structure Offset computation Pager hierarchy Region mapper & dataspaces TU Dresden, 2013-11-05 MOS - Memory Slide 45 / 47

More information Flexpages H.Härtig, J.Wolter, J.Liedtke: Flexible sized page objects, http://os.inf.tu-dresden.de/papers_ps/flexpages.pdf Dataspaces Mohit Aron, Yoonho Park, Trent Jaeger, Jochen Liedtke, Kevin Elphinstone, Luke Deller: The SawMill Framework for VM Diversity, ftp://ftp.cse.unsw.edu.au/pub/users/disy/ papers/aron_pjled_01.ps.gz TU Dresden, 2013-11-05 MOS - Memory Slide 46 / 47

Next Lesson Next lecture (12.11.): 'Real-Time Systems' TU Dresden, 2013-11-05 MOS - Memory Slide 47 / 47