Final Exam Slides

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

• OS File data structure

(System-Wide) Open File Table • One system-wide (global) file table shared by all processes • File open count • File attribute, including ownership, protection/permission infor, access times • Locations of file on disk • Pointers to locations of file in memory • Each entry in open file table is called FCB (File control Block) • Basically the File attributes are stored here Per-Process File Table • Pointer to entry in the (system-wide) open file table • CUrrent position inf the file (offset) • Permission info - how the process accesses the file (r, w, rw)

• Journaling Crash Occurs

1) Crash during journal write • This is harder to address if crash 2) Crash during checkpoint Possible Journal write approaches • One at a time - slow! • Write all 5 blocks at once • Disk IO sequence can differ from actual intended write sequence • Write small blocks first and then big blocks • This approach is very unsafe as it can result in false valid writes • Two step transaction write (Journal Write) • Step #1: write four blocks (TxB, I[v2], B[v2], Db) at once • • Step #2: write TxE block. If completed, the journal is in safe state •

• What is page fault handling

1) If there is a reference to a page, first reference to that page will trap to operating system • Page fault 2) OS looks at another table to decide • Invalid reference → abort (stop the instruction) • Just not in memory 3) Find free frame in memory 4) Swap page into frame via scheduled disk operation 5) Reset tables to indicate page now in memory Set validation bit = v 6) Restart the instruction that caused the page fault

• The solution to critical-section problem must satisfy 3 requirements:

1) Mutual exclusion: only on thread does a particular thing at a time 2) Progress: If no process is executing in its critical section, and there exists form process that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely • When critical section is a available, OS should select the next process to enter Critical section ASAP • Otherwise, uses will think pc is freezing or slow 3) Bounded waiting: A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted • 1) Processes who want to enter Crit. sec. Have some idea (Prediction) when theory will enter crit sec • 2) Process who wants to enter crit. Sec. should not wait forever • To satisfy 1) and 2), OS should have a policy (# of times to enter Crit. sec ) for allowing other processes to enter Crit. sec.

• Virtualization Benefits

1) Run multiple/ different OSes on a single machine • OS research, SW testing, and run time debugging 2) Consolidate underutilized servers to reduce CAPEX and OPEX 3) Simplified management • Dynamic rebalance workloads to guarantee apps performance 4) Improved availability • Avoid downtime with VM relocation 5) Enforced Security • Hose system protected by VMs • VMs protected from each other

• Chapter 14: File System Implementation • Directory implementation

2 approaches • 1) Linear list • Linear list of file names with pointer to the data blocks • Easy to implement • Implement with either Array or Linked list • Array Implementation File create Operation • 1) Search through array to check if there is name conflict • 2) Insert into array File Delete Operation • 1) Search through array and file the file - O(n) • 2) Delete entry • First make entry unused - you may want to use valid/invalid bit • Copy the last entry to the empty slot • Delete the last entry Not very efficient because on linear search and array resizing • Can fix this by having sorted array with binary search or using a linked list • 2) Hash table • A better approach would be to use a Hash table • Still file information is stored in linked list, but using a hash function to point to the location in the list

• Memory barrier

2 memory models • Strongly ordered • where a memory modification of one processor is immediately visible to all other processors • Weakly ordered • where a memory modification of one processor may not be immediately visible to all other processors. • A memory barrier is an instruction that forces any change in memory to be propagated (made visible) to all other processors. • Instructions • When a memory barrier instruction is performed, the system ensures that all loads and stores are completed before any subsequent load or store operations are performed. • Therefore, even if instructions were reordered, the memory barrier ensures that the store operations are completed in memory and visible to other processors before future load or store operations are performed.

• Crash Consistency

A Single write succeeds • Just the data block (Db) is written to disk • • What is the problem? • Data block 5 has garbage data • This is not a problem from the perspective of FS, but users will lose data! • Just the updated i-node (I[v2]) is written to disk • • What is the problem? • i-node (v2) points to the disk block 5 for Db, but Db has not been written. • FS will read garbage data (old contents of disk block 5) • This is file inconsistency problem - disagreement between bitmap and inode • Just the updated bitmap (B[v2]) is written to disk. • • What is the problem? • bitmap indicates that block 5 is allocated, but no i-node points to it. • File inconsistency problem • Will also result in a space leak, as block 5 would never be used by FS 2 Writes succeed • i-node (I[v2]) and bitmap (B[v2]) are written to disk, but not data (Db). • • What is the problem? • Metadata has consistency, looks ok from FS perspective, but, data block 5 has garbage data • i-node (I[v2]) and the data block (Db) are written, but not the bitmap (B[v2]) • • What is the problem? • i-node pointing to the correct data on disk (Db) • FS has an inconsistency between the i-node and the old version of the bitmap • Another file may overwrite data block 5. • Bitmap (B[v2]) and data block (Db) are written, but not the i-node (I[v2]). • • What is the problem? • Inconsistency between the i-node and the data bitmap • Although the data block was written and the bitmap indicates its usage, FS has no idea which file it belongs to, as no i-node points to the file

• Peterson's solution

A classical SW based solution for critical section Limitations • May not work on modern computers architectures • Modern processors and compilers may reorder read and write operations when having no dependencies • Allows both processes to be in their crit sec at the same time • Need a memory barrier to make Peterson's solution work on modern computers • Not scalable for more than 2 threads

• Directories

A collection of tuples, each of which contains a human-readable name and low level name to which it maps • Low level = i-node number Can be viewed as a symbol table that translates file names into their FCB Operations in directory • 1) search for/Create/Destroy/Rename file • 2) List a directory • 3) traverse the file system • 4) Creating back or replicas, common in distributed file systems like GFS (Google File System)

• Directory

A collection of tuples, each of which contains a human-readable name and low-level name to which it maps Each entry refers either to another directory or a file Each directory also has a low-level name (i-number) itself Directory is a special type of file (with special flat bit) 2 special entries "." and ".."

• Memory Management Unit (MMU)

A memory management unit, is a unit having all memory references passed through itself, primarily performing the translation of virtual memory addresses to physical addresses Consider simple scheme which is a generalization of the base register scheme • Base register is called relocation register The value in the relocation register is added to ever addressed generated by a user process at the time it is sent to memory

• What is a page fault?

A page fault is when the page fault tries to reference a block in memory but it is not loaded in so it must be loaded from the HDD A page fault is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Page-fault: interrupt that occurs when an instruction references a page that is not in memory • Page request → not in memory → go to disk and load it to memory • What is the cost of page-fault? - disk access is expensive; need to consider pre-paging again Valid-invalid bit • With each page table entry a valid-invalid bit is associated • V: in-memory, i:not-in-memory (in disk) • Initially valid-invalid bit is set to i on all entries • During MMU address translation, if valid-invalid bit in page table entry is i page fault •

• Updated New Process Arrival with TLB

A process needing n pages arrives If n frames are available, allocate these frames to pages OS puts each page in a frame and then puts the frame number in the corresponding enter in the page table OS flushed the TLB (mark all invalid) OS starts the process As the process is executed, OS loads TLB entries as each page is accessed, replacing the existing entry if TLB is full

• Updated new process arrival with TLB

A process needing n pages arrives If n frames are available, allocate these frames to pages OS puts each page in a frame and then puts the frame number in the corresponding enter in the page table OS flushed the TLB (mark all invalid) OS starts the process As the process is executed, OS loads TLB entries as each page is accessed, replacing the existing entry if TLB is full

• Semaphore

A special type of variable that supports 2 atomic operations Semaphore S - integer variable that can be accessed via two indivisible/atomic operations wait() and signal() Indivisible operation • Aka atomic operation • All the modification to S (Semaphore) called in the wait() and signal() operations must be executed indivisibility • No other process can simultaneously modify the same S value 0 or less means someone else is in critical section 1 or more means you can enter into critical section 2 Types of Semaphore • Binary (or mutex =) semaphore • Integer value that can only range between 0 and 1 • Counting semaphore • Integer value can range over unrestricted domain • Can be used when multiple resources are available • Can be used for scheduling and queue management Semaphore without busy waiting • Using block and waiting queue • 2 operations • block - place the process invoking the operation on the appropriate waiting queue • wakeup - remove one of processes in the waiting queue and place it in the ready queue • Scheduling algorithm for waiting queue is FCFS Problems with semaphores • Deadlock - 2 or more processes are waiting indefinitely for an event caused be one of the waiting processes • What does the OS do in a deadlock? - it does nothing • Error-Prone • wait() and signal() must be matched • Common error is omitting a signal() or wait() or both Semaphore disadvantages • Essentially a shared global variable • Access to semaphore - b/c can be used for multiple purposes • Not control for mechanism for proper use

• Address translation

Address generated into: • Page number (p) • Used as an index into a page table which contains base address of each page in physical memory • Page offset (d) • Combined with base address to define the physical memory address that is sent to the memory unit

• Chapter 7: Synchronization Examples • Bounded Buffer Problem

Also called Producer-Consumer Problem N buffers, each can hold one item, 2 processes • Producer - tries to insert and item into empty slot in buffer • Consumer - tries to remove the item from a filled slot in the buffer 3 requirements • 1) Producer (P) must not inert item when buffer is full • 2) Consumer (C) must not remove item when buffer is empty • 3) P and C should not insert and remove at the same time A potential issue is a Race condition How to address the problem • Use Semaphore How many semaphores do we need? • 3 (mutex, full, and empty semaphores) Code Example • mutex = 1 empty = N //size of buffer (3) full = 0 Producer() { wait(empty); // if not empty wait(mutex); // -- // produce data // insert data count++; signal(mutex); //++ signal(full); //++ } Consumer() { wait(full); // if not full wait(mutex); //-- // produce data // insert data count--; signal(mutex); //++ signal(empty); //++ }

• Caching - Using faster device holding copy of data

Always just a copy • Buffering - holds unique copy of data • Caching - holds redundant copy of data Key to performance (e.g. TLB) Improve disk performance by reducing the number of disk cess • Keep recently used disk blocks in main memory after the IO call that brought them into memory completes What should happen when we write to a cache • Write-through • Write data through to disk as soon as they are placed on any cache • Reliable, but poor performance and scalability (distributed systems) • Delayed-write (write-back) • Modifications are written to the cache and then written through to the disk later • Advantage - Faster • Disadvantage? - Consistency, potentially losing data (data availability) read() Operation • 1. read() call - User process requests a read from a device • 2. OS moves the process to I/O wait queue • 3. OS checks if data is in a buffer. If not • a. OS tells the device driver to perform input • b. Device driver tells the DMA controller (src/desc locations, command) • c. DMA controller transfers the data to the kernel buffer when it has all been retrieved from the device • d. DMA controller interrupts the CPU when the transfer is complete • 4. OS transfers the data to the user process and places the process in the ready queue • 5. When the process gets CPU, it resume the execution

• Binary Translation

Binary translation is developed to process critical instructions Critical instructions - Sensitive but not privileged instruction In virtualization, there are 2 instruction types • 1) Sensitive instructions • Those instructions that interact with hardware • Mostly privileged instructions • E.g. modify page table, registers, Software interrupt • 2) Non-sensitive Instructions • All other instructions • Non-privileged instructions • E.g. normal arithmetic instructions Could all CPUs be fully virtualizable • Only if the set of sensitive instructions is a subset of privileged instructions (No Critical Instructions) Binary translation module is used to skip or modify the guest OS binary code blocks which include critical instructions Translate those critical instruction into privileged instructions which will be trapped by Hypervisor for further evaluation Hypervisor translated all critical instructions at runtime on-the-fly Time consuming and large performance overhead VMWare uses optimization techniques like caching • Translate once, and cached translation instead of translating again

• Blocking, nonblocking, and Asynchronous IO

Blocking - process suspended until IO completed • Synchronous IO system calls vs. Asynchronous Data transfer from devices • Very intuitive - easy to use and understand • Insufficient for some needs Non Blocking - IO call returns as much as available • Used for interface, data copy • Receives keyboard/mouse input while displaying data on the screen • A video app the reads frames from a file while simultaneously displaying the output • Implemented bia multithreading • Some threads are performing blocking IO • Some threads continue with the execution • Returns quickly with count of bytes written or read • Use synchronization tools like Semaphores The analogy of blocking vs nonblocking • Web Server with single thread (listener and worker) • Web Server with multiple threads What are drawbacks of blocking and nonblocking • When issuing IO calls, context switching happens (preemption) • Process goes to IO wait queue (for long or short time) • Too many IO calls in low CPU utilization Asynchronous - process runs while IO executes • When a process issues a system call for async IO • System call returns immediately and background process in kernel performs IO operation • The caller process does its job • When IO is completed, background process triggered software interrupt, signal, or call-back routine • aio_read(), aio_write()

• Readers and Writers Problem

Classic synchronization problem in Data sharing/management systems A data set is shared among a number of concurrent processes • Readers - only read the data set • Writers - only read and write Requirements • 1) If two or more readers access the shared data at the same time, no adverse effects will result • 2) No simultaneous access from a writer and some other readers/writers -- no reading while data is being updated • 3) Writers should have exclusive access to the shared data • If a writer is updating data, no other readers or writers are allowed to access the data Example Code • count = 1 reader_count = 0 sem_t mutex = 1 Rc_lock = 1; writer() { lock(mutex); count = count*10; unlock(mutex); } reader() { lock(rc_lock); if (++read_count == 1) lock(mutex) unlock(rc_lock); printf("count = %d", count); lock(rc_lock); if (--read_count < 1) unlock(mutex) unlock(rc_lock); } Limitation • Starvation for writers with multiple readers Real world examples of Readers-Writers Problem • Databases • Bank systems

• Compaction + Swapping

Compaction • Solution to external fragmentation • Relocate existing process to make a larger hole • Which one is better of 2 approaches • # of movement • Possible free block (hole) size • Only possible if relocation is dynamic and is done at execution time • IO Problem • Latch job in memory while it is involved in IO • You cannot do compaction when a process is performing IO operation Swapping • Is the swap sector part of the file system? • NO, users cannot access swap space • Swapping: removing process from memory to disk, later the process will be reloaded into memory • Swap out: memory → disk • Swap in: disk → memory • Why is swapping relevant to memory management? • When proc becomes active (swap-in) OS must reload it into memory • With dynamic relocation OS finds a new position in memory for the process and updates the relocation and limit registers • If swapping is part of system, compaction is easy to add • When do "swap-in", this is great time to do compaction

• Copy-on-Write (COW)

Copy on write allows both parent and child processes to initially share the same pages in memory • vfork(): virtual memory fork • If either processes midiries a shared page, only then is the page copied • Faster process creation + efficient memory use COW allows more efficient princess creation as only modified pages are copied • vfork(): • Chile using COW address space of parent • Designed to have child call exec() • Very efficient

• Too Much Milk Problem

Correctness • Someone buys if needed • At most one person buys Atomic operations are not guaranteed here Concurrent programs or multi threads are non deterministic due to many possible interleaving Person A & B are not taking to eachother, but use a not to avoid buying too much milk • Leave note before leaving • Remove note after buying mile • Don't buy milk if there is note Lessons from milk problem • Obvious code often has bugs, so solution is complicated • Modern compilers/architectures reorder instructions, making reasoning even more difficult • Generalizing to many threads.processors • Even more complex

• Create a file

Create "/foo/bar" This will be on final exam Steps • 1. Read i-node for "/" • 2. Read root data to find i-node # for "foo" • 3. Read i-node # for "foo" • 4. Read "foo" data to check the block is available • 5. Read i-node bitmap for "bar" (find available slot) • 6. Write i-node bitmap (check it for in-use) • 7. Write foo "data" (i-node # for "bar") • 8. Read i-node for "bar" (check if ok) • 9. Write i-node for "bar" • 10. Write i-node for "foo" (foo data block id)

• Full Virtualization

Hypervisor enables VM identical to real HW machine • Virtual machine == Real hardware • E.g. Virtual Box, VMWare Workstation Everything is virtualized (same HW CPU) Full HW emulation • Technically Very difficult, but latency! Unmodified Guest OS to be run in isolation Building blocks of Full Virtualization • 1) Trap-and-Emulate • 2) Binary Translation

• Storage space allocation methods

Disk is a series of blocks 1) Contiguous allocation • OS allocates a contiguous chunk of free blocks when it creates a file • FCB has start location and length • Old method • Disadvantages (Same problems with memory contiguous allocation) • 1) Finding free space • First Fit (Faster), best fit (slightly better space efficiency) • 2) External fragmentation • Holes are created that may nor be able to fit new files • Compaction Offline disk compaction - copy everything to another storage, then rewrite to the original storage (w/ compaction) Online - disk defragmentation is very slow • 3) Changing file size (file growth limited) • The next block may be taken by another file • Error return or copy to larger hole • Advantages • Easy to implement • Minimizing head movement (HDD) - sequential read 2) Linked allocation • Each file is a linked list that can be scattered • FCB has a pointer to the first and the end block • Each block has a pointer to the next block • Advantages • No external fragmentation • File size change • Very nice for sequential access • Disadvantages • Good system for SSD, very bad for HDD because a lot of head movement • No random access • Many seek operations (frequent head movement) • Wasted space due to pointer (cluster/grouping) • Example: FAT (File Allocation Table) 3) Indexed Allocation • Index block has pointers to all other blocks • Advantages • Direct (Random) Access • No external fragmentation • No file limit, just add new block to index block • Disadvantages • Design of index block • FS wants a small index block but it should support large files with a large number if indices

• Bonus Chapter. Advanced Topics - Distributed systems, computer Networks, and Virtualization • Distributed systems

Distributed systems - A Collection of loosely coupled nodes interconnected by a communication network Nodes variously called processors, computers, machines, and hosts • Site is location of the machines, node referees to the specific system. • General a server has resources, remote client nodes use the resources Parallel computing and Distributed systems • Parallel computing • Tightly coupled • Processors share clock, mem, and run one OS • High performance computing • Frequent communication • Distributed System • Loosely coupled system • Networked computing • Each processor (node) has its own memory and runs an independent OS • Sometimes centralized storage (early NFS) • Cluster computing • Generally has larger scalability • Every node in cluster should be in same network segment

• Trap-and-Emulate

Dual Mode Operation (Kernel and User Mode) • Privileged Instructions - OS kernel and device driver access to the system hardware • Non Privileged instructions - only running in user mode (e.g. Arithmetic operations) Dual Mode CPU (Full Virtualization) • • Guest VM has virtual kernel and user modes, but it doesn't know if it is virtualized so it will cause issues when it tries to run privileged instructions from user mode • Procedure • 1) Attempting a privileged instructions in user mode causes an error → TRAP • 2) Hypervisor gains control, analyzes error, executed operations as attempted by guest OS • 3) Return control to guest OS in user mode • 4) this process is called TRAP-and-EMULATE User mode code in guest OS runs in same speed as if not guest OS • No performance hit in user mode But kernel mode and privileged instructions runs slower due to trap-and-emulate • Especially a problem when multiple guest OSes are running, each needing a TRAP-and-EMULATE

• Read a file

Open "/foo/bar" Assume that "/foo/bar" has been accessed recently Must write for 3rd operation because it needs to write access time •

• EAT with demand paging

EAT (Effective Access Time) • EAT = (1 - p) x memory access time + p x (page fault time) • Page fault time consists of one memory access and disk IO • Page fault overhead + swap page in • In general, page fault time is determined by disk access time • Swap page in: read from disk, loaded to memory • Disk access time is slower than memory access time Example • Memory access time = 200 nanosec • Average page fault time = 8 ms • EAT = (1-P) X 200 + p x (8ms) • = 200 + p x 7,999,800 • If want performance degradation < 10% (over mem access time) • 220 > 200 + 7,999,800 x p • P < 0.0000025 • P < one page fault in every 400,000 memory accesses • P must be very low • This is feasible in practice • Because page fault is very rare because of locality

• Effective Access Time (EAT) with Paging

Effective access time (EAT) • What is EAT is page table is in memory • 2 memory access time • EAT = 2 * MAT (mem access time) • What is EAT with a TLB • TLB hit ratio:p, TLB: TLB Access time • EAT = (TLB + MAT) * p + (TLB + 2 * MAT) * (1 - p) • As p increases, EAT decreases

• Deadlock Prevention

Eliminate Mutual exclusion • Shared resources do not require mutual exclusion (Eg read-only files) • Potential issue - Some resources cannot be shared (at the same time) Eliminate hold and wait • Either not wait or not hold • Can you make a not-wait policy? • Each process holds all of its resources before its begins execution • Eliminates wait possibility • Can you make a not-hold policy? • Only allow the process to request resources when it currently has none • Eliminates the hold possibility • Problems - Low utilization or Starvation Eliminate No Preemption • Similar to hot-hold policy • Make a process automatically release its current resources it cannot obtain all the oned it wanted • Restart the process when it can obtain everything • Alternatively, the desired resource can be preempted from other waiting processes • Problems - Not all resources can be easily preempted Eliminate Circular wait • Imposing order on the resources and request them in order • If a thread holds resource i, then it can always request and acquire resources > i • If a thread holds resource i, then it cannot request and acquire resources < i Each technique can cause • Low resource utilization • Starvation • Not implementable

• Fragmentation

External fragmentation • Frequent loading and unloading program causes free space to be broken into little pieces • External fragmentation exist when there is enough memory to fit process in memory, but space is not contiguous • 50 percent rule: for every 2N allocated blocks, N blocks are lost due to fragmentation • 1/3 of memory space is wasted • We want an allocation policy that minimizes wasted space Internal Fragmentation • Allocated memory may be slightly larger than requested memory and not being used • Internal partition is wasted • When memory y is allocated to a proc, the proc has some empty space • Why internal fragmentation happens • Consider a process of size 1MB and there is a free space of 1MB + 2 bytes • The overhead to keep track of this 2 bytes hole will substantially larger than the hole itself

• Frame allocation mechanisms for multi-programming

Fixed allocation • Equal allocation -- eg if there are 100 frames and 5 processes, give each process 20 frames • Problem is doesn't consider actual size of process • Proportional allocation - allocate according to the size of the process • Dynamics in multiprogramming, proces size changes • Allocation = (proc size / all proc size) * total number of frames Global vs local allocation • Global allocation - process selects a replacement frame from the set of all frames; one process can take a frame from another • Process selects a replacement frame from the set of all frames; one process can take a frame from another • Use single LRU for all pages • Great throughput, flexible memory use, so more common • Process exec time can vary greatly • Pros • Flexible, adjusts to divergent process needs • Cons • No per-process isolation. Thrashing might become more likely • Thrashing: high paging activity ( page fault/ replace again, again, again, . . .) • Local allocation - each process selects frame from only its own set of allocated frames • Each process selects frame from only its own set of allocated frames • Per process allocation • More consistent per-process performance • Not necessarily faster, just consistent • Isolation, protected processes • Shortage of memory frame process A does not affect page fault of other processes • Disadvantages • Possibly underutilized memory • May not give a process enough memory, may be bad performance

• Open a File

Open "/foo/bar" Assume that "/foo/bar" has not been accessed recently •

• Page Replacement algorithms

Four Total: • FIFO • OPT (aka MIN) • LRU (Least Recently Used) • Random FIFO (First in, First out) • Evict the oldest page, simple to implement • FIFO doesn't care about access frequency • OS can easily throw out a page that is being accessed frequently • May increase disk access • In example, has 7 page faults OPT (optimal page replacement) (aka MIN) • Evict the page that will not be access for the longest time • Hard to know the future • In example, has 5 page faults LRU (Least Recently Used) • Approximation of OPT that works well if the recent past is a good predictor of the future • Evict a page that has not been used in the longest time • In example, has 6 page faults • LRU will perform badly when pages have been accessed repeatedly Random • Random replacement works well in practice

• IO Device control Registers

Four registers for device control • Status: indicates a device busy, data ready, or error condition • Containing bit that can be read by CPU • Control: command to perform in device • Written by CPU • Data-in: Data being sent from the device to the CPU • Read by CPU • Data-out: Data being sent from the CPU to the device • Written by CPU

• Types of Virtualization

Full virtualization Paravirtualization OS-level (or Process-level) Virtualization • Containerization e.g. Docker Application-level Virtualization • Java VM • WINE

• Full Virtualization VS Paravirtualization

Full virtualization • No source code modification • Overhead form Trap-and-emulate and binary translation • Pros • No changes to OS • No source code modification • Easy to use • Cons • Slower • Latency from OS/HW emulation • Hard to provide real-time guarantee • Latency • 1) RAM (75% slower) • 2) DiskIO (20% slower) • 3) netIO (10% slower) • 4) CPU Privileged Instruction (7% slower) Paravirtualization • OS cooperates with hypervisor • Minilam changes to OS which results in better interaction between the OS and virtual hardware • Faster, but relatively poor portability • Pros • Performance, Faster • Feasible for all CPU Architectures • Cons • - OS Modification • Poor portability • Precludes off-the-shelf OS and legacy ve

• Second Chance Algorithm

Generally FIFO, plus Hardware-provided reference bit • A single reference bit per page • Clock requirement Steps: • 1) OS keeps frames in a circular list • 2) on reference , set page reference bit t o 1 • 3) on page fault, OS • a) checks the reference bit of the next frame (containing a page) • b) replaces the page, and set its bit to 1 if the reference bit is 0 • c) sets the bit to 0, and advance the pointer to the next frame if the reference bit is 1 Single reference bit per page • Categorize pages into 2: young and old • Cost of Second chance algorithm • Cost: updating 1 bit of pages (stored in TLB) • Worst case: all bits are 1

• What is paging?

Give up contiguous memory allocation in physical address space and try to address external fragmentation 90/10 rule: Processes spend 90% of their time accessing only 10% of their memory Physical address space of a process can be non-contiguous • Logical mem needs to be contiguous • Avoids external fragmentation • Avoids problem of carrying sized mem chunks Divide physical memory into fixed sized blocks called frames • Size is power of 2, from 512 bytes to 12 Mbytes • By dividing mem into fixed size frames we can eliminate external page fragmentation Divide logical memory into blocks of same sized pages OS keeps track of all free frames To run a program on size N pages, need to find N free frames and lead the program Set up a page table to translate logical address to physical address Paging does not address internal fragmentation

• Memory allocation policies

How to satisfy the request of size n from a list of free holes First-Fit: use the first hole that the process will fit in, Best-Fit: Use the smallest hole that is just large enough for the process. Must search the whole list unless ordered by size. Worst-Fit: allocate the largest hole available. Must search entire list What is best policy First fit VS Best fit • Both can leave many small and useless holes • To shorten search time for First-Fit, start the next search at the next hole following the previously selected hole. (this is called next-fit) • In practice, first fit and best-fit are better than worst fit. First fit generally faster than best fit

• Virtualization Terminologies

Hypervisor (Virtual machine Monitor • Software that creates and runs virtual machine Virtual Machine • Software abstraction that mimics the characteristics of a physical server • Same input/output and behavior expected from real hardware • Host, Guest VM Guest OS • OS installed on Virtual machine

• Paravirtualization

Hypervisor enables VM that are similar but not 100% identical to the physical hardware • VM != real HW (but similar) • Developed for CPUs that cannot be virtualized • Hypervisor does not emulate hardware (FAST!) • E.g. Xen, VMWare ESX Server Unfortunately, it requires OS modification • USes special APIs that a modified OS must use • But, no modifications to ABI • What is ABI (Application Binary Interface) • E.g. library, DLL • What if questions for ABI modification • Not required No change for App source code Can run the same binary on Guest OS on para-virtualization • Required Recompile all Aps Are people going to use this technique (although it's fast) How to modify all the apps (feasibility )

• Journaling (Write Ahead logging)

Idea: When updating the disk, before overwriting the structures in place, first write a plan for update operation ("write ahead") as a form of "log" • Write ahead logging If crash takes place during the update (e.g., overwrite) • After the crash, FS can go back and look at the logs, and then try again; FS knows exactly what to fix • Instead of scanning the entire disk (fsck) EXT3 FS Structure • Disk is divided into block groups • • ext3 file system with journaling • • Journaling block: difference between ext2 and ext3 • Super block has a pointer to locate journal block

• Deadlock Avoidance

If OS has prior knowledge of how resources will be requested, it is possible to determine if threads are entering an unsafe state Possible States are • Deadlock: no forward progress • Unsafe state: state may allow deadlock • Safe state: deadlock will not happen, threads/processes are safe

• Resource allocation graph/Wait-for Graph

If graph has no cycle, no deadlock exists If there is a cycle, deadlock might exist Wait-for graph If any instance of a resource involved in the cycle is held by a thread not in the cycle, then we can make progress when that resource is released

• Enhanced Second chance algorithm

Improve algorithm by using reference bit and modify bit Reference bit: page access Modify bit: change in the page What Is the difference between a modified page and an unmodified page when performing swap out? • Only overwrite the changed data to disk Goal is to reduce overhead and IO Page replacement in enhanced Second chance • The idea is to find a page with (0,0) and replace it • OS goes around at most 3 times searching for this class • 1) page with (0,0) → replace the page • 2) Page with (0,1) → initiate IO to write out the page , lock the page in mem until IO completion, clear the modified bit and continue to search • 3) For pages with reference bit set, the reference bit is cleared • (1,0) → (0,0) • 4) if OS finished the first round and there was not (0,0) page, • On the second pass, a page that was originally (0,1) or (1,0) might have been changed to (0,0) → replace the page • If the page is being written out, waits for IO completion and the remove the page • On the second pass, a page that was originally (0, 1) or (1, 0) might have been changed to (0, 0) → replace this page • If the page is being written out, waits for I/O completion and then remove the page • A (1, 0) page is treated as on the first pass, it will be the best candidate in the next pass • By the third pass, all the pages will be at (0,0)

• Liveness

Liveness refers to a set of properties that a system must satisfy to ensure processes make progress. Indefinite waiting is an example of a liveness failure.

• Soft (symbolic) link

Ln -s - same as creating shortcut A soft link only makes a symbolic pointer from one file to another Removing B does not affect A Removing A leaves the name B in the directory, but its contents no longer exists

• Hard link

Ln command - Makes links between files A hard link adds a second connection to a file Creates another file, but it refers to the same file FS maintains reference counts, so it will only delete a file after the last link to it has been deleted Problems • Can create circular link with directories and then OS can never delete disk space

• Locality of references

Locality of Reference refers to the tendency of the computer program to access instructions whose addresses are near one another Temporal locality • If a process access an item in memory, it will tend to access the same item again soon Spatial locality • If a process accesses and item in memory, it will tend to reference and adjacent item soon

• Chapter 13: File System Interface • File

Logical unit of data on a storage device (disk). A collection of related information stored in secondary storage (Formal Definition) An array of bytes which can be created, read, written, and deleted • Generally a file has two names; use-space (e.g., test.txt) and a unique low level name (i.e., a number) • The low-level name is often called an i-number (i-node in Unix/Linux)

• Chapter 9: Main Memory • Terminology

Main memory - the ram in the system Segment - a chunk of memory assigned to a process • Contiguous allocation Physical address - a real address in memory Logical (virtual) address - an address relative to the start of a process' address space

• File system

Managing files and directories Essentially managing secondary storage (disk) as a form of files and directories in a reliable and efficient manner

• Mutex

Mutual Exclusion • To protect critical section and prevent race condition Simplest is mutex lock • Bool var indicating if lock is available or not Protect a critical section • First acquire() a lock • Then release() the lock acquire() and release() must be atomic Requires busy waiting • This lock therefore called a spinlock Rules for using mutex lock • 1) Lock is initially free • 2) Always acquire before accessing shared data structure • 3) Always release after finished with shared data • 4) Never access shared data without lock

• Dining-Philosophers Problem

N philosophers sit at a round table with a bowl of rice in the middle Philosophers spend their lives alternating thinking and eating When Thinking, no interaction with others When hungry, tries to pick up 2 chopsticks • Can only pick up one chopstick at a time • When they have 2 chopsticks, can start eating • When finished eating, released both chopsticks one at a time Challenge is 2 philosophers cannot access a chopstick at the same time Shared data is • Bowl of rice (data set) • Chopsticks (binary semaphore initialized to 1) Approach • 1) Represent each chopstick as a semaphore • 2) a philosopher tries to grab a chopstick by executing wait() operation • 3) Philosopher releases their chopstick by executing signal() operation • 4) The shared data are semaphores (binary semaphore) chopstick[5], where all chopsticks are initialized to 1. • chopstick is available (free, value == 1) • chopstick is not available (used by someone else, value == 0) Structure of philosopher i semaphore chopstick[5] Phil() { // do thinking // gets hungry // pick up the right chopstick wait(chopstick[i]) // pick up the left chopstick wait(chopstick[(i+1)%5]) // eating //release right chopsticks wait(chopstick[i]) //release left chopsticks wait(chopstick[(i+1)%5]) } Pros • No two neighbors are eating simultaneously Cons • Deadlock - every philosopher picks up the right chopstick and then all of them have one chopstick each How to avoid deadlock • 1) Make at most 4 seats available • 2) Make it so only odd num seats can try to eat, then even and so on • 3) Only let philosopher pick up chopstick if and only if both are available Real-world applications • Cooperating processes require shared limited resources • Disk backups, travel reservations

• DMA (Direct Memory Access)

New hardware - DMA controller Use DMA controller that can write directly to memory • Instead of data-in/data-out in controller register. (no PIO) Procedure of Data transfer with DMA • 1) The CPU provides the DMA with the locations of the source and destination of the transfer • How?: Writing command block into memory • Command block has two pointers ("source" and "destination"), and size of the block • 2) The DMA controller operates the bus and interrupts the CPU when the entire transfer is complete, instead of when each byte is ready. • 3) The DMA controller makes the CPU a little bit slower • Bus contention - Data transfer uses a shared memory/data bus - resource contention with (CPU - MEM) • CPU gives higher priority to DMA - controlled data transfer (called cycle stealing) • But, much faster than PIO (status-register-based transfer)

• File system consistency checker: fsck

Not try to fix all inconsistency problems Goal is consistency in FS meta data 1) Prohibitively slow • Basic mechanism: Scanning the entire disk to find all the allocated blocks and read the entire directory tree • Particularly bad for RAID • 512GB > 1 hours 2) Only addressing metadata consistency • No knowledge about file context/history • Reformatting for meta data consistency

• Protection

OS Must allow users to control sharing of their files • Control access to files Grant or Deny access to file operations depending on the protection info Access list and groups (Windows) • Keep and access list for each file with the user name and type of access • List can become large and tedious to maintain Access control bits (Unix) • Three categories for users (owner, group, world) • Three types of access privileges (Read, write, execute) • Maintain a bit of reference for each combination

• Demand paging workflow

OS loads page the first time it is referred Process must give up CPU while the page is being loaded (because of preemption on CPU scheduler) • How long does it take to load a page from disk to memory? - disk access time If the page is full? • Page replacement Page-fault: interrupt that occurs when an instruction references a page that is not in memory • Page request → not in memory → go to disk and load it to memory • What is the cost of page-fault? - disk access is expensive; need to consider pre-paging again

• LRU approximation - two algorithms

Option #1 • Keep a timestamp for each page with the time of the last access, then evict LRU pages • Unfortunately, this is expensive approach • OS mus record time stamp for each memory access and then evict a page • The OS has to look through all the pages Option #2 • Keep a list of pages • The front of the list is the most recently used • End of the list is the least recently used • On a page access, move the page to the front of the list • Doubly linked list can be used • Unfortunately this option is still expensive, since the OS must modify multiple pointers on each memory access Approximation Page Replacement • HW requirements: maintain reference bits with each page • On each access to the page, the HW sets the reference bit to '1' • Set to '0' at varying times, depending on the page replacement algorithm • Additional Reference Bits: 8 bit system • On reference, set high bit to '1' • At regular intervals or on each memory access, shift the byte right, placing '0' in the high order but • On page fault, the lowest numbered page is kicked out • Both are approximation based, no total order on page • Faster , since setting a single bit on each memory access is faster • Page fault still requires a search through all pages, but still faster

• Chapter 6: Synchronization Tools • Race condition

Output of concurrent program depends on the order of operations between threads Preemptive can result in race conditions when data is shared between multiple processes

• What is a paging table?

Page table keeps track of the page frame in memory where the page is located Small page/frames size or Large page/frame sizes? • Each page table entry takes memory to track • Page sizes are growing over time A page table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual addresses and physical addresses.

• Chapter 12: I/O Systems • IO Hardware

Port • Connection point for devices Bus • Allows multiple devices to communicate with CPU, typically shared by multiple devices • Bus is composed of Three lines ( or HW wires). • Address, Data and Control Controller • Receives commands from system bus, translates them into devices actions and reads/ writes data on to the system bus • A collection of electronics that operates port, bus, device

• Prerequisites and necessary conditions for deadlock

Prerequisites • Multiple threads/processes • Finite resources • Multiple threads are competing for resources Deadlock can happen if all following conditions hold: • Mutual exclusion - at least one thread must hold a resource in non-shareable mode • The resource may only be used by one thread at a time • Hold and wait - at least one thread holds a resource and is waiting for another resource(s) to become available. • No preemption - a thread can only release a resource voluntarily; another thread or the OS cannot force the thread to release the resource • Circular wait - a set of waiting threads {T_1, . . .,T_n } where T_i is waiting on T_i+1 (i = 1 to n) and T_n is waiting on T_1 .

• Contiguous memory allocation

Problem - dynamic nature of the process / As the processes enter the system, grow, and terminate, OS must keep track of which memory is available and utilized. Variable Partition in memory allocation • Multiple partition allocation • Degree of multiprogramming limited by the number of partitions • What is degree of multiprogramming • The number of processes currently in memory • Variable partition sized for efficiency (sized to a given processes needs) • Why variable partition sizes? • B/C process can grow • Hole - block of available memory; holes of various sizes are scattered through memory • When a process arrives, its allocated memory from a hole is large enough to accommodate it • Process exciting frees it partition adjacent free partitions are combined • OS maintains information about: a) allocated partitions b) free partitions (hole)

• MetaData Journaling

Problems of Data Journaling • 2 disk writes of data blocks • Data block content is typically bigger than i-node or bitmap Metadata Journaling is to reduce disk operation for data block to one disk write • Data journaling: two disk writes of data block • Metadata journaling: one disk write of data block Metadata Journaling Sequence • 1. Data block write • Write data to final location on disk; wait for completion • 2. Journal metadata write • Write the TxB, I[v2], and B[v2] to the journal log; wait for writes to finish • 3. Journal commit • Write the transaction commit block (TxE) to the log; wait for the write to complete; the transaction (including data - step #1) is now committed. • • 4. Checkpoint metadata • Write the contents of the metadata update to their final locations w/i FS. Metadata Journaling Summary • Reduced disk I/O overhead! • Data blocks are typically large • Need just one write operation in metadata journaling • But, two write operations for meta data (i-node, bitmap) • FS always trusts metadata in journal • This is why "Starting data write first, then write metadata to journal" • If crash occurs after data block write while metadata is being written Ignore data block because there is no metadata

• Advantages of distributed systems

Resource sharing • Share files or remote HW resources (Storage, GPU) • Process info in a distributed database, NoSQL (Not Only SQL) Computation speedup and High performance • Divide and conquer, MPI (Message Passing Interface), Map-Reduce • Load balancing - moving jobs to more lightly-loaded sites/nodes Reliability • Detect and recover from node failure • Hot standby, Data replication Communication • Supporting networked environment

• File locks

Shared (similar to reader lock) • Multiple processes can acquire concurrently Exclusive (more common) • Mandatory (Windows) • Only one process accesses a file at a time • Holding proper file lock is required • Possible deadlock and starvation for low priority processes • Advisory (UNIX) • Processes can coordinate file locks

• Directory Structure

Single-level Directory • One namespace for the entire disk, every name is unique • If one user uses a name, no one else can have the same name • Some early computers used this strategy because their disks were very small Two-level directory • Each user has a separate directory, but all of each user must use unique names • Tree-structure Directory • Tree structured name space • Store directories on disk, just like files • Only difference is the FCB for directories has a special flat bit • Directory is a special type of file • Read: User programs read directories just like any other files • Write: oly special system calls can write to directories • Removal of directory • If dir is empty, then delete it • If not empty • Require user to empty the directory • Other issues due to • Difficult to share file across tree-structured directories and users due to permission/protection • A single file May have multiple file names (referential naming) •

• Small page size vs Large page size

Small size • More efficient memory use / Less internal fragmentation • Higher degree of multiprogramming is possible Large size • Smaller page table (less overhead) • Amortizes disk overhead over a large page • Fewer page faults (locality of reference)

• How does deadlock differ from starvation?

Starvation means thread is making process by requesting resources but never getting the needed resource In starvation, the program makes process, while in deadlock program makes no progress

• Data Journaling

Step #1: Journal Write • Suppose FS is to write i-node, bitmap, and data • Before writing them to disk, FS writes them to the log (journal) • • "Journal write" is also disk operation! - Writing journal log on disk Step #2: Checkpoint • Update data structure (e.g., bitmap, i-nodes, data) in ext3 (Disk) • The second disk operation

• Buffering

Store data in memory while transferring between devices 2 Buffers • Device buffer • IO Devices typically contain a small onboard buffer where can store data temp before transfer to CPU • Disk buffer stores block when it is read from the disk • It is transferred over the bis by the DMA controller into a buffer in physical memory • The DMA controller interrupts the CPU when the transfer is done. • OS Buffer • why does OS need a buffer? • To cope with speed mismatch between devices (E.g. received file over a network (slow) to store to disk (fast) ) • To cope with devices that have different data transfer size (e.g. FTP server brings the file over the network one packet at a time. Stores t osdisk on block at a time ) • To minimize the time a user process is blocked on a write

• On Disk Structure (EXT-like File System)

Suppose we have a small disk composed of 64 * 4kb blocks Super block • Information about this particular file system • # of all i-nodes and data blocks are in the FS • Information about where the i-node block begins I-node bitmap • 0: Associated i-node block is free • 1: Associated i-node block is in-use Data bitmap • 0: Associated data block is free • 1: Associated data block is in-use

• Application IO interface

The OS provides an high level interface to access devices • This greatly simplifies the programmers job • OS uses standard interfaces • There are devices dependencies • IO mechanisms can vary from device to device but the dependencies are encapsulated in device drivers • New devices come with new device drivers. Device characteristic • 6 total: • 1. Transfer-Unit: Block Device or Character-Stream Device • 2. Access-Type: Sequential or Random Access • 3. Timing: Synchronous or Asynchronous • 4. Sharable or Dedicated • 5. Speed of Operation • 6. Read-Write, Write-Only, Read-Only • Transfer Unit: Block device or character stream device • A character stream device transfer bytes one by one where as a block device transfers a block of bytes as a unit • ACcess-Type : Sequential or random access • Sequential: Keyboard, NIC • Random: Disk (HDD, SSD) , GPU • Timing: synchronous or Asynchronous • Synch: data transfer with predictable response time • Asynch: Irregular data gransfe, typically unpredictable response time • Most devices are asynchronous, while I/O system calls are synchronous • OS implements blocking I/O • Sharable or Dedicated • A sharable device can be used concurrently by several processes or threads; a dedicated device cannot • Disks are typical sharable devices • Printer and scanner are not sharable • Speed of Operation • Device speeds range from a few bytes per sec. to gigabytes per sec. • Most devices are slow (except for disk and GPU - these are super fast) • Keyboard is slow device.

• Logical vs Physical address space

The concept of a logical address space that is bound to separate physical address space is central to proper memory management • Logical address - generated by the CPU; also referred to as virtual address • Physical address - address seen by the memory unit Logical address space is the set of all logical addresses generated by a program Physical address space is the set of all physical addresses generated by a program Why need Logical address space • Process memory may grow with dynamic memory allocation(with malloc) • Virtual memory has no idea about the actual physical limit Size comparison • Logical space does not equal (!=) physical address space

• Device Drivers

This is basically an interface that communicates with a device What is a simple way to communicate with a device? • Busy waiting • This is the idea of polling • Simplest way to implement a device driver Polling • This is how polling works; for each byte of IO • 1) the host repeatedly (busy waits) reads the busy bit (in status register) until that bit becomes clear (idle). • 2) The host sets the write bit in the command register and writes a byte into the data-out register. • 3) The host sets the command-ready bit in status register. • 4) When the controller notices that the command-ready bit is set, it sets the busy bit. • 5) The controller reads the command register and sees the write command. It reads the data-out register to get the byte and does the I/O to the device. • 6) The controller clears the command-ready bit, clears the error bit in the status register to indicate that the device I/O succeeded, and clears the busy bit to indicate that it is finished. • Step 1: the host repeatedly busy waits. • Busy wait cycle to wait for IO from device • Is this ok? Reasonable if device is fast Inefficient if device is slow If the device is slow, then can the CPU switch to another task? Generally yes, but if CPU misses a data-write cycle, CPU may lose data Because data from devices are stored in the buffer is controller, but the buffer size is typically small. • Busy waiting is not good • Alos polling requires the CPU instructions cycles 1) read a device register Interrupt-Driven Approach • Process is simple • 1) CPU asks device fir IO operation • 2) CPU performs other tasks • 3) device is doing IO • 4) When device finishes IO, it generated interrupt • 5) CPU checks interrupt after each instruction • Where interrupts from devices should go? • CPU ahs interrupt request line • Interrupt triggered by IO devices • Checked by CPU after instruction cycle • HOw are interrupts processed • Interrupt handler receives interrupts Non Maskable interrupts - unrecoverable memory error Maskable interrupt - to ignore or delay some inputs • Then, Interrupt vector table to dispatch interrupt to correct interrupt handler routine (in memory) • Programmed IO (PIO) Typical data transfer mechanism CPU sends and received data (status bit) in controller register • One Byte at a time • Interrupt doesn't help a lot for large data transfer • CPU sends and received data (status bit) in controller register • "One byte at a time" • Interrupt doesn't help a lot for large data transfer - why? CPU has to check interrupt-request line per every instruction and move to handler routine Think about 1GB data transfer, each interrupt happens at every 1 byte data transfer

• Copy-on-Write

This is different from COW in memory New updates in a file are placed in previously unused locations on disk. After completion of updates, COW FS flips the root structure of the FS to include pointers to the newly updated structures. Doing so makes keeping the file system consistent and straightforward. Early idea: Log-structured File System (LFS)

• Address binding

Three stages of when will a program's address be determined • 1) Compile time (by the compiler) • The compiler generates the exact physical location in memory (absolute code). OS does nothing • 2) Loading time (by loader and linker) • Compiler generated an addres (relocatable code) but at load time, loader and linker determine the process' starting position. Once the process loads, it does not live in memory • 3) Execution time (by OS) • Compiler generated address and OS can place it anywhere it wants in memory • Beed HW support (registers + MMU)

• What is TLB?

Translation look-aside buffer (TLBs) • AKA Associative memory • Basically stores page numbers (key) and the frame (value) • TLB must be flushed (erased) at every context switch • Because processes do not share keys so need to clear and update keys • TLBs typically small (32 to 1,024 entries) • On a TLB miss, value is loaded into the TLB (from page table) for faster access next time (L1 Cache) • Replacement policies must be considered (LRU) • Some entries can be wired down for permanent fast access

• 2 Types of Hypervisors

Type 1: Bare Metal (Native) Hypervisor • Hypervisor implemented directly on physical hardware • Hypervisor preforms scheduling and allocation of system resources • E.g. VMWare ESX Server, Xen • • Pros • Performance (no additional HW layers) • Security (Ho possibility of attack form Hosted OS) • Cons • Complex Type 2: Hosted Hypervisor • Hypervisor built completely on top of host OS • Host OS provides resource allocation and standard execution environment to each guest OS • e.g. VirtualBox • • Pros • Simplicity • Hosted OS takes care of all hardware • Cons • Single point of failure • What if base OS needs a reboot

• 3 Communication mechanisms

UDP (User Data Protocol) • Simple lightweight, but unreliable • Connectionless, Fire and Forget • Cons • The system will encounter situations where packets get lost (dropped) and thus do not reach their destination • The sender will not be informed of the loss • In general, UDP provides a minimal level of reliability • E.g. checksum: to detect come forms of packet corruption • Pros • Lightweight • Can improve reliability by adding application level retransmission mechanisms TCP (Transmission Control Protocol) • Reliable, more complicated • The sender knows that the receiver has actually received the message by Ack (acknowledge) packet • Dropped reply (or Ack) case • Q1: Called two generals problem • Q2: Receiver ignores duplicate message • This time the receiver ignores duplicate message and just resends ack packet • Called exactly-one-processing • Previous message is stored in memory of receiver RPC: Remote Procedure Call • Logical extension of procedure call for networked environment • RPC abstracts procedure calls between processes on networked systems • Remote communication has more failure scenarios than local procedure call • The message can be delivered exactly once rather than at once most

• Banker's algorithm

Use bankers algorithm when multiple instances exist in a resource type Assume that: • A resource can have multiple instances • Common in real systems • OS has N threads, M resources types Initially, each thread must declare the maximum number of resources it will need Calculate a safe sequence if possible Assume simple model • Each thread declares it maximum needs • If the solution of the algorithms exists, this ensures no unsafe state is reached Note that max needs does NOT mean it must use that many resources - simply it might

• What is demand paging?

Usually between memory and disk Demand paging uses memory as a cache of the disk Key idea • Code needs to be in memory to execute, but program rarely used • 90/10 rule • Locality and working set • Working set - small portion of process actually being used Bring a page into memory only when it is needed • Less IO needed, no unnecessary IO • Less memory needed • Faster response with higher degree of multiprogramming Similar to paging system with swapping • When a page is needed; reference to it • Invalid reference → abort & swap-in • Not-in-Memory → swap-in (bring it to memory)

• Memory protection

Valid-input bit attached to each entry in the page table • Valid indicates indicates that the associated page is in the process' logical address space, and is thus a legal page • "invalid" indicates that the page is not in the process' logical address space • Some systems use page-table length register (PTLR)

• Thrashing

Very high activity (page fault) Memory is overcommitted and pages are continuously swapped out while they are still in sues Poor CPU performance

• Chapter 10: Virtual Memory • Virtual memory

Virtual memory - separation of user logical memory from physical memory • Only part of program needs to be in memory for its execution - 90/10 rule • Logical address space can be much larger than physical address space • Allows address spaces to be shared by several processes • Allows for more efficient process creation • More programs running concurrently Virtual memory > Physical memory • Code needs to be in memory to execute, but entier program rarely used • Error code, unusual routines, large data structures • Entire program code not needed at the same time • Consider ability to execute partially loaded program • Program no longer constrained by limit of physical memory • Lots of potential benefits • Each program takes less memory while running • Then more programs run a the same time • Increase the degree of multiprogramming • Increased CPU utilization and throughput • Less IO needed to load of swap programs into memory • Each user program runs faster

• What is Virtualization

Virtualization - to extend or replace an existing interface to mimic the behavior of another system Informal definition • Virtualization is an ability to run multiple (Virtual) OSes on a single physical system and share underlying HW resources • One computer (server) hosts many (virtualized) computers

• Swap space

What happens when a page is removed from memory • If the page contained code, we could simply remove it since it can be reloaded from the disk • If the page contained data, we need to save the data so that it can be reloaded if the process it belongs to refers to it again (Swap) • Swap space: a portion of disk is reserved for storing pages that are evicted from memory At any given time, a page of virtual mem might exist in one or more of • The file system • Physical memory • Swap space (not part of file system

• Chapter 8: Deadlock • What is deadlock?

When 2 or more threads are waiting for an event that can only be generated by these same threads Result of deadlock • Program makes not process and freezes CPU scheduler cannot address deadlock

• Dynamic Relocation

When the process needs to be moved from addr. 400 to 1500 what does the OS need to do? • Just needs to change register values that store the logical address bounds • Pros • OS can easily move a process during its execution • OS can allow a process to grow over time • Simple, fast hardware: 2 special registers, and add, and a compare • Cons • Slow down HW due to the add on every memory reference • Complicated memory management • the number of processes are limited to the size of the memory

• Xen

Why Xen was developed • Full virtualization was a wrong design choice • Poor performance • Trap-and-emulate and Binary Translation • X86 and ARM not fully virtualizable Xen Tradeoff • Para-virtualization • Give up "no source code modification" • Doesn't require changes to ABI • Significantly performance improvement • Improved simplicity • Requires less than 2% source code modification Control plane SW is not part of Xen • Benefit is when changing scheduler or something like that, other parts of Xen are not affected • CPU Protection • Guest OS must run at a lower privilege level than Xen • Weird: there are 2 privilege levels • 1) User mode and 2) kernel mode • Xen: Kernel mode • Guest OS: User mode • Apps: User mode • Problem: Guest OS should use different (separate) address space from apps, guest OS can indirectly control apps via Xen • X86 Protection • Control Transfer • Hypercalls: Synchronous calls from a domain (VM) to Xen • Allows domains to perform privileged operation fia software traps • Similar to system calls • Events: asynchronous notifications from Xen to domains • Replace device interrupts

• Write a file

Write something to "/foo/bar" •

• Client server model

• One of the most common models for distributed systems (or computation) • A server is a process or set of processes that provide a service, including web server, file server, database service • Server can be standalone or a form of cluster • A client is a program that uses the service Design considerations • 1) Fault tolerance • 2) High performance • 3) Security • 4) Reliable communication • Packet loss • Packet loss due to lack of buffering within • network switch, router, or end-point (host) • Common scenario • 1. A network packet arrives at a router • 2. For the packet to be processed, it must be placed in memory within the router • 3. If many such packets arrive at once, memory in the router may not accommodate all of the packets • 4. Router starts dropping packets


संबंधित स्टडी सेट्स

Chapter 12-QUIZ-Inventories and Cost of Goods Sold

View Set

PCAP: Programming Essentials in Python

View Set

Chapter 14: Assessing Skin, Hair, and Nails

View Set

Exam 8 Adult Health Chapter 49, 50, 51

View Set

CH#4: Life Insurance Policy Provisions, Options and Riders Q&A

View Set