Kernel Synchronization II

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Chapter 6: Process Synchronization
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
CS510 Concurrent Systems Jonathan Walpole. What is RCU, Fundamentally? Paul McKenney and Jonathan Walpole.
Parallel Processing (CS526) Spring 2012(Week 6).  A parallel algorithm is a group of partitioned tasks that work with each other to solve a large problem.
Synchronization. Shared Memory Thread Synchronization Threads cooperate in multithreaded environments – User threads and kernel threads – Share resources.
CS533 Concepts of Operating Systems Class 4 Linux Kernel Locking Issues.
CS510 Concurrent Systems Class 1
What is RCU, fundamentally? Sri Ramkrishna. Intro RCU stands for Read Copy Update  A synchronization method that allows reads to occur concurrently with.
CS533 - Concepts of Operating Systems 1 CS533 Concepts of Operating Systems Class 8 Synchronization on Multiprocessors.
CS510 Concurrent Systems Class 1 Linux Kernel Locking Techniques.
CS533 Concepts of Operating Systems Class 17 Linux Kernel Locking Techniques.
CS533 Concepts of Operating Systems Linux Kernel Locking Techniques.
Synchronization CSCI 444/544 Operating Systems Fall 2008.
OSE 2013 – synchronization (lec3) 1 Operating Systems Engineering Locking & Synchronization [chapter #4] By Dan Tsafrir,
Relativistic Red Black Trees. Relativistic Programming Concurrent reading and writing improves performance and scalability – concurrent readers may disagree.
CS510 Concurrent Systems Introduction to Concurrency.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Kernel Locking Techniques by Robert Love presented by Scott Price.
CSE 425: Concurrency II Semaphores and Mutexes Can avoid bad inter-leavings by acquiring locks –Guard access to a shared resource to take turns using it.
CS533 Concepts of Operating Systems Jonathan Walpole.
The read-copy-update mechanism for supporting real-time applications on shared-memory multiprocessor systems with Linux Guniguntala et al.
CS510 Concurrent Systems Jonathan Walpole. RCU Usage in Linux.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Kernel Structure and Infrastructure David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Read-Copy-Update Synchronization in the Linux Kernel 1 David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis.
Homework-6 Questions : 2,10,15,22.
CS510 Concurrent Systems “What is RCU, Fundamentally?” By Paul McKenney and Jonathan Walpole Daniel Mansour (Slides adapted from Professor Walpole’s)
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Kernel Synchronization David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
C++11 Atomic Types and Memory Model
Chapter 6: Process Synchronization
Process Synchronization
Process Synchronization
Synchronization.
Processes David Ferry, Chris Gill
Overview of the Lab 2 Assignment: Linux Scheduler Profiling
Designing Parallel Algorithms (Synchronization)
Threading And Parallel Programming Constructs
Semaphore Originally called P() and V() wait (S) { while S <= 0
COMS Prelim 1 Review Session
Kernel Structure and Infrastructure
Lecture 2 Part 2 Process Synchronization
Does Hardware Transactional Memory Change Everything?
Top Half / Bottom Half Processing
Implementing Mutual Exclusion
Kernel Synchronization I
CS510 Concurrent Systems Class 1a
Implementing Mutual Exclusion
Kernel Synchronization II
Userspace Synchronization
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
CS510 Concurrent Systems Jonathan Walpole.
Linux Kernel Locking Techniques
CSE 451 Section 1/27/2000.
Problems with Locks Andrew Whitaker CSE451.
Atomicity, Mutex, and Locks
Processes David Ferry, Chris Gill, Brian Kocoloski
EECE.4810/EECE.5730 Operating Systems
CSE 542: Operating Systems
CSE 542: Operating Systems
Presentation transcript:

Kernel Synchronization II David Ferry, Chris Gill CSE 422S - Operating Systems Organization Washington University in St. Louis St. Louis, MO 63143

Basic Kernel Synchronization Watch out for non-recursive locks! If you already hold a (spin) lock don’t reacquire it! Atomic variables Spin locks (non-sleepable locks) Mutexes (sleepable locks) Reader-writer locks Semaphores CSE 422S – Operating Systems Organization

When to Use Different Types of Locks Spin locks - very short lock durations and/or very low overhead requirements Mutexes - Long lock duration and/or process needs to sleep while holding lock Atomics - When shared data fits inside a single word of memory, or a lock-free synchronization protocol can be implemented Read-Copy-Update (RCU) - Modern locking approach that may improve performance CSE 422S – Operating Systems Organization

Sleeping while holding Locks Sleeping while holding a lock should be avoided (unless absolutely necessary) Delays other processes Deadlock risk: is it guaranteed to wake up (at least eventually) and release the lock? A process cannot sleep holding a spinlock Change code to back out of lock, then sleep Or, use a mutex instead of a spin lock CSE 422S – Operating Systems Organization

The BKL is No Longer Used The Big Kernel Lock (BKL) was the first lock introduced to the kernel Locked the entire kernel Provides correctness, but very slow New uses are prohibited Gradually replaced with finer-grained locking schemes CSE 422S – Operating Systems Organization

Synchronization Design Challenge A common kernel problem: Multiple threads share a data structure. Some are reading Some are writing Reads and writes should not interfere! Shared data CSE 422S – Operating Systems Organization

Synchronization Design Tradeoffs All synchronization methods need to balance the needs of readers and writers: Reads tend to be more common Lots of reads Few writes Balanced Reads and writes Lots of writes Few reads Synchronization can prevent concurrency… Reader/writer locks Mutual exclusion Or it can allow concurrency at the expense of overheads: Lock free / wait free algorithms Transactional memory CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization RCU Philosophy Under RCU: Concurrent reads are synchronization-free (which means scalability!) Writers must guarantee that all readers only ever see a consistent view of memory Similar to a publish-subscribe model Let’s look at the API… CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization RCU Writer API Even if pointer write is atomic: struct foo *ptr = NULL; p = kmalloc(...); p->A = 1; p->B = 2; p->C = 3; ptr = p; Overall code is not safe! Compiler may re-order lines 3-6 CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization RCU Writer API RCU encapsulates memory fences struct foo *ptr = NULL; p = kmalloc(...); p->A = 1; p->B = 2; p->C = 3; rcu_assign_ptr(ptr,p); rcu_assign_ptr method publishes P CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization RCU Reader API Consider reading a data structure: p = ptr; if (p != NULL) do_something(p->A, p->B, p->C); This is also not safe! The values of A, B, and C could change between reads! CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization RCU Reader API Safely reading the data structure: rcu_read_lock(); p = rcu_dereference(ptr); if (p != NULL) do_something(p->A, p->B, p->C); rcu_read_unlock(); rcu_dereference() can be thought of as subscribing to a specific, valid version of ptr lock/unlock defines RCU critical section CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization RCU Encapsulation Note, RCU semantics can be encapsulated for specific data structures: rcu_list_add() rcu_for_each_read() But not: rcu_for_each_write() RCU does not allow for concurrent writes! CSE 422S – Operating Systems Organization