OS Midterm 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

SSD Writes

Data is divided into blocks, these blocks are divided into pages. SSDs provide same interface as HDDs to OS -- read and write chunk (4KB) at a time. Can't update in place -- it's always done differently. Can only overwrite data 256KB at a time (size of a block) even if individual pages are 4KB each. Like having to empty your entire bookshelf and re-put all the books back on any time you want to put a new book on. No updates in place -- entire erasure block must be erased. New blocks will show up in cache, while on the SSD there is valid data and deleted data. The entire block from the SSD must be copied into the cache, then in cache the junk data can be replaced by the new data, then the entire block on the drive is erased. Lastly, the block is copied from cache back into the SSD.

L9Q2

Data on a magnetic disk is accessed in units of sectors. The time to seek from one track to another depends on the number of tracks on the disk. The disk rotation time depends on the rotation speed of the disk. The seek time is not fixed. The average rotation time is not variable. The data transfer time for one sector is variable because it depends on the rotational speed and size of the disk (reading from the outside will be faster because the outside of a disk moves faster than the inside).

Address Translation

Decouples the names of memory locations and their physical locations. Physical addresses are calculated "on the fly" as the instructions are executed. For adequate performance, the translation must be done by HW at run time (Memory-Management Unit / MMU). Thread = abstraction of the processor. Address translation = abstraction of memory. CPU's virtual addresses generated at execution -> MMU -> physical addresses. Allocation throughout history: contiguous memory allocation -> paged memory allocation -> segmented -> paged segmented.

Disk Performance

Disk access time = seek time + rotation time + transfer time. Transfer time is time it takes to move bits into the location on / off the disk. Seek time: time to move disk arm over track (1-20 ms). Rotation time: time to wait for disk to rotate under head.

Paging

Divide virtual memory into fixed-sized blocks called pages (like 4 kb). Divide physical memory into fixed-sized blocks called frames (can hold any page of virtual memory). Pages and frames are of the same size. Set up a page table for each process to translate logical to physical addresses. Finding a free page frame is easy (bitmap): each bit represents one physical page frame: 1 means allocated, 0 means unallocated. Virtual address generated by CPU is divided into: page number p (index into a page table which contains base address of each page in physical memory) and page offset d (offset within the page). Page size (like frame size) is always a power of 2, defined by the HW: for a given logical address ... on slides.

Demand Paging

Do we need to load the entire program code in physical memory at program execution time? No! At execution time, you might not need the whole code. You load that which you need and mark those pages as valid while rest is invalid. Page fault occurs when a page is referenced for the first time because valid bit in page table entry is set to invalid. Kernel brings misisng page in from disk. Adv: less I/O needed, less memory needed, faster response, more processes can be admitted.

Efficient Address Translation

Done on every memory reference. How can we make it efficient? If TLB miss, then go to page table. Cache recent translations. TLB pictorially on slides. WATCH THIS LECTURE AGAIN bc i am so tired.

FFS Asymmetric Tree

Each file is represented as a tree. High degree (internal nodes with many children), indirect block can contain points up to 1024 blocks. Fixed structure. 48KB for files that only use direct pointers, then + 4MB for using the 13th slot's indirect pointer, then + 4 GB, then + 4 TB for triple indirect block. Small files: shallow tree, efficient storage for small files. Big files: deep tree, efficient lookup for random access in large files.

Deadlock Examples

Example 1, no deadlock. Example 2, deadlock (two cycles). Example 3, no because T4 may release its instance of resource type R2 which could then be allocated to T3. Even if there's a cycle, may not be deadlock. If there's a cycle and only one resource, then there's deadlock.

SSD Issues

Expensive writes. Durability issues: wear out and read disturb error. Solutions: layer of indirection (maintain a flash translation layer (FTL) in SSD, FTL is code embedded in the SSD that converts block I/O to internal operations; ensures performance and endurance, map virtual block numbers (which OS uses) to physical page numbers (which flash memory controller uses), can now freely relocate data without the OS knowing), or Copy on Write (do not overwrite a page on updates, instead, write new version in a free page, one more thing on slides).

Memory Fragmentation

External Fragmentation: total memory space exists to satisfy a request, but it is not contiguous. Internal Fragmentation: allocated memory may be slightly larger than requested memory -- memory internal to a partition, but not being used. Keeping information about where a hole is can sometimes take up more space than the hole in the first place (internal fragmentation). Worst-case external: a bunch of distinct tiny holes. Worst-case internal: lots of unused space.

Microsoft File Allocation Table (FAT)

FAT-32 implemented in 1970s was the main file system for MS-DOS and early versions of MS WIndows. Simple, easy to implement. Still widely used (thumb drives, camera storage devices). Stored on disk, on boot cache memory, second (backup) copy on disk. When machine turns on, control goes to boot ... which contains info on how system is organized. Boot record occupies particular area which has executable code and OS to launch / boot. File allocation table resides at the start of the ... There's a duplicate of the file allocation table. Also has a root directory which contains an entry for each file stored directly in the file system (file names, number, size, data, etc.).

UNIX FFS (Fast File System)

FFS is default file system in FreeBSD. inode -- index node, the root of asymmetric tree whose leaves are the data blocks of a file. 1 inode = 1 file. Inode contains file metadata and location of the file data blocks. inode table (array) stored at some well-known location on the disk (analogous to FAT table). FFS Superblock (identifies file system's key parameters). MORE ON SLIDES.

FFS: inode

FFS uses fixed, asymmetric tree called a multi-level index. File number - inumber in FFS, is an index into the inode array. inode has extensive metadata (fiel type, size, # links to inode, user, group, protection bits, etc.), 1-12 direct pointers which point to leaves (actual data of the file) -- if our file is larger, then we use the 13th pointer as an indirect pointer which points to an internal node called an indirect block (1K pointers, or 4KB) that has an array of direct pointers. If we need to grow file even further, then we use the 14th pointer which is a double indirect block with 1K indirect pointers which each points to an indirect block, which then has pointers. What if the file is even bigger?? The last resort is the 15th pointer, which is the triple indirect block that has 1k double indirect pointers, etc.

FFS Block Groups

FFS volume is divided into a set of block (cylinder) groups: a set of nearby cylinders. You can access with tiny movement. Cylinder groups are typically about 1MB in size. DIAGRAM on slides.

Round Robin

FIFO with preemption based on time limits. Ready processes given a quantum of time when scheduled: a time quantum is generally 10 to 100ms. Process runs until quantum expires or until it blocks. Suitable for interactive (timesharing) systems. Each task gets resource for a fixed period of time: it's max amount of uninterrupted time given to a task (time quantum or time-slice), if the task doesn't complete it goes back in the end of the queue, more ON THE SLIDES. A longer task split into tiny short time quantums will need more context switches. A short task will take up the full time of the time quantum even if it finishes early. Adv: it's fair, ... ON SLIDES

FIFO

First in, first out. First come first served. Maintain a simple queue. Schedule tasks in the order that they arrive and continue running them until they complete or give up the processor. Less starvation, efficient because minimizes context switches. Adv: good policy for workload where tasks are roughly equal in size, minimizes overhead of context switches, simple, fair. Disadv: waiting time depends on arrival order, short processes are stuck waiting for long processes to complete.

Deadlock

Four necessary conditions: limited / bounded resources, circular waiting, no resource preemption, hold and wait. It's possible to test for this.

File

From user's perspective, smallest allocation of secondary storage. A named collection of information managed on secondary storage by the FS, smallest allocation of logical secondary storage, depending on FS a file can be viewed as an unstructured stream of bytes or a series of records, contain data and have metadata (attributes).

Solid State Disks (SSDs)

Full of flash memory chips. No moving parts (no rotate / seek motors), eliminates seek and rotational delay (.1-.2 ms access time), very low power and lightweight, limited "write" cycles. Rapid advances in capacity and cost ever since. In 2009, use NAND multi-level cell (2 or 3-bit / cell) flash memory, sector (4 KB page) addressable but stores 4-64 "pages" per memory block, trapped electrons distinguish between 1 and 0.

Address Translation Goals

Functional goals: isolation and transparency to programmer -- illusion of more or less memory than physically present, memory protection / isolation, memory sharing -- controlled sharing of code or data, support for sparse address spaces and dynamic resizing -- dynamic allocation (heap / stack growth). Performance goals: efficient I/O, flexible physical placement, low memory overhead of translation (compact tables, hashed inverted tables), fast address translation (TLB).

How can two processes share segments?

Have exactly the same base value for the segment that you want to share in the segment tables of different processes.

Why is page size always a power of 2?

Have some number of bits to represent page number (m-n) and some to represent offset (n). More on discord probably.

FS Components

How do we go from a file name and offset to a block number? Each file has a name and metadata. The storage devices (SSDs or HDD) provide a much lower abstraction with large arrays of data blocks. How do we translate? File names and offsets are mapped in two steps. Directories map file names to file numbers. Then the file number is used in an index structure (persistently stored tree) to find the block that holds the data at any specified offset. File name -> directory structure -> file number -> file index structure -> data blocks (list or tree structure) -> the block. Trees are much better than lists for search time and we can group files in their directories this way. With flat organization you could run out of names (finite number of names) -- with hierarchical structure, you can't really run out of names bc files can have same name in different directories and use the directory path to resolve the name.

Contiguous Allocation Approaches

How to satisfy a request for a memory chunk of size N from a list of holes (blocks of available memory)? First-fit: start from the head of the list, allocate the first hole that's big enough. Variation: next / circular fit: start at the chunk after the one just allocated, and pick the first one that's large enough (treat the list as if it's circular), does not include the block in which something was just allocated. Best-fit: allocate the smallest hole that fits. Worst-fit: allocate the largest hole (tries to avoid having a bunch of tiny holes).

Scheduling Policies

Ideal CPU scheduler: maximize CPU utilization, maximize throughput, minimize turnaround time, minimize waiting time, and maximize fairness. Reality - no universal scheduling policy: many models, determine what to optimize using metrics, in most cases optimize the average measure. Real CPU schedulers implement a particular policy: FIFO (FCFS), SJF (Shortest Job First), Round Robin: use a time slice and preemption to alternate jobs, Priority-based: most important first, Multilevel Feedback Queues: round robin on priority queues.

When should we run the scheduler?

If new task enters ready state while another is running, that's a good time. If a process blocks, then it's idling so we pick a ready task to run. If there's a timeslice or the thread yields (running -> ready) then that's a good time too. When a task is unblocked and becomes ready, that might be a good time. When a task finishes. Best three times: running -> finished, running -> ready, ready -> waiting.

Deadlock Approaches

Ignore it, prevention (make one of four conditions impossible), avoidance (Banker's Algorithm, control allocation), and detection and recovery (look for a cycle, preempt or abort).

FFS Free Block Allocation

In FFS it's a bitmap. Free space management: bitmap one bit per storage block to indicate free or not. First free allocation: small files fragmented, large files contiguous: FFS puts each new file block in the first free block in that file's block group, small files fill holes near start of block group, large files fill holes near start of block group and then write most data to sequential range blocks. Important: keep 10% or more free!! (reserve space in the... ON SLIDES).

FS Design Challenges

Index structure: how do we locate the blocks of a file? Need to map file number and offset to a storage block. Also have to keep track of which blocks are free (free space map). The blocks which belong to a file should be near each other. Index granularity: what block size do we use? Free space: how do we find unused blocks on disk? Locality: how do we preserve spatial locality? Reliability: what if machine crashes?

Directory

Information about files is kept in the directory structure, creates the namespace for files, organizes and provides... ON SLIDES.

Contiguous Allocation Example

Input queue holds process1, process2, process3. Holes get created in the memory. OS keeps list of holes and list of allocated partitions. Initially whole memory space (apart from OS) is open (1 big hole). What if there's not enough memory? Example on slides. Problem: fragmentation.

Contiguous Allocation Tradeoffs

It's simple, it's fast, only needs a few registers + adder + comparator, can relocate in physical memory without changing processes. Disadv: fragmentation, can't keep program from accidentally overwriting its code, can't share code / data with other processes, can't grow stack / heap as needed.

Hard Disk Drive Structure

Magnetic disk is still the most common secondary storage. Data bits are stored in fixed size sectors, 5-8 bits it sounds like. Smallest amount of bits that can be read or written in a single operation. Has to at least read or write entire sector, can't read or write a single bit. When you power up a drive, the platters are constantly spinning on a spindle and an arm with read-and-write heads read info. A track is one of many concentric rings on the disk surface, and a read-write head is mechanically positioned over a track in the cylinder and reads as it rotates. Each track (numbered 0-n) has its sectors. To access a specific sector, the read-write head must wait on average half of the time it takes the disk to rotate. To access a sector on a different track, the head has to move to the other track and wait 1/2 track rotation time. Less expensive, good for when you have to write something over over and over again.

FTL: Functions

Map logical block address on flash pages to physical page on the drive. Kind of like virtual memory. The FTL writes the new version to some free already-erased physical page and remaps the logical page (?). Garbage collect erasure block by copying live pages to new location, then erase -- diagram on slides. Wear-levelling: only write each physical page a limited number of times, remap pages that no longer work. Wear-leveling is used almost universally in flash products today and prevents the overuse of any particular block. Without wear-leveling, blocks will cluster in one area (example on slides).

Directory Structure

Maps filenames to file numbers. File number: unique ID that's used to lookup physical disk location of a file. Directory info can be stored in a file: directories are special files that contain mappings of filenames to file numbers. Each process maintains the "current working directory" -- root directory has a predefined (well-known) file number. Recursive filename lookup. Predefined file number for the root directory. Cache translations so next time we access something in that directory, we have the number for that directory.

xv6 Address Translation

Memory is managed in pages (and frames) where each such page is 4096 (2^12) bytes. Process virtual address space is 2^32 = 4G bytes while the physical memory is limited to 16 MB only. Project 4.

Memory Management

Memory needs to be allocated efficiently to ensure a reasonable supply of ready processes to consume available CPU time. Goals: provide a convenient abstraction for programming (virtual memory: separation of logical from physical memory), allocate scarce memory resources among competing processes, arbitrate: address translation and validation, enable sharing: allow multiple processes to share selected regions of memory.

Resource Allocation Graph

Modeled using directed graphs, which shows the current allocation of resources to threads and the current requests by threads for new resources. Will discuss in the context of threads, but also applies to processes. Two types of nodes: thread (circle) and resource (square). If there are multiple identical units of a reusable resource, that's shown with dots inside the box. Edges can be a resource requested or a resource allocated, depending on where the arrow points. We make this on the assumption that the code works. In slide example, p1 has no outstanding requests so it's running. p2 is blocked because it needs two resources but r2 only has one available. p3 isn't blocked.

Paged Segmentation

Most architectures support segmentation and paging. Basic idea: segments exist in virtual address space, segment table entry has pointer to page table, page table length, and access permissions, page table entry has page frame and access permissions, virtual address (VA) is <segment number, virtual page number (VPN), offset>, and share / protection at either page or segment-level. Entire segment does not have to be in memory at one time. Segments broken up into pages (smallest size it can be is the size of one page) -- not one contiguous block anymore (solves fragmentation). Because paging is used at the lowest level, all segment lengths are some multiple of the page size. The pages belonging to a segment can be dispersed through memory. Every process needs a segment table. Entry in page table is not the physical address because segments consist of multiple pages -- instead, find physical address of the page table for the segment.

Multi-level Paging

Multi-level page tables are tree-like structures to hold page tables. Each level of page table fits in a physical page frame. Only the top-level page table must be filled in, the lower level tables are allocated only if pages are accessed by a process. Example: Sun Microsystems SPARC processor. How much memory is needed to store a process page table? Ex: 32-bit architecture, 4KB pages, 4 byte PTE -- single level page table size will be number of entries x size of each entry = (2^32/2^12)x2^2 = 2^20x2^2 = 4MB. Two-level page table size: if we have only one valid page in our process then 2^10 (number of entries of top-level page table) x 2^2 (size) + 2^10 x 2^2 (process needs to access some page) = 2^13 bytes = 8 KB. LEARN HOW TO DO THIS

Valid-Invalid Bit

Need HW support to distinguish between the pages that are in memory and the pages that are on the disk. Associate a valid-invalid bit with each page table entry (v in-memory, i not-in-memory). During address translation, if valid-invalid bit in page table entry is i, causes page fault.

MLFQ Example

New task enters Q0 and needs 36 ms to finish. I/O and CPU-intensive tasks will likely stay in Q0 because they keep blocking.

Paging Internal Fragmentation

No external fragmentation, but internal present. If not multiple of page size, some portion of last page k that will be unused. LOOK AT Q4 ANSWER DISCORD.

L9 Q7

No. The FTL will laugh at your attempt to localize. SSD will run into a problem because it hates locality because it doesn't like to write to the same place -- needs writes to be as spread out as possible.

Priority-based Scheduling

Not all tasks are equal: lower priority for compute intensive processes, higher priority for interactive processes (can't keep the user waiting). Usually preemptive, each task is assigned a priority, scheduling policy is to pick the process in the ready queue having the highest priority, equal-priority processes are scheduled in FIFO order. Adv: mechanism to provide relative importance to task. Disadv: could lead to starvation of low priority tasks (solution is aging -- as time progresses, incrementally or at once increase the priority of waiting tasks), recalculate priority (many algorithms): increase priority of I/O intensive jobs, favor processes in memory, ONE MORE ON SLIDES, etc.

TERMINOLOGY

ON SLIDES

Comparison of Memory Management Techniques

ON SLIDES -- IMPORTANT.

File System (FS)

OS abstraction. Physical storage device vs OS abstraction: physical block / sector numbers vs filenames + directory hierarchy, read / write sectors vs read / write bytes, no protection / access rights for sectors vs file protection / access rights, possibly inconsistent structure or corrupted data vs reliable and robust recovery. User -> file (bytes) -> file system -> hardware.

Consistency

Old state and new, updated state meet certain necessary invariants (no orphaned blocks). For Q3 in lecture, A and B will never lose or gain too much or too little money.

File System Pictorially

On slides. Each file is a named collection of information and is stored on disk. File system provides uniform access to files and lets user manipulate them. Some OSs show files as a byte-stream oriented flow and when you do read or write commands, those commands will always access the next n bytes and a seek command moves the current position to a new one. Some OSs support files as fixed and sequential record oriented, where read / write will affect the next record. Other OSs support direct record oriented, when read / write record k.

L9 Q6

On the very outer edge because it moves fastest.

Deadlock Recovery

Once a deadlock is detected, we have two options: kill / abort threads (abort all deadlocked threads: threads need to start all over again and may have problem with shared resources, abort one thread at a time until cycle is eliminated: system needs to rerun detection after each abort) or revoke resources and force their release (need to select thread and resource to preempt, need to rollback thread to previous state, need to prevent starvation) -- need to do this safely so state of the shared objects is left consistent.

Fine-Grained Synchronization

One lock for each data item. More locks, so fewer objects per lock. Ex: one lock per data element (array index), one lock per bank account. This is more error prone -- how do we split up the data structure?

Coarse-Grain Synchronization

One master lock for the whole data structure. Fewer locks, so more objects per lock. Ex: one lock for an entire data structure (like an array), one lock for all bank accounts. Good to use when there's little concurrency.

FFS Locality

Optimize for the common case: file's data blocks, data and metadata, and different files from the same directory are accessed together, files in the same directory are located in the same group: subdirectories located in different block groups. Data blocks, metadata, and free space interleaved within block group: avoid huge seeks between user data and system structure. Users will often access files in the same directory around the same time. Everything can't be near everything else. Disk is divided into multiple block groups -- DIAGRAM on slides -- corresponding parts labelled on diagram.

Isolation

Other transactions do not see results of earlier transactions until they are committed. Serializability (transaction 1 appears to execute entirely before transaction 2 or vice versa).

Address Types

Physical / Absolute Addresses: an integer. Logical / Virtual addresses: reference to a memory location independent of physical memory. Relative Address: a virtual address expressed relative to some location. It's possible to use more memory than what can actually be physically stored -- some part of virtual memory will be stored physically, and some will be in secondary memory. When you compile a program, virtual addresses are generated because we can't assume anything about memory at compile time. RAM hardware structure. Main memory acts as a cache for the virtual memory on disk. A word is usually 4 bytes but can also be 1 byte.

FFS: Zooming in on the inode

Picture on slides.

FAT Example

Read file 2, block 2. The file number 2 is used as an index into FAT table, so we have pointer to the first block of the file. We then know we need block 2, so we use that as an offset and copy it from disk to memory. DIAGRAM ON SLIDES -- table doesn't have a file with the number 3 because that entry is part of file 2's entry. The file numbers are not allocated sequentially.

Task

Refers to both a process and thread.

SSD vs. Ransomware

Researchers add "Time-Travel" feature to SSDs to fight ransomware attacks. The tool can be used to revert to a previous version of the file and would also help the case of a user accidentally deleting one of their own files. Tradeoffs: retention vs. duration and storage performance (will have to keep old data for quite a long time).

Wait-For Graph

Resource allocation graph containing only threads where each thread can have multiple incoming resource allocation edges but only one outgoing resource request edge. Used to look for cycles for deadlock. To create: one node per thread, and edge from thread A to B implies that A is waiting for B to release a resource that A wants -- only exists iff the corresponding resource allocation graph contains two edges: A -> R and R -> B for some resource R. Do this in a single instant of time, not as things change. Cycles may indicate deadlock -- need to pay attention to the number of resource instances. May need to know how to draw these from the resource allocation graph. Example on slides: p1 and p5 are waiting on p4 to release a resource. p2, p3, and p6 are waiting on p5 to release resource, example has a cycle from p4-p5-p2.

xv6 Vanilla Scheduler

Round Robin. Process' kernel thread calls swtch() to save its context and return to the scheduler (%esp and %eip are saved and restored, swtch() just switches between two threads... ) ON SLIDES

SJF Scheduling

Runs whatever job puts the least demand on the CPU. For each task, identify duration of its next CPU burst. Two schemes: non-preemptive: once CPU given to the task, it is not preempted until the task completes its CPU burst. Preemptive: if a new task arrives with CPU burst length less than remaining time of the executing task, preempt -- this scheme is known as Shortest Remaining Time First (SRTF) or Shortest Remaining Time to Completion First (SRTCF). Adv: provably optimal for minimizing waiting times. Disadv: hard to accurately estimate execution times (use heuristics based on history), worst case variance in response time (by doing the shortest tasks as quickly as possible, does longer tasks as slowly as possible), fundamental tradeoff for... ON SLIDES.

MLFQ Rules

Scheduler picks the first task in teh highest priority queue. Higher priority tasks always run, preempting lower priority tasks. RR within the same priority queue. All tasks start at the highest priority queue: when a task enters the system, it is put into the topmost queue. If task uses up its time quantum, the task drops one level: task priority is reduced, task is moved down one priority queue. Every time task yields the processor before quantum expires, it stays at the same level. Aging (priority boost): after some time... ON SLIDES.

L9 Q1

Segment and page size is not variable. A segment may be placed with any starting address, but there's no such thing as a segment frame. A page may be placed into any page frame. With segmentation, all components of a program kind of reside in a contiguous logical address space but every component resides in a different segment (separate logical entities) so not really. With paging, all components of a program reside in a contiguous logical address space. With segmentation, all components of a program do not necessarily reside in a contiguous area of physical memory, they're allocated in different spots. With paging, all components of a program do not reside in a contiguous area of physical memory. Segmentation leads to external fragmentation while paging does not.

Multi-Level Feedback Queue (MLFQ)

Set of Round Robin queues. Actually used in OSs. She talks about this more, maybe rewatch. Q1 -> Q2 if you need more time -> Q3 if you need even more. Q1 is highest priority, Q3 is lowest. Q1 has shortest time quantum, Q3 has longest. High priority queues have short time slices. Scheduler looks at queue i-1 only if queue i is empty. Assume a newly arriving task is short, run it with the highest priority, demote it the longer it runs. Adv: can deliver excellent overall performance (similar to SJF) for interactive tasks, no need for a priori knowledge: MFQ observes the execution of a task and prioritizes it accordingly. Disadv: priorities get controlled by a ... ON SLIDES.

Other Optimizations

Share memory between processes. Set entries in both page tables to point to same page frames. Keep track of whether the shared page is still in use. Zero-on-demand / zero-on-reference: for security, kernel zeroes a few KB of heap or stack memory to avoid accidental information leakage, sets page table entries for "dirty" pages to invalid, causing a trap into the kernel, when more memory is needed, kernel zeroes more memory and extends the stack / heap only as needed. Copy-on-write: copy page table entries only and set them to read-only, make a real copy of the underlying page on a store (write) request -- ex: UNIX fork() with copy on write (duplicates parent stack, just copies page table and do not copy pages in process memory, mark all pages (in new and old page tables) as read-only.

Contiguous (Base and Bound) Address Translation

Simple memory allocation model that assigns a process consecutive memory blocks (that is, memory blocks having consecutive addresses). Partition: contiguous block of memory sized to a given process' needs. Hole: block of available memory (when a process arrives, it is allocated from a hole large enough to accommodate its needs, process exiting frees its partition, adjacent free partitions combined, OS maintains list of processes (input queue), allocation partitions and holes. How is address space of each process protected? A pair of base and bound registers define the logical address space for each process, CPU must check every memory access generated in user mode to be sure it is between base and bound.

Swapping and Memory Compaction

Swapping is the temporary removal of a partition from memory. You can move one block out to create a bigger hole. Compaction is the systematic shifting of partitions in memory, generally in one direction, to consolidate multiple disjoint holes into one larger hole. With compaction, you still might not be able to make a big enough hole. With swapping, you could technically swap out everything to have one big hole.

Round Robin Example

The ready queue is treated as a circular FIFO queue. T1 runs for 2 time units and finishes, T2 runs for 2 out of its 4 time units and then is put back at the end of the queue. T3 runs for 2 units but only needs 1, then T2 runs, then T4 finishes.

Single-Level Page tables

The size of a page table is proportional to the size of the virtual address space. With 64-bit address spaces and 4KB pages, 2^64 / 2^12 = 2^52 page table entries. Page table takes up 2^54 per process. Sparse address space (heap / stack) introduces unjustified overhead. Most of the page entries will be invalid (not in use). Can we reduce the space taken up by the page table? Yes, with multi-level (hierarchical) paging.

ACID Properties

Transactions help achieve the ACID properties: atomicity, consistency, isolation, and durability.

Atomicity

Update appears as indivisible (all or nothing), no partial updates are visible (at logical level). At the physical level, only a single disk / flash write is atomic.

File Systems Background

Variable-size Buffer (I/O API and syscalls, memory address), Block (file system, logical index) -> Hardware Devices (HDD with sectors and physical index, or SSD with FTL communicating with physical block and physical index). A file system usually works with blocks, not sectors or pages. Separates the drive into different pieces. Provides way to store data about those pages.

Paging Address Translation

Virtual page number to physical page frame translation performed by MMU. Page table is an in-memory data structure that the MMu uses to look up translations from virtual page number to physical frame number. Each process has its own page table: entries contains pointers to page frames, stored in physical memory. Rewatch lecture maybe for this slide.

Segment Address Translation

We have the segment number and offset. The CPU spits out virtual addresses which need to be translated. We look at the segment, and for each process we maintain a segment table (a special register will point to the beginning of a page table for the process). Use segment number as an index into the segment table. When we find the corresponding entry in the table, it will give us the physical address for the start of the segment (base) -- then we also can see the bound. We add the offset. Pictorially on slides. Seg. fault if you try to access outside of bounds. Offset + physical address.

Handling Page Fault

What happens if a process tries to access a page that was not brought into memory (marked as invalid)? That will cause a page fault which causes a trap to the OS. DIAGRAM ON SLIDES. Reference -> trap -> page is on backing store -> bring in missing page -> reset page table -> restart instruction.

Ownership Pattern

You lock an entire data structure (coarse-grain lock). Used in large, multithreaded programs. Contains producer-consumer queues for sending messages between stages. Threads in stage 1 will be producers for the consumers in stage 2.

Non-preemptive Scheduling

A running task will be able to continue until it terminates (is gone from the system) or it blocks (I/O, unsuccessful lock acquisition, etc.). At this point we choose another task to run.

Transaction Concept

A transaction is a set of atomic updates to the state of one or more objects. Used to take resources safely away from running processes. Can finish in one of two states. Committed: if a transaction commits (succeeds) then the new state of the objects will be observed (all updates occur). Rollback (or abort): if a transaction rolls back / fails, then the object will remain in its original state (as if no updates to any part of the state were made), so no updates occur -- computation can be safely rewound. Graph of this on the slides. Good to keep logs of information to restore initial state. Thread restarting (each transaction has a begin_ and end_transaction statement). Generally, we abort the "youngest" transaction.

Banker's Algorithm

A way to determine safety of a program. If we have prior knowledge of how resources will be requested, we can predict when we'll enter the unsafe state. Relevant for resources that can be released and reused later. Need to know how many resources we have. First figure out how many resources are initially available. Then determine if you can safely provide each task with its resources.

Conditional Variables

Abstraction that supports conditional synchronization. Always associated with a lock. Enables threads to wait inside a critical section by releasing the lock. Synchronization primitive that models events. Represents some condition that a thread can wait on until the condition occurs OR notify other waiting threads that the condition has occurred. Without these, variable threads continually have to poll to check if the condition is met. Provides signaling (notification mechanism), not mutual exclusion: a mutex is needed to synchronize access to the shared data, each CV is associated with a mutex.

FFS Tradeoffs

Adv: Efficient storage for small files, efficient lookup for random access in large files, locality for large files, locality for metadata and data. Disadv: inefficient for tiny files (a 1 byte file requires both an inode and a data block), inefficient encoding when file is mostly contiguous on disk, need to reserve some free space to prevent fragmentation.

Multilevel Translation Tradeoffs

Adv: allocate / fill only page table entries that are in use, access permissions can be specified at each level. Disadv: one pointer per virtual MORE ON SLIDES

Segmentation Tradeoffs

Adv: don't need to find one big hole -- it can be broken into segments (the segments are contiguous but can be of different sizes), can share code / data segments between processes, can protect code segment from being overwritten, can transparently grow stack / heap as needed. Disadv: complex memory management (need to find chunk of particular size), external fragmentation (wasted space between chunks). Can't free the segment if at least one process needs it (use a core map to track who needs it).

FAT Tradeoffs

Adv: simple, easy to find free block, easy to append to a file. Disadv: random access to a file is horrible because you have to go through list, poor locality, non-existent file control, random access very slow, fragmentation (file blocks for a file may be scattered, files in same directory may be scattered, MSDOS defrag tool), limited metadata, no support for reliability or hard links, max file size is 4 GB.

Segmentation

Allow a process space to be broken into multiple base + bounds "segments". Segments can be used to hold the program code, data, and stack or to hold system data structures. Segment is a variable-size contiguous region of virtual memory. Each process has a segment table that contains: base (the starting physical address where the segment resides in main memory), bound / limit (the length of the segment), access permissions. Updating the segment table is a privileged (kernel-only) operation. Logical address consists of a tuple (segment number and offset -- points to allocation of word inside this particular segment). Pictorial example on slides. Each segment table points to the start of where segment begins in physical memory.

CPU burst

Amount of work (CPU time) to do until its next I/O request or termination.

FAT Organization

An array of 32-bit entries (one entry per available block on disk). File's number is the index of the file's first entry in the FAT. Also used for free space tracking: if data block i is free, then FAT[i] contains 0. Grow file by allocating free blocks and linking them in. Locality: next fit is used to get next spot (next free block starting from the last block of the file) -- can result in fragmented files (spread out across disk) and have to run defragmentation executable. Use file number as index into FAT table, pointing to the first FAT entry, which indicates the first block of a file. FAT table also keeps track of free blocks.

FIFO Example

Assume non-preemptive scheduling and single CPU. Three tasks arrive in this order at about the same time. T1 goes right away, T2 takes a long time next, then finally T3. Average waiting time is the average of the times each had to wait (0+1+10)/3 = 11/3 sec. Average completion time is the time it takes to finish averaged (1+10+12)/3 = 23/3 sec. GANTT CHARTS / METRICS WILL BE ON EXAM.

Non-preemptive SJF Example

Assume non-preemptive scheduling, 1 CPU, known execution times. Three tasks arrive at the same time. T1 runs first because it has the shortest burst time, T3 is next, then T2. Average waiting time (0+3+1)/3 sec, average completion time is (1+12+3)/3 sec.

Preemptive SJF Example

Assume: preemptive scheduling, 1 CPU, known execution. Three tasks have different arrival times and burst times. T2 will start for 2 units because it arrived 2 units before the others, then T1 will start, T3 will run, then T2 will resume. Average waiting time will be: ON SLIDES sec, average completion time will be ON SLIDES sec.

Scheduling Metrics

CPU Utilization: the percentage of time that the CPU is busy. Throughput: the number of tasks completed per unit of time. Completion / turnaround time: time it tasks to run a task from initialization to termination, including all of the waiting time. Waiting time: the total amount of time a task spends in the ready queue. Response time: the time from the submission of a request until the first response is produced. Fairness: how equal is the performance received by different users?

Preemptive Scheduling

CPU scheduling that occurs when the operating system decides to favor another process, preempting the currently executing process with a context switch.

Durability

Committed updates are persistent (permanent, even if system crashes).

CPU Scheduler

Component of the kernel. Design principle: separation of policy and mechanism. Decides whether the currently running task should continue running and which of the ready tasks should run next. Long term scheduler (admits processes to ready queue) and short term scheduler, which is responsible for selecting one of the processes from the ready queue and scheduling them for execution (what we focus on). Preemptive and non-preemptive. Many OS scheduling concepts are applicable in other applications: web servers, network routing, etc.

Job

Current CPU burst of a task until it blocks again. Task alternates between CPU and blocking operations (I/O, sleep, etc.), when a task is blocked on ...


Conjuntos de estudio relacionados

Health/disease Mind-Body Connection

View Set

BIOL 107 Study Set First 8-weeks

View Set

Multiplication Tables 10-20 (for practicing mental math)

View Set

Chapter 1 - ECON 2105 - 10 Principles of Economics

View Set

Translating Algebraic Expressions and Verbal Expressions

View Set

CIS Chapter 5: System software: Operating Systems and Utility Programs

View Set

RNRS 117- Bowel Elimination Sherpath (Exam II)

View Set