Background: I/O Concurrency

Similar documents
Background: Operating Systems

Network File System (NFS)

Network File System (NFS)

Announcement. Exercise #2 will be out today. Due date is next Monday

Remote Procedure Call (RPC) and Transparency

Lecture 4: Memory Management & The Programming Interface

GFS: The Google File System

Processes and Virtual Memory Concepts

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

Computer System Overview

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

Threads and Too Much Milk! CS439: Principles of Computer Systems February 6, 2019

Processes and Threads

Problem Set: Processes

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

Principles of Operating Systems CS 446/646

Threads and Too Much Milk! CS439: Principles of Computer Systems January 31, 2018

Problem Set: Processes

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Qualifying exam: operating systems, 1/6/2014

Overview. This Lecture. Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4. COSC440 Lecture 3: Interrupts 1

The Kernel Abstraction

CSci 4061 Introduction to Operating Systems. (Thread-Basics)

LINUX OPERATING SYSTEM Submitted in partial fulfillment of the requirement for the award of degree of Bachelor of Technology in Computer Science

OPERATING SYSTEM. Chapter 4: Threads

Multiple Processor Systems. Lecture 15 Multiple Processor Systems. Multiprocessor Hardware (1) Multiprocessors. Multiprocessor Hardware (2)

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

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

Processes and Threads Implementation

IsoStack Highly Efficient Network Processing on Dedicated Cores

Notes based on prof. Morris's lecture on scheduling (6.824, fall'02).

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

CSE544 Database Architecture

ELEC 377 Operating Systems. Week 1 Class 2

Kernel Support for Paravirtualized Guest OS

* What are the different states for a task in an OS?

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

Advanced Computer Networks. End Host Optimization

CSE 410: Systems Programming

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Implementation of Processes

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

Process Time. Steven M. Bellovin January 25,

Processes and Threads. Processes: Review

W4118: OS Overview. Junfeng Yang

Input / Output. Kevin Webb Swarthmore College April 12, 2018

Suggested Solutions (Midterm Exam October 27, 2005)

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Operating Systems Overview. Chapter 2

Chapter 4: Threads. Chapter 4: Threads

PROJECT 6: PINTOS FILE SYSTEM. CS124 Operating Systems Winter , Lecture 25

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 22: Remote Procedure Call (RPC)

CPS 310 first midterm exam, 10/6/2014

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

Scheduling Mar. 19, 2018

Part 1: Introduction to device drivers Part 2: Overview of research on device driver reliability Part 3: Device drivers research at ERTOS

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


CS 450 Operating System Week 4 Lecture Notes

Architectural Support. Processes. OS Structure. Threads. Scheduling. CSE 451: Operating Systems Spring Module 28 Course Review

Disciplina Sistemas de Computação

Operating Systems : Overview

Threads, SMP, and Microkernels. Chapter 4

Cute Tricks with Virtual Memory

What s in a process?

CS 5460/6460 Operating Systems

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

Operating Systems Structure and Processes Lars Ailo Bongo Spring 2017 (using slides by Otto J. Anshus University of Tromsø/Oslo)

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

Lecture 2 Operating System Structures (chapter 2)

Threads SPL/2010 SPL/20 1

NUMA replicated pagecache for Linux

Announcements Processes: Part II. Operating Systems. Autumn CS4023

CSE 451 Midterm 1. Name:

CS 31: Intro to Systems Threading & Parallel Applications. Kevin Webb Swarthmore College November 27, 2018

Chapter 8: I/O functions & socket options

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

416 Distributed Systems. Distributed File Systems 2 Jan 20, 2016

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

csci3411: Operating Systems

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Operating System Architecture. CS3026 Operating Systems Lecture 03

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Problem Set 2. CS347: Operating Systems

Resource Containers. A new facility for resource management in server systems. Presented by Uday Ananth. G. Banga, P. Druschel, J. C.

Hardware OS & OS- Application interface

Chapter 13: I/O Systems

Operating System. Operating System Overview. Layers of Computer System. Operating System Objectives. Services Provided by the Operating System

Operating System Overview. Operating System

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

Operating Systems: Internals and Design Principles. Chapter 2 Operating System Overview Seventh Edition By William Stallings

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

Frequently asked questions from the previous class survey

CS307: Operating Systems

Lecture 3: O/S Organization. plan: O/S organization processes isolation

Transcription:

Background: I/O Concurrency Brad Karp UCL Computer Science CS GZ03 / M030 5 th October 2011

Outline Worse Is Better and Distributed Systems Problem: Naïve single-process server leaves system resources idle; I/O blocks Goal: I/O concurrency Goal: CPU concurrency Solutions Multiple processes One process, many threads Event-driven I/O (not in today s lecture) 2

Review: How Do Servers Use Syscalls? Consider server_1() web server (in handout) network syscalls R W W C time disk syscalls R R time application CPU time 3

Review: How Do Servers Use Syscalls? Server waits for each resource in turn Each Consider resource server_1() largely idle web server (in What handout) if there are many clients? network syscalls R W W C time disk syscalls R R time application CPU time 4

Performance and Concurrency Under heavy load, server_1(): Leaves resources idle and has a lot of work to do! Why? Software poorly structured! What would a better structure look like? 5

Solution: I/O Concurrency Can we overlap I/O with other useful work? Yes: Web server: if files in disk cache, I/O wait spent mostly blocked on write to network Networked file system client: could compile first part of file while fetching second part Performance benefits potentially huge Say one client causes disk I/O, 10 ms If other clients requests in cache, could serve 100 other clients during that time! 6

One Process May Be Better Than You Think OS provides I/O concurrency to application transparently when it can, e.g., Filesystem does read-ahead into disk buffer cache; write-behind from disk buffer cache Networking code copies arriving packets into application s kernel socket buffer; copies app s data into kernel socket buffer on write() 7

I/O Concurrency with Multiple Processes Idea: start new UNIX process for each client connection/request Master process assigns new connections to child processes Now plenty of work to keep system busy! One process blocks in syscall, others can process arriving requests Structure of software still simple See server_2() in webserver.c fork() after accept() Otherwise, software structure unchanged! 8

Multiple Processes: More Benefits Isolation Bug while processing one client s request leaves other clients/requests unaffected Processes do interact, but OS arbitrates (e.g., lock the disk request queue ) CPU concurrency for free If more than one CPU in box, each process may run on one CPU 9

CPU Concurrency Single machine may have multiple CPUs, one shared memory Symmetric Multiprocessor (SMP) PCs Intel Core Duo I/O concurrency tools often help with CPU concurrency But way more work for OS designer! Generally, CPU concurrency way less important than I/O concurrency Factor of 2X, not 100X Very hard to program to get good scaling Easier to buy 2 machines (see future lectures!) 10

Problems with Multiple Processes fork() may be expensive Memory for new address space 300 us minimum on modern PC running UNIX Processes fairly isolated by default Memory not shared How do you build web cache on server visible to all processes? How do you simply keep statistics? 11

Concurrency with Threads Similar to multiple processes Difference: one address space All threads share same process memory One stack per thread, inside process Seems simple: single-process structure! Programmer needs to use locks One thread can corrupt another (i.e., no cross-request isolation) 12

Concurrency with Threads App1 0 0 App2 t1 t2 stack stack N M User Space Filesystem Kernel Disk Driver Hardware 13

Threads: Low-Level Details Are Hard! Suppose thread calls read() (or other blocking syscall) Does whole process block until I/O done? If so, no I/O concurrency! Two solutions: Kernel-supported threads User-supported threads 14

Kernel-Supported Threads OS kernel aware of each thread Knows if thread blocks, e.g., disk read wait Can schedule another thread Kernel requirements: Per-thread kernel stack Per-thread tables (e.g., saved registers) Semantics: Per-process: address space, file descriptors Per-thread: user stack, kernel stack, kernel state 15

Kernel-Supported Threads App1 0 0 App2 t1 t2 stack stack N M User Space stack, table stack, table Filesystem Kernel Disk Driver Hardware 16

Kernel Threads: Trade-Offs Kernel can schedule one thread per CPU Fits our goals well: both CPU and I/O concurrency But kernel threads expensive, like processes: Kernel must help create each thread Kernel must help with thread context switch! Which thread took a page fault? Lock/unlock must invoke kernel, but heavily used Kernel threads not portable; not offered by many OSes 17

User-Level Threads Purely inside user process; kernel oblivious Scheduler within user process for process own threads In addition to kernel s process scheduler User-level scheduler must Know when thread makes blocking syscall Not block process; switch to another thread Know when I/O done, to wake up original thread 18

User-Level Thread Implementation App1 0 0 App2 t1 t2 stack stack Thread Scheduler Process Scheduler Kernel N M User Space Filesystem Disk Driver Hardware 19

User-Level Threads: Details Apps linked against thread library Library contains fake read(), write(), accept(), &c. syscalls Library can start non-blocking syscall operations Library marks threads as waiting, switches to runnable thread Kernel notifies library of I/O completion and other events; library marks waiting thread runnable 20

User-Level Threads: read() Example read() { tell kernel to start read; mark thread waiting for read; sched(); } sched() { ask kernel for I/O completion events; mark corresponding threads runnable; find runnable thread; restore registers and return; } 21

User-Level Threads: Event Notification Events thread library needs from kernel: new network connection data arrived on socket disk read completed socket ready for further write()s Resembles miniature OS inside process! Problem: user-level threads demand significant kernel support: non-blocking system calls uniform event delivery mechanism 22

Event Notification in Typical OSes Usually, event notification only partly supported; e.g., in UNIX: new TCP connections, arriving TCP/pipe/tty data: YES filesystem operation completion: NO Similarly, not all syscalls can be started without waiting, e.g., in UNIX: connect(), read()/write() on socket open(), stat(): NO read() from disk: SOMETIMES (e.g., aio_read()) 23

Non-blocking System Calls: Hard to Implement Typical syscall implementation, inside the kernel, e.g., for read() (sys_read.c): sys_read(fd, user_buffer, n) { // read the file s i-node from disk struct inode *i = alloc_inode(); start_disk(, i); wait_for_disk(i); // the i-node tells us where the data are; read it. struct buf *b = alloc_buf(i-> ); start_disk(, b); wait_for_disk(b); copy_to_user(b, user_buffer); } 24

Non-blocking System Calls: Hard to Implement Typical syscall implementation, inside the kernel, e.g., for read() (sys_read.c): Why not just return to user program instead sys_read(fd, user_buffer, n) { of calling wait_for_disk()? // read the file s i-node from disk How will kernel know where to continue? struct inode *i = alloc_inode(); In user space? In kernel? start_disk(, i); wait_for_disk(i); // the i-node tells us where the data are; read it. Problem: Keeping state for complex, multistep operations struct buf *b = alloc_buf(i-> ); start_disk(, b); wait_for_disk(b); copy_to_user(b, user_buffer); } 25

User-Threads: Implementation Choices Live with only partial support for user-level threads New operating system with totally different syscall interface One syscall per non-blocking sub-operation Kernel doesn t need to keep state across multiple steps e.g., lookup_one_path_component() Microkernel: no system calls, just messages to servers, with non-blocking communication 26

Threads: Programming Difficulty Sharing of data structures in one address space Even on single CPU, thread model necessitates CPU concurrency Locks often needed for mutual exclusion on data structures May only have wanted to overlap I/O wait! Events usually occur one-at-a-time Can we do CPU sequentially, and overlap only wait for I/O? Yes: event-driven programming 27

Event-Driven Programming Foreshadowed by user-level threads implementation Organize software around event arrival Write software in state-machine style When event X occurs, execute this function. Library support for registering interest in events (e.g., data available to read()) Desirable properties: Serial nature of events preserved Programmer sees only one event/function at a time 28