Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 149: Operating Systems March 12 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Similar presentations


Presentation on theme: "CS 149: Operating Systems March 12 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak."— Presentation transcript:

1 CS 149: Operating Systems March 12 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak

2 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 2 Linux Memory Management  Two main components Physical memory  Allocating and freeing pages, groups of pages, small blocks of RAM Virtual memory  Mapping memory into the address space of running processes.

3 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 3 Linux Physical Memory (Intel x86-32)  Physical memory is divided into three zones. 1. ZONE_DMA  Pages that used by legacy devices. 2. ZONE_NORMAL  Normal, regularly mapped pages. 3. ZONE_HIGHMEM  Pages with high memory addresses that are not mapped into the kernel address space. Operating Systems Concepts, 9 th edition Silberschatz, Galvin, and Gagne (c) 2013 John Wiley & Sons. All rights reserved. 978-1-118-06333-0

4 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 4 Linux Kernel Memory Allocation  The kernel uses the buddy system for its memory.  Suppose initially, a region of 64 pages is available. A request is rounded up to a power of 2, say 8 pages. Keep dividing in half until the allocation can be made. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc.. 0-13-600663-9 All rights reserved

5 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 5 Linux Kernel Memory Allocation Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc.. 0-13-600663-9 All rights reserved Allocations are contiguous.

6 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 6 Linux Kernel Memory Allocation, cont’d A second request for 8 pages. A request for 4 pages. The second 8-page allocation is released. The first 8-page allocation is released. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc.. 0-13-600663-9 All rights reserved

7 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 7 Linux Kernel Memory Allocation, cont’d  The buddy algorithm causes internal fragmentation.  Linux uses a slab allocator to carve smaller allocations from what is allocated by the buddy algorithm.  Since the kernel frequently allocates certain types of objects, slabs are cached by object size. Operating Systems Concepts, 9 th edition Silberschatz, Galvin, and Gagne (c) 2013 John Wiley & Sons. All rights reserved. 978-1-118-06333-0

8 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 8 Linux Kernel Memory Allocation, cont’d Operating Systems Concepts, 9 th edition Silberschatz, Galvin, and Gagne (c) 2013 John Wiley & Sons. All rights reserved. 978-1-118-06333-0

9 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 9 Review for the Midterm  A test of understanding, not memorization.  Open book, open notes, open laptop, open Internet. But not open neighbor! Forbidden to communicate with anyone else during the exam. _

10 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 10 Review for the Midterm, cont’d  What is an operating system. Why study them?  History of operating systems. The good old days before your computer had an OS. Data processing

11 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 11 Review for the Midterm, cont’d  OS concepts Concurrency Processes File systems I/O redirection Pipes Shell API  fork() and join()

12 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 12 Review for the Midterm, cont’d  OS structure Kernel mode vs. user mode Monolithic vs. layered Virtual machines Client-server Distributed _

13 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 13 Review for the Midterm, cont’d  Processes Context switching Creation and termination States  Process scheduling Goals Process behavior  compute-bound vs. I/O bound _

14 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 14 Review for the Midterm, cont’d  Scheduling algorithms Preemptive vs. non-preemptive Scheduling criteria Algorithms: FCFS, SJF, SRT, RR, HPF, etc. Priority queues Time quanta (slices) Timelines Interrupt routines _

15 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 15 Review for the Midterm, cont’d  Threads Lightweight processes Multithreaded systems User-level vs. kernel-level Thread scheduling  UNIX Pthread library create threads start threads wait for threads _

16 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 16 Review for the Midterm, cont’d  Interprocess communication  Shared memory UNIX system calls for shared memory  Message passing blocking vs. nonblocking sockets remote procedure call (RPC) pipe

17 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 17 Review for the Midterm, cont’d  Process synchronization race condition critical region  Mutual exclusion lock variables busy waiting Peterson’s solution test and set lock instruction sleep and wakeup

18 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 18 Review for the Midterm, cont’d  Producer-consumer problem  Readers-writers problem  Dining philosophers problem  UNIX Pthreads library semaphores  wait and post (signal) mutexes  lock and unlock  Monitors Dining philosophers problem  Java implementation

19 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 19 Review for the Midterm, cont’d  Deadlocks  Requesting a resource preemptable vs non-preemptable  Four deadlock conditions 1. mutual exclusion 2. hold and wait 3. no preemption 4. circular wait

20 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 20 Review for the Midterm, cont’d  Deadlock modeling  Strategies  Detection and recovery  Prevention  Banker’s algorithms  Resource trajectories

21 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 21 Review for the Midterm, cont’d  Memory management  System memory design Memory manager  Memory hierarchy Cache Main Disk storage

22 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 22 Review for the Midterm, cont’d  Monoprogramming systems  Multiprogramming with fixed partitions  Multiprogramming with variable-sized partitions  Process relocation  Process protection _

23 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 23 Review for the Midterm, cont’d  Address binding Symbolic addresses to relocatable address Compile-time, load-time, execution-time  Logical vs. physical address space  Dynamic loading  Dynamic linking  Swapping Keep track of memory allocations Backing store

24 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 24 Review for the Midterm, cont’d  Memory allocation algorithms  First fit  Next fit  Best fit  Worst fit

25 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 25 Review for the Midterm, cont’d  Paging  Pages  Page frames  Page table Multilevel Inverted  Logical address format  Shared pages

26 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 26 Review for the Midterm, cont’d  Page replacement algorithms  FIFO: First-in first-out Second chance  LRU: Least recently used  LFU: Least frequently used  MFU: Most frequently used  Random pick  Local vs. global

27 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 27 Review for the Midterm, cont’d  Fragmentation Internal and external  Locality of reference Translation lookaside buffer (TLB) Hit ratio

28 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 28 Review for the Midterm, cont’d  Segmentation  Virtual memory Demand paging Page fault Copy-on-write  Kernel memory Buddy system _

29 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 29 Review for the Midterm, cont’d  Working set model Thrashing Page fault frequency (PFF)  Locality model  Prepaging  Page size  TLB reach  Program structure  Memory-mapped files

30 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 30 Sample Midterm Questions  What is the output from Line A and Line B in the following code? Answer: Line A: value = 15 Line B: value = 5 #include int value = 5; int main() { pid_t pid = fork(); if (pid == 0) { value += 10; printf("Line A: value = %d\n", value); // Line A return 0; } else { int status; waitpid(-1, &status, 0); printf("Line B: value = %d\n", value); // Line B return 0; }

31 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 31 Sample Midterm Questions, cont’d  What is the output from Line A and Line B in the following code?  Answer: Line A: value = 10 Line B: value = 5 #include int value = 5; void *my_thread(void *parm); int main() { pthread_t tid; pthread_attr_t attr; pid_t pid = fork(); if (pid == 0) { pthread_attr_init(&attr); pthread_create(&tid, &attr, my_thread, NULL); pthread_join(tid, NULL); printf("Line A: value = %d\n", value); // Line A } else { int status; waitpid(-1, &status, 0); printf("Line B: value = %d\n", value); // Line B } void *my_thread(void *parm) { value = 10; pthread_exit(0); }

32 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 32 Sample Midterm Questions, cont’d  We can extend our resource allocation graphs as follows: If there are multiple instances of a resource, we show each instance with a dot inside the resource rectangle. a. b.

33 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 33 Sample Midterm Questions, cont’d  Continued … We indicate that a process holds a resource instance by an arrow from a dot to the process circle. We indicate that a process has requested (is waiting for) any instance of a resource by an arrow from the process circle to the resource rectangle. a. b.

34 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 34 Sample Midterm Questions, cont’d  For each of these resource allocation graphs, explain why or why not it represents a deadlock. a) Answer: Has two cycles: P2  R3  P3  R2  P2 and P1  R1  P2  R3  P3  R2  P1 P2 is waiting for R3, which is held by P3. P3 is waiting for either P1 or P2 to release an instance of R2. P1 is waiting for P2 to release R1. The processes are deadlocked. a. b.

35 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 35 Sample Midterm Questions, cont’d  For each of these resource allocation graphs, explain why or why not it represents a deadlock. b) Answer: Also has a cycle: P1  R1  P3  R2  P1 P2 can release an instance of R1, which can be taken by P1. P4 can release an instance of R2, which can then be taken by P3. Thus, the cycle is broken. There is no deadlock a. b.

36 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 36 Sample Midterm Questions, cont’d  Consider this traffic deadlock (AKA traffic gridlock): a. Briefly explain how the four deadlock conditions are satisfied in this example. 1.mutual exclusion 2.hold and wait 3.no preemption 4.circular wait

37 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 37 Sample Midterm Questions, cont’d a. Answer: 1. Mutual exclusion. Only one car can occupy a particular spot on the road at any instant. 2. Hold and wait: A car holds its spot and waits to move forward. 3. No preemption: A car cannot be removed (preempted) from its spot on the road. 4. Circular wait: Each side of the block contains cars whose movements are blocked by cars waiting at the next intersection

38 Computer Science Dept. Spring 2015: March 10 CS 149: Operating Systems © R. Mak 38 Sample Midterm Questions, cont’d b. What’s a simple rule to prevent this traffic gridlock?  Answer: Do not allow cars to move into an intersection unless it can clear the intersection. (“Don’t block the box.”)


Download ppt "CS 149: Operating Systems March 12 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak."

Similar presentations


Ads by Google