Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps

Similar presentations


Presentation on theme: "Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps"— Presentation transcript:

1 Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
File systems

2 HW 7 Comments virtual address -> VPN
If you can’t get a miss rate below 1% then find the lowest possible miss rate (i.e. the miss rate with maximum memory) all of the misses are compulsory misses Add 1% to whatever this miss rate is and find the minimum memory size that yields this miss rate For example, if the smallest possible miss rate is 2.3%, then find the minimum amount of memory that yields a miss rate of 3.3%. Your answers don’t have to be identical to the sample solutions, but they should be close

3 Virtual Address -> VPN

4 Working Set The working set of a process is the set of pages that it is actually using usually much smaller than the amount of memory that is allocated As long as a process's working set fits in memory it won't thrash Formally: the set of pages a job has referenced in the last T seconds How do we pick T? too big => could run more programs too small => thrashing

5 What happens on a memory reference?
An instruction refers to memory location X: Is X's VPN in the TLB? Yes: get data from cache or memory. Done. (Often don't look in TLB if data is in the L1 cache) Trap to OS to load X's VPN into the cache OS: Is X's VP located in physical memory? Yes: replace TLB entry with X's VPN. Return control to CPU, which restarts the instruction. Done. Must load X's VP from disk pick a page to replace, write it back to disk if dirty load X's VP from disk into physical memory Replace the TLB entry with X's VPN. Return control to CPU, which restarts the instruction.

6 Traps A trap is an exception generated by the CPU Traps are caused by
errors (divide by 0, invalid memory access) system call (i.e. a user request for the OS to do something) When a trap occurs, the CPU transfers control to the operating system A vector stores which OS service routine to use for each trap one routine for system calls one routine for handling page faults Trap number chooses the vector entry to use

7 What happens on a Trap? CPU switches protection mode from user to kernel (aka privileged or supervisor mode) Jumps to the specific trap handler like an interrupt service routine The trap handler saves the CPU state (registers etc.) sees what it needs to do does what it needs to do restores user state returns the the user program (switches back to user mode)

8 Files A user-level abstraction for “a collection of bytes in (non-volatile) storage” Files have: A name Possibly a type A location - which device, where on that device Size (and possibly maximum size) Protection - who may read and write this? Time, date, and user identification

9 File operations What operations should a file system support?

10 File Operations File creation Writing a file make room for the file
enter the new file into the directory Writing a file specify the file and the data to write to the file OS keeps track of your location in the file successive writes are placed one after the other in the file

11 More File Operations Reading a file Repositioning within a file
specify the file and the buffer into which the data should be read OS keeps track of your location in the file Location pointer is often shared between read and write operations Repositioning within a file Changes the location pointer Often called “seeking” No actual I/O

12 Yet More File Operations
Deleting a file Find the directory entry and delete it Mark the space used by the file as free Don’t actually “erase” the file Truncating a file Throw away all the data in the file Keep the attribute information

13 Opening and Closing Files
The above six operations are enough But for convenience, we have the notion of the open file The open system call tells the OS that the specified file will be used by several operations user need not specify name each time OS need not search directories each time Location pointers, etc. need only be maintained for open files

14 Directories The directory lists all of the files in the volume
A volume is a logical disk - there may be more than one volume per physical disk (or more than one physical disk per volume) We put the directory at the beginning so we always know where to start Directory Files Volume

15 Single-Level Directories
In a single-level directory structure, the directory lists all files and their offsets Like a table of contents notes Spring todo ideas notes410 Spring00 todo ideas

16 Two-Level Directories
Single-level directories suffer from name collision If you and I both name a file “prog1.c” then one file will overwrite the other Split up the space into top-level directories for each user Keep a directory for each user’s files, and a directory of the user directories

17 Tree-Structured Directories
Let directories contain subdirectories Arrange files in a tree To name a file, specify a list of directories from the top down, plus the name of the file itself This is called a path name A path beginning at the root is an absolute path; if part of the path is implied, it’s a relative path

18 The Current Directory Set the current directory with setcwd() system call All future open() calls interpret path names relative to the current directory Saves on directory lookups Initial current directory is often set at login time, to the user’s home directory

19 Disk Block Allocation The basic unit of storage on a disk is a block
Block sizes vary, but think 512 bytes Each file is stored in one or more blocks For simplicity, blocks are not split between files; leftover space at the end of a block is wasted When creating or enlarging a file, which disk block(s) should be allocated to the file?

20 Contiguous Allocation
In contiguous allocation, a file gets blocks b, b+1, b+2, ... Direntry stores starting location, length Two blocks with sequential numbers are very likely to be in the same track, so no head movement is required What’s the problem?

21 Linked allocation In linked allocation, a file gets a linked list of disk blocks Direntry stores starting location Each block contains data and a pointer to the next block Advantages? Disadvantages?

22 Indexed allocation In indexed allocation, the file gets a list of disk blocks An index block contains the block list Advantages Disadvantages How do we deal with very large files?

23 other file information
Unix Inodes data other file information data data direct blocks data data data 1 indirect data data 2 indirects data 3 indirects data

24 Free Space How do you find free disk blocks?
Bitmap: One long string of bits represents the disk, one bit per block Linked list: each free block points to the next one (slow!) Grouping: list free blocks in the first free block Counting: keep a list of streaks of free blocks and their lengths


Download ppt "Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps"

Similar presentations


Ads by Google