CSE 451: Operating Systems Section 7: Project 2b; Virtual Memory.

Slides:



Advertisements
Similar presentations
4.4 Page replacement algorithms
Advertisements

Chapter 101 The LRU Policy Replaces the page that has not been referenced for the longest time in the past By the principle of locality, this would be.
More on Semaphores, and Classic Synchronization Problems CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Chapter 6: Process Synchronization
1 Memory Management Managing memory hierarchies. 2 Memory Management Ideally programmers want memory that is –large –fast –non volatile –transparent Memory.
CSE 451: Operating Systems Section 6 Project 2b; Midterm Review.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
Paging Algorithms Vivek Pai / Kai Li Princeton University.
Operating Systems Final Exam Review. Topics F Virtual Memory F File Systems F I/O Devices F Project 3: Macro Shell.
Virtual Memory. Names, Virtual Addresses & Physical Addresses Source Program Absolute Module Name Space P i ’s Virtual Address Space P i ’s Virtual Address.
CMPT 300: Operating Systems Review THIS REIVEW SHOULD NOT BE USED AS PREDICTORS OF THE ACTUAL QUESTIONS APPEARING ON THE FINAL EXAM.
Memory Management Virtual Memory Page replacement algorithms
Operating Systems Final Exam Review. Topics Paging Virtual Memory File Systems I/O Devices Project 3: Macro Shell.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Page Replacement Algorithms
Synchronization CSCI 444/544 Operating Systems Fall 2008.
1 CSE451 - Section Last section! Project 4 due tomorrow Today: Some practice for the exam “Big picture” review tomorrow Evaluations Project 3 +
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Virtual Memory.
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
CSE 451: Operating Systems Section 10 Project 3 wrap-up, final exam review.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Memory Management Techniques
CS425 /CSE424/ECE428 – Distributed Systems – Fall 2011 Material derived from slides by I. Gupta, M. Harandi, J. Hou, S. Mitra, K. Nahrstedt, N. Vaidya.
Page Replacement Algorithms Memory Management. Optimal Page Replacement ▪The label for each page in memory is labeled with the number of instructions.
CSE 451: Operating Systems Section 7 Data races, thread pools, project 2b.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Lecture 11 Page 1 CS 111 Online Virtual Memory A generalization of what demand paging allows A form of memory where the system provides a useful abstraction.
Consider the program fragment below left. Assume that the program containing this fragment executes t1() and t2() on separate threads running on separate.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
CSE 451: Operating Systems Section 9: Storage; networks.
Consider the Java code snippet below. Is it a legal use of Java synchronization? What happens if two threads A and B call get() on an object supporting.
Lecture 12-1 Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2012 Indranil Gupta (Indy) October 4, 2012 Lecture 12 Mutual Exclusion.
CSE 153 Design of Operating Systems Winter 2015 Lecture 12: Page Replacement.
CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization.
CSE Four Fiddy One Section 7 Kurtis Heimerl Aaron Kimball
1 Page Replacement Algorithms. 2 Virtual Memory Management Fundamental issues : A Recap Key concept: Demand paging  Load pages into memory only when.
CSE 451: Operating Systems Section 6 Project 2b. Midterm  Scores will be on Catalyst and midterms were handed back on Friday(?) in class  Talk to Ed,
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
MIDTERM REVIEW CSCC69 Winter 2016 Kanwar Gill. What is an OS? What are processes and threads? Process states? Diagram showing the state changes What data.
COS 318: Operating Systems Virtual Memory Paging.
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Webserver w/user threads
CSE 451: Operating Systems
Preemption Set timer interrupts But now, must synchronize Two tools:
Section 10: Last section! Final review.
Semester Review Chris Gill CSE 422S - Operating Systems Organization
Synchronization Issues
CSE 451 Autumn 2003 Section 3 October 16.
CSE451 - Section 10.
Practical Session 8, Memory Management 2
First slide Rest of project 2 due next Friday Today:
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
CSE 153 Design of Operating Systems Winter 2019
Last section! Project 4 + EC due tomorrow Today: Project 4 questions
CSE451 - Section 10.
Lecture 9: Caching and Demand-Paged Virtual Memory
CSE 153 Design of Operating Systems Winter 19
CSE 451 Section 1/27/2000.
CSE 542: Operating Systems
Practical Session 9, Memory Management continues
CSE 542: Operating Systems
Clock Algorithm Example
Presentation transcript:

CSE 451: Operating Systems Section 7: Project 2b; Virtual Memory

Project 2a grading  Grades will be sent out later tonight 5/10/12 2

Debugging threaded programs  What techniques have you used?  printf statements: macros are helpful #define print_debug(f, a...) do { \ fprintf(stdout, "DEBUG: %lu: %s: " f, \ pthread_self(), __func__, ##a); \ fflush(stdout); \ } while(0) 5/10/12 3

Debugging threaded programs  Other tools:  gdb  Deadlock vs. corruption  To enable core dumps: ulimit -c unlimited  helgrind? DRD?  MS Visual Studio; Intel Inspector XE; …  What does the textbook say?  We’ve mostly discussed thread correctness; what about thread performance? 5/10/12 4

Thread pools 5/10/12 5  What is the “type” of a task?  What function do the threads run?  Can we make this abstract / generic?

sioux thread pool struct thread_pool { queue request_queue; sthread_cond_t request_ready; }; struct request { int next_conn; }; // New request arrives: // enqueue request, signal request_ready // Worker threads: // dequeue, run: handle_request(request); 5/10/12 6

Generic thread pool struct thread_pool { queue task_queue; sthread_cond_t work_to_do; }; typedef void (*work_fn) (void *); struct task { work_fn work; void *arg; }; // New work arrives: // enqueue new task, signal work_to_do // Worker threads: // dequeue, run: task->work(task->arg); 5/10/12 7

Thread performance  Where might there be performance bottlenecks with a thread pool?  Where are threads running?  What do threads have to do to access thread pool?  Where is the work queue stored? 8 Image from:

Synchronization is expensive  Explicit synchronization  Critical sections protected by mutexes, condition variables and queues  Strategies: reduce critical section size; atomic updates / lock-free data structures; RCU; …  Implicit synchronization  Through cache coherence / memory hierarchy  Strategies: partitioning / sharding 5/10/12 9

Debugging thread performance  How can we debug thread performance?  Intuition?  Profiling tools:  cachegrind / callgrind  Intel VTune Amplifier 5/10/12 10

sioux web server  Make the web server multithreaded  Create a thread pool  Suggestion: create separate thread_pool.h, thread_pool.c  Wait for a connection  Find an available thread to handle the request  Request waits if all threads busy  Once the request is handed to a thread, it uses the same processing code as before  Use pthreads for parts 4 and 6: we won’t test sioux with sthreads! 5/10/12 11

Preemption (part 5)  Remember this tip from previous section:  One way to think about preemption-safe thread library:  Disable/enable interrupts in “library” context  Use atomic locking in “application” context  Does locking / unlocking a mutex happen in “library context” or “application context”? 5/10/12 12

How not to implement mutexes sthread_user_mutex_lock(mutex) splx(HIGH); if (mutex->held) { enqueue(mutex->queue, current_thread); schedule_next_thread(); } else { mutex->held = true; } splx(LOW); 5/10/12 13

How not to implement mutexes  Don’t turn it into a spinlock: sthread_user_mutex_lock(mutex) while(atomic_test_and_set( &(mutex->available))) { }  This is also wrong: where could we get preempted that could lead to deadlock? sthread_user_mutex_lock(mutex) while(atomic_test_and_set( &(mutex->available))) { enqueue(mutex->queue, current_thread); schedule_next_thread(); } 5/10/12 14

So how does one implement mutexes?  Need to lock around the critical sections in the mutex functions themselves!  Your struct _sthread_mutex will likely need another member for this  For hints, re-read lecture slides:  Module 7: Synchronization (slide 20 forward)  Module 8: Semaphores  Similar hints apply for condition variables 5/10/12 15

Project 2b  Any more questions? 5/10/12 16

Virtual memory 5/10/12 17 Process’ VM: Another process Disk Physical memory: (slides from Chernyak Fall 2009) page frame # Process’ page table How can we use paging to set up sharing of memory between two processes?

5/10/12 18

Page replacement algorithms  FIFO (First in/first out)  Replace the oldest page with the one being paged in  Not very good in practice, suffers from Belady’s Anomaly  Second-Chance (Modified FIFO)  FIFO, but skip referenced pages  VAX/VMS used this  Random  Better than FIFO!  NFU (Not Frequently Used)  Replace the page used the least number of times  Better variation: Aging ensures that pages that have not been used for a while go away.  NRU (Not Recently Used)  Replace a page not used since last clock cycle  LRU (Least Recently Used)  Replace the least recently used page  Works well but expensive to implement. (More efficient variants include LRU-K)  LRU Clock (Modified LRU)  Replace the least recently used page, with a hard limit on the max time since used  Clairvoyant  Replace the page that’s going to be needed farthest in the future. 5/10/12 19

Example of Belady’s anomaly 5/10/ Sequence of page requests: 3 physical page frames: Page faults (in red): 9

Example of Belady’s anomaly 5/10/ Sequence of page requests: 4 physical page frames: Page faults (in red): 10

22 5/10/12