CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 25

Similar documents
FILE SYSTEMS, PART 2. CS124 Operating Systems Winter , Lecture 24

FILE SYSTEMS, PART 2. CS124 Operating Systems Fall , Lecture 24

PROCESS VIRTUAL MEMORY PART 2. CS124 Operating Systems Winter , Lecture 19

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

P6/Linux Memory System Nov 11, 2009"

Memory System Case Studies Oct. 13, 2008

Pentium/Linux Memory System March 17, 2005

Virtual Memory: Systems

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

P6 memory system P6/Linux Memory System October 31, Overview of P6 address translation. Review of abbreviations. Topics. Symbols: ...

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

Foundations of Computer Systems

Virtual Memory: Systems

CSE 153 Design of Operating Systems

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23

seven Virtual Memory Introduction

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Applications of. Virtual Memory in. OS Design

OPERATING SYSTEM. Chapter 9: Virtual Memory

JOURNALING FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 26

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

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

Operating Systems: Internals and Design. Chapter 8. Seventh Edition William Stallings

Chapter 9: Virtual Memory

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

Process Environment. Pradipta De

CS 550 Operating Systems Spring Process II

CSE 120 Principles of Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

This lecture is covered in Section 4.1 of the textbook.

Process Address Spaces and Binary Formats

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

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

FFS: The Fast File System -and- The Magical World of SSDs

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Virtual Memory Paging

Operating System Design and Implementation Memory Management Part III

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Lecture 12: Demand Paging

Memory Mapping. Sarah Diesburg COP5641

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

IMPLEMENTATION OF SIGNAL HANDLING. CS124 Operating Systems Fall , Lecture 15

Lecture 19: Virtual Memory: Concepts

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

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

CS370 Operating Systems

Understanding the Design of Virtual Memory. Zhiqiang Lin

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Basic Memory Management

Virtual Memory III /18-243: Introduc3on to Computer Systems 17 th Lecture, 23 March Instructors: Bill Nace and Gregory Kesden

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

Chapter 1 Introduction

The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

CS420: Operating Systems

CONCURRENT ACCESS TO SHARED DATA STRUCTURES. CS124 Operating Systems Fall , Lecture 11

Memory Management - Demand Paging and Multi-level Page Tables

Virtual Memory III. Jo, Heeseung

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

Chapter 10: Virtual Memory

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Computer Systems Engineering: Spring Quiz I Solutions

CS 550 Operating Systems Spring Memory Management: Page Replacement

Paging and Page Replacement Algorithms

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Virtual Memory II CSE 351 Spring

Page Which had internal designation P5

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Operating System Concepts 9 th Edition

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

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Process and Its Image An operating system executes a variety of programs: A program that browses the Web A program that serves Web requests

CS 153 Design of Operating Systems

Memory Management. Fundamentally two related, but distinct, issues. Management of logical address space resource

Changelog. Virtual Memory (2) exercise: 64-bit system. exercise: 64-bit system

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

Kernels & Processes The Structure of the Operating System

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 13

Virtual Memory Outline

Operating Systems. IV. Memory Management

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

Storage Management 1

Processes and Virtual Memory Concepts

ECE 598 Advanced Operating Systems Lecture 10

Physical memory vs. Logical memory Process address space Addresses assignment to processes Operating system tasks Hardware support CONCEPTS 3.

CS307: Operating Systems

CSE 120 Principles of Operating Systems Spring 2017

Computer Systems. Virtual Memory. Han, Hwansoo

Exceptions and Processes

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

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

18-447: Computer Architecture Lecture 16: Virtual Memory

3. Process Management in xv6

virtual memory Page 1 CSE 361S Disk Disk

Transcription:

CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2015 Lecture 25

LAST TIME: PROCESS MEMORY LAYOUT! Explored how Linux uses IA32! All processes have a similar layout Each process has its own page table structure Different for Identical for 0xc0000000 %esp Process-specific data structures Kernel stack Mapping to physical Kernel code and global data User stack Kernel Processes have isolated address spaces Program entry-point is at 0x08048000 Program s stack grows down from 0xc0000000 0x40000000 brk Memory mapped region for shared libraries Run-time heap (via malloc) Uninitialized data (.bss) Initialized data (.data) Process 2 0x08048000 0 Program text (.text) Forbidden

LAST TIME: PROCESS MEMORY LAYOUT (2)! Kernel maps some of its own code and data into Data structures that all processes need Support for system calls Processes cannot access this directly!! Must use int 0x80 trap, or sysenter/syscall! Kernel also contains data specific to the process Page table for the process Kernel-stack for the process Different for Identical for 0xc0000000 %esp 0x40000000 brk 0x08048000 0 Process-specific data structures Kernel stack Mapping to physical Kernel code and global data User stack Memory mapped region for shared libraries Run-time heap (via malloc) Uninitialized data (.bss) Initialized data (.data) Program text (.text) Forbidden Kernel Process 3

PROCESS VIRTUAL MEMORY AREAS! Kernel maintains details about regions in Supplemental details beyond what is recorded in the IA32 page-directory structure task_struct mm mm_struct pgd mmap vm_area_struct vm_end vm_start vm_prot vm_flags vm_next Process Virtual Memory Shared Libraries! Kernel uses these details to resolve page faults and general protection faults Some faults are expected; can be recovered from Others are due to bad program behavior vm_end vm_start vm_prot vm_flags vm_next vm_end vm_start vm_prot vm_flags vm_next Data (.data,.bss) Run-time heap Program text (.text)

MEMORY MAPPING OBJECTS! In Linux, each area is associated with an object on disk: A regular file in the UNIX filesystem, such as a program binary or a shared library An anonymous file, presented by the kernel, containing only zero values! (Not an actual file, but presented via the file abstraction)! The anonymous file is used when a process allocates new pages (e.g. when the heap or stack is expanded) A victim page is evicted, and then the page s contents are overwritten with zero values Once a new page is allocated, it is saved to disk in a special swap area 5

MEMORY MAPPING OBJECTS (2)! The anonymous file is used when the kernel allocates new pages to a process! Reason: A process should never be able to see data from another process, unless it is explicitly shared! Example: a process that prompts the user for a password Another process allocates a page, which maps to the same physical page in DRAM but the password data wasn t overwritten before the second process gets the page!! The kernel must ensure that such situations cannot happen 6

SHARED AND PRIVATE OBJECTS! Objects can be mapped into a area as either a shared object or a private object Memory area that the shared object is mapped into is called a shared area Similarly, area that a private object is mapped into is called a private area! Multiple processes may be running same code (e.g. /bin/bash), or using same shared library (libc.so) Load the shared object into physical once, and then map it into the address space of multiple processes! Writes to a shared object are visible to all processes accessing the object! Writes will also modify the shared object stored on disk!! With shared objects, very important to enable writes only when appropriate! 7

SHARED AND PRIVATE OBJECTS (2)! When a process writes to a private object, only that process should see the modification Additionally, the change should not modify the private object on disk! A simple technique: Each time a specific private object is mapped into a process, load another copy into physical! This approach can become very expensive Particularly in situations where a specific private object is loaded into multiple processes, but none of the processes are making changes to the object!! A much better technique: copy-on-write 8

PRIVATE OBJECTS AND COPY-ON-WRITE! Like shared objects, a private object is initially loaded into physical only once Kernel sets the object s pages to be read-only, and flags the area as private copy-on-write! Example: Two processes using a private copy-on-write object Initially, object is loaded into physical only once! Both processes have area marked as read-only, private copy-on-write Process A Read-only, private-cow Physical Loaded, in- Private copy-onwrite object Object Process B Read-only, private-cow 9

PRIVATE OBJECTS, COPY-ON-WRITE (2)! When a process writes to a private copy-on-write page, this generates a general protection fault Process tried to write to a read-only page!! Kernel handles these faults in a special way: If write was to a read-only area that is also copy-onwrite, make a copy of the page that was accessed Create a new page Copy data from page into new page In the process page table, replace the page with new page! Now change is local to the writing process Process A Read-only, private-cow Physical Loaded, in- Private copy-onwrite object Object Process B Read-only, private-cow 10

PRIVATE OBJECTS, COPY-ON-WRITE (3)! Example: Process A writes to the private object! Kernel receives a general protection fault Process tried to write to a read-only page but, the page is flagged as private copy-on-write, so the kernel performs copy-on-write steps! Step 1: Allocate a new page, and copy the data into it Process A Physical Loaded, in- Process B write Read-only, private-cow Copy! Read-only, private-cow Private copy-onwrite object 11 Object

PRIVATE OBJECTS, COPY-ON-WRITE (3)! Step 2: Update Process A s space to reference the copied page, not the original Copied page is also marked read-write, not read-only! Step 3: Return from the protection-fault handler CPU retries the instruction that caused the fault, and this time it succeeds without any problems Process A Physical Process B Loaded, in- write Read-only, private-cow Copy A s copy Read-only, private-cow Private copy-onwrite object 12 Object

COPY-ON-WRITE AND fork()! When a process calls fork(), it spawns an identical child-process Most significant differences are that the process ID and parent-process ID are different All code, data, and I/O state of parent process is exactly replicated in the child process! Creating an actual copy of the parent process would be inefficient and slow Parent and child process share the same program text and shared libraries, and these are read-only Plus, parent and child processes might not actually change all of the data they now share! Instead, kernel can use copy-on-write technique to create the child process 13

COPY-ON-WRITE AND fork() (2)! When process calls fork(), the kernel can use the copy-on-write technique: Duplicate process-specific data structures, including page tables and mm_struct details Flag all pages in both processes as read-only Mark all areas as private copy-on-write! When either parent or child process writes to : Modified page is automatically duplicated by the copy-on-write mechanism Parent and child still appear to have isolated address spaces Different for Identical for 0xc0000000 %esp 0x40000000 brk 0x08048000 0 Process-specific data structures Kernel stack Mapping to physical Kernel code and global data User stack Memory mapped region for shared libraries Run-time heap (via malloc) Uninitialized data (.bss) Initialized data (.data) Program text (.text) Forbidden Kernel Process 14

VIRTUAL MEMORY AND execve()! UNIX execve() function also relies heavily on the system Loads and runs a new program in the current process context! Step 1: clean up the current process state Reset the process address space in preparation for the new program! Iterate through the vm_area_struct list: Unmap areas Delete vm_area_structs, too Different for Identical for 0xc0000000 %esp 0x40000000 brk 0x08048000 0 Process-specific data structures Kernel stack Mapping to physical Kernel code and global data User stack Memory mapped region for shared libraries Run-time heap (via malloc) Uninitialized data (.bss) Initialized data (.data) Program text (.text) Forbidden Kernel Process 15

VIRTUAL MEMORY AND execve() (2)! Step 2: map private areas! Program text (.text) and initialized data (.data) are specified in binary file Map these pages directly to the appropriate areas of the binary file When pages are referenced, kernel will swap them into main automatically! Both areas are marked private copy-on-write (Or,.text may be marked read-only instead ) Different for Identical for 0xc0000000 %esp 0x40000000 brk 0x08048000 0 Process-specific data structures Kernel stack Mapping to physical Kernel code and global data User stack Memory mapped region for shared libraries Run-time heap (via malloc) Uninitialized data (.bss) Initialized data (.data) Program text (.text) Forbidden Kernel Process 16

VIRTUAL MEMORY AND execve() (2)! Step 2: map private areas, cont.! Uninitialized data (.bss) isn t contained in the binary file Binary simply specifies the size of this region Kernel maps the.bss pages to the anonymous file, which contains all zero values! Uninitialized data is initially set to all zero values! Kernel also maps user stack and heap to the anonymous file Sizes are increased as needed Different for Identical for 0xc0000000 %esp 0x40000000 brk 0x08048000 0 Process-specific data structures Kernel stack Mapping to physical Kernel code and global data User stack Memory mapped region for shared libraries Run-time heap (via malloc) Uninitialized data (.bss) Initialized data (.data) Program text (.text) Forbidden Kernel Process 17

VIRTUAL MEMORY AND execve() (3)! Step 3: map shared areas! If the program is linked with any shared objects: e.g. libc.so, the C standard library! Libraries are dynamically linked into the program! Then, the shared objects are mapped into the process address space e.g. shared read-only (otherwise, changes are visible to all other processes, and also modify the original file!) Different for Identical for 0xc0000000 %esp 0x40000000 brk 0x08048000 0 Process-specific data structures Kernel stack Mapping to physical Kernel code and global data User stack Memory mapped region for shared libraries Run-time heap (via malloc) Uninitialized data (.bss) Initialized data (.data) Program text (.text) Forbidden Kernel Process 18

VIRTUAL MEMORY AND execve() (4)! Step 4: set the process Program Counter to the program s entry-point Next time the process is scheduled for execution, it will start running from the entry-point Different for Identical for 0xc0000000 %esp Process-specific data structures Kernel stack Mapping to physical Kernel code and global data User stack Kernel! As new program executes, the system will swap in necessary pages e.g. program text, data, shared library code, etc. 0x40000000 brk 0x08048000 0 Memory mapped region for shared libraries Run-time heap (via malloc) Uninitialized data (.bss) Initialized data (.data) Program text (.text) Forbidden Process 19

SUMMARY: VIRTUAL MEMORY! Virtual is an essential component of modern operating systems! Used extensively to implement many features Process and isolation of address-spaces Fast context-switches and process-forking Simplifies loading of programs and libraries into main Facilitates efficient use by sharing common data across many processes! Data is only duplicated when strictly necessary 20

21 SOLID STATE DRIVES AND TRIM Supplemental Material

22 File Systems and File Deletion File systems generally separate directory information and file contents One or more directories can contain a link to a given file (e.g. hard links, symlinks) When a file is deleted, two operations: Remove directory entry to file If no more directory entries reference the file, mark the file s space as available Normally, the file s actual data isn t modified by deletion (Can securely delete file data by overwriting it one or more times) The operating system simply stops using the disk sectors where the file previously resided at least until the area is used by a new file A user1 A B home C C user2 D

23 Free Space and SSDs Solid State Drives (SSDs) and other flash-based devices often complicate management of free space SSDs are block devices; reads and writes are a fixed size Problem: can only write to a block that is currently empty Blocks can only be erased in groups, not individually! An erase block is a group of blocks that are erased together Erase blocks are much larger than read/write blocks A read/write block might be 4KiB or 8KiB Erase blocks are often 128 or 256 of these blocks (e.g. 2MiB)! As long as some blocks on the SSD are empty, writes can be performed immediately If the SSD has no more empty blocks, a group of blocks must be erased to provide more empty blocks

24 Solid State Drives Solid State Drives include a flash translation layer that maps logical block addresses to physical cells Recall: system uses Logical Block Addressing to access disks When files are written to the SSD, data must be stored in empty cells (i.e. contents can t simply be overwritten) If a file is edited, the SSD sees a write issued against the same logical block e.g. block 2 in file F1 is written SSD can t just replace block s contents SSD marks the cell as, then stores the new block data in another cell, and updates the mapping in the FTL Flash Translation Layer F1.1 F1.2 F1.3 F2.1 F2.2 F3.1 F3.2 F3.3 F3.4 F1.2'

25 Solid State Drives (2) Over time, SSD ends up with few or no available cells e.g. a series of writes to our SSD that results in all cells being used SSD must erase at least one block of cells to be reused Best case is when an entire erase-block can be reclaimed SSD erases the entire block, and then carries on as before Erase! Flash Translation Layer F1.1 F1.2 F1.3 F2.1 Flash Translation Layer F2.1'' F2.2 F3.1 F3.2 F3.3 F2.2 F3.1 F3.2 F3.3 F3.4 F1.2' F3.1' F3.4' F3.4 F1.2' F3.1' F3.4' F1.1' F2.1' F1.3' F1.2'' F1.1' F2.1' F1.3' F1.2''

26 Solid State Drives (3) More complicated when an erase block still hs data e.g. SSD decides it must reclaim the third erase-block SSD must relocate the current contents before erasing Result: sometimes a write to the SSD incurs additional writes within the SSD Phenomenon is called write amplification Flash Translation Layer Flash Translation Layer F2.1'' F3.1' F3.4' F2.1'' F3.1' F3.4' F2.2 F3.1 F3.2 F3.3 F2.2 F3.1 F3.2 F3.3 Erase! F3.4 F1.2' F3.1' F3.4' F1.1' F2.1' F1.3' F1.2'' F1.1' F2.1' F1.3' F1.2''

27 Solid State Drives (4) SSDs must carefully manage this process to avoid uneven wear of its cells Cells can only survive so many erase cycles, then become useless How does the SSD know when a cell s contents are no longer needed? (i.e. when to mark the cell ) The SSD only knows because it sees multiple writes to the same logical block The new version replaces the version The SSD knows that the cell is no longer used for storage Flash Translation Layer F2.1'' F3.1' F3.4' F2.2 F3.1 F3.2 F3.3 F1.1' F2.1' F1.3' F1.2''

28 SSDs and File Deletion Problem: for most file system formats, file deletion doesn t actually touch the blocks in the file themselves! File systems try to avoid this anyway, because storage I/O is slow! Want to only update directory entry and other bookkeeping data, and we want this to be as efficient as possible Example: File F3 is deleted from the SSD SSD will only see the block with the directory entry change, and maybe a few other blocks The SSD has no idea that file F3 s data no longer needs to be preserved e.g. if the SSD decides to erase bank 2, it will still move F3.2 and F3.3 to other cells, even though the OS and the users don t care! Flash Translation Layer F2.1'' F3.1' F3.4' F2.2 F3.1 F3.2 F3.3 F1.1' F2.1' F1.3' F1.2''

29 SSDs, File Deletion and TRIM To deal with this, SSDs introduced the TRIM command (TRIM is not an acronym) When the filesystem is finished with certain logical blocks, it can issue a TRIM command to inform the SSD that the data in those blocks can be discarded Previous example: file F3 is deleted The OS can issue a TRIM command to inform SSD that all associated blocks are now unused TRIM allows the SSD to manage its cells much more efficiently Greatly reduces write magnification issues Helps reduce wear on SSD cells Flash Translation Layer F2.1'' F3.1' F3.4' F2.2 F3.1 F3.2 F3.3 F1.1' F2.1' F1.3' F1.2''

30 SSDs, File Deletion and TRIM (2) Still a few issues to resolve with TRIM at this point Biggest one is TRIM wasn t initially a queued command Couldn t include TRIM commands in a mix of other read/write commands being sent to the device TRIM must be performed separately, in isolation of other operations TRIM must be issued in a batch-mode way, when it won t interrupt other work e.g. can t issue TRIM commands immediately F2.1'' F3.1' F3.4' after each delete operation This was fixed in SATA 3.1 specification A queued version of TRIM was introduced Another issue: not all OSes/filesystems support TRIM (or not enabled by default) Flash Translation Layer F2.2 F3.1 F3.2 F3.3 F1.1' F2.1' F1.3' F1.2''