CS153 Final
Which of the following are true about UNIX access control system?
Subjects can belong to multiple groups Root user can write to any file
Swap resides on disk
True
free() does not need a system call
True
An important problem about persistent storage (e.g. file systems) is reliability in case of system crash, i.e, crash consistency. Which of the following about crash consistency are true?
FS can be in an inconsistent state because FS operations are not atomic Journaling File Systems (JFS) can provide certain degree of crash consistency
Journaling FS improve the performance of FFS
False
Multi-level page tables improve the performance of address translation
False
Page faults are handled by hardware
False
Segmentation can lead to internal fragmentation
False
Swap can be smaller than physical memory
False
The working set of a process includes all its data pages
False
Which of the following are benefits offered by virtual memory (not virtual address space)?
Illusion of having more memory than physical memory.
Which of the following cases are improvements of Fast File System(FFS) over traditional UNIX File System?
It allocates files to a cylinder group to improve read and write performance It duplicates mater block to improve reliability in case of disk failure
Which of the following are correct about Log-structured File System(LFS)?
It reduces the disk seek time during write operations.
In the UNIX file system, what information does a directory contain for a file in that directory?
Logical address on the disk of the file's i-node
When multiple virtual pages are mapped to the same physical page, these virtual pages are called aliases, which of the following techniques create aliases?
Memory sharing Copy-on-Write
What are the benefits of using variable sized partitioning to allocate virtual address spaces as compared to using paging?
No internal fragmentation Context switches are faster Latency for translating a virtual address to a physical address is lower
Which of the following are the benefits of hierarchical multi-level directories in a file system?
Offer a convenient way for users to organize files
Which of the following are true about RAID system?
RAID system can provide better performance than single drive system
Is the "open" system call in UNIX absolutely essential? What are the consequences of not having it?
The open syscall is not absolutely essential, instead of accepting file descriptor, we can also make file related syscalls accepting file path, like (read"/one/two/three", buffer, size) The consequence is that the OS kernal has to do path translation for every file operations, which will be much slower. Another concern is that because of remaining and linking, the file you expect to operate on may change. With open, once the file is open, the file descriptor will always refer to the same file.
Explicit free list is better than implicit free list for heap management
True
Page replacement can require invalidating a TLB entry
True
Page tables can be bigger than physical memory
True
Consider a byte-addressable system with 1 Gbyte physical memory that uses a 2-level page table. The directory (i.e., outer page table) has a size of 16Kbytes. The PTE size is 8 bytes. Its ok to leave expressions if they are too difficult to simplify. a. What is the size of the inner page table in pages? (Hint: you can infer this from the directory size) b. If the page size is p bytes, what is the number of PTEs in the inner page table as a function of p (Hint: use the result you derived in part a) c. Given also that the virtual addresses are 36 bits wide, write another expression for the number of PTEs in the inner page table as a function of the page size, p. d. Given that the expressions in b and c are both for the number of PTEs in the inner page table, solve for p to determine the page size in the system e. How many bits are there in the Physical Page number?
a. 16Kbytes/8PTEs = 2K PTEs b. number of PTEs = size/(size of PTE) = (2K*p)/8 = 2048Kp/8 = 256p c. (2^36)/p d. (2^36)/p = 256p 2^28 = p^2 2^14 e. Since the page size is 2^14, there are 14 offset bits, leaving 16 bits for PPN
Ext4 is the default file system of most Linux distros. It's i-nodes are similar to the one we discussed in class. It has 12 direct links, 1 indirect link, 1 double indirect link, and 1 triple indirect link. The default block size is 4 Kbyte. Assume a pointer is 4 bytes in size. a. What is the max disk size the default config of ext4 can support? b. What is the max file sizez that doesn't use the triple indirect link in i-node? c. Suppose you write one more block worth of data at the end of the file in part b, how many additional blocks will be needed and the new structure of the file. d. Disregard journaling. How many blocks on the disk will have to be updated to carry out the operation in part c? Note that some other blocks not related directly to the file may have to be updated. e. Your computer crashes in the middle of the operations above; explain what could cause the disk to be inconsistent? Show a specific scenario with the operations in part d and explain what the observed effect of the inconsistency is. f. To avoid the inconsistencies you explained in part e, ext4 uses journaling. Explain how journaling can help solve this problem.
a. 4 bytes pointer = 2^32 indexable blocks * 4KB/per block = 2^44 bytes = 16TB b. 12 + 2^10 + 2^20 indices * 4KB ~= 2^32 Bytes = 4GB c. We used up all the direct, single indirect, and double indirect links, in order to add one more data block, we need to use the triple indirect link, which means we need additional 4 blocks. d. 6 blocks; i-node, three indirect blocks, the data block, and the free map e. The block may be allocated but it's not linked to i-node yet, then these blocks will be missing. f. Journaling will first log the operations to be performed: allocation, linking, writing data to the data block. If the system is crashed in the middle, the kernel can follow the plan, check what has been finished and resume the ones that have not been completed successfully.
In the following problem, consider a unix file system with i-nodes similar to the one we discussed in class. It has 8 direct links, 1 indirect link, 1 double indirect link and 1 triple indirect link. The block size is 1 Kbyte. Assume a pointer is 4 bytes in size. a. What is the maximum file size that does not use the triple indirect link in i-node? b. Suppose that you write one more block worth of data at the end of the final in part a, how many additional blocks will be needed and the new structure of the file c. How many blocks total on the disk will have to be updated to carry out the operation in part b. Note that some other blocks not related directory to the file may have to be updated. d. Your computer crashes in the middle of operation above; explain what could cause the disk to be inconsistent? Show a specific scenario with the operations in part c and explain what is the observed effect of the inconsistency.
a. 8 directly indexed blocks + 256 single indirect indexed blocks + 256*256 doubly indirect indexed blocks b. Need to add the data block + top level of triple indirect, one block of the next level of triple indirect, and one block of the bottom level. 4 blocks total. So, in addition to the 8 direct blocks, single indirect block, and the double indirect block all filled out from part a, we will have the triple indirect->ttop level of indirect with one pointer->next level index block with one pointer->bottom level index block with one pointer->new data block. c. Free map to update the 4 newly allocated blocks, 4 writes to write the new blocks (3 index one data), one write to update the i-node to put the new triple index pointer. d. Caching and disk scheduling may cause delay of some or all of the writes, or reordering them leading to scenarios where any subset of the writes could have happened, with the other lost. Many scenarios possible, for example, data block written only but not connected to i-node.
Memory hierarchy is an important concept in architecture and OS design. Answer the following questions about memory hierarchy. a. Caching is the core technique to bridge the gap of access performance between different layers in the memory hierarchy. Caching works because of the program locality. Explain what program locality is. b. When the data we want is not in the cache, it is called a cache miss. What types of cache miss can we encounter? What are their relationship with the cache placement and replacement policies? c. A modified form of the FIFO cache replacement policy, known as the second-chance replacement algorithm, works by looking at the front of the queue as FIFO does, but instead of immediately evict the head item, it checks to see if it has been accessed (e.g reference bit is set) recently. If so, the item is inserted back into the end of the queue else it's evicted. Is this algorithm always going to result in fewer cache misses than FIFO? d. Someone argues that the clock algorithm is supposed to be an apx of LRU - Take a position for or against the statement and justify.
a. Temporal locality: recently accessed data/code is likely to be accessed again in the future Spatial locality: data/code close to the recently accessed data/code is likely to be accessed too. b. Code miss: When the cache is empty Conflict miss: When the cache is not full but due to placement policy, the entry has already been occupied by some data. Capacity miss: Cache is full Under conflict or capacity miss, one item needs to be evicted and the cache replacement policy decides which item to evict. c. No, they perform equally badly under the condition where all pages are always referenced. Moreover, it takes longer to select the victim item. FIFO doesn't require any state inspection. It always evicts at the first entry. Second chance, requires inspecting the reference bit every time and it may even need to push the first entry to the back one or more times. In terms of speed to select an item to evict it is slower. For space efficiency, it is also worse because now every entry needs a reference bit. d. In case every item is accessed during two scans, the clock algorithm will degrade to FIFO.
Latest Intel CPU supports IA-32e paging mode which translates 48-bit virtual addresses to 52-bit physical addresses with a page size of 4KB. all page translation tables must fit into one page and the CPU has a TLB. During address translation, a page fault is generated if any of the PTE during the page table walk is invalid or the request access mismatches protection configuration. a. Assume PTE entry must be aligned to 2^n boundary (e.g 2,4,8,...), how many levels of page tables are required to perform the translation? b. Explain possible steps involved in looking up the virtual address 0x7ffe1b03824d, when all pages are present in memory. c. Assume the access permission check is only performed after the address translation finishes, what is the maximum number of page faults that could be generated in response to a memory access? d. Why should the OS always leave an unmapped(invalid) virtual page between the stack and heap? e. Null pointer dereferences are critical bugs and can lead to security attacks. If the OS doesn't have a software mechanism to detect null pointers, what hardware mechanism can the OS use to trap the process when it dereferences a null pointer?
a. The physical address is 52-bit so the nearest 2^n boundary is 64-bit or 8 byte for each page table entry. Since each level of page table can only occupy one physical page, we have 4096/8=512 entries, which corresponds to 9 bits. Given the virtual address is 48-bit and the page size/offset is 12 bits, there are 36 bits left. 36/9 = 4, so we'll end up with 4-level page tables. b. Use the virtual page number 0x7ffe1b03824d to check if the TLB has the translation result. If yes, done. Else, walk the page tables. c. Since we have a 4-level page table, we can have 4 page faults for the address translation. Once the translation is okay, we check for access permissions, which may result in another page fault. So 5 possible page faults total. d. Stack grows top-down and heap grow bottom-up. The guarding page prevents stack and heap from growing into each other and corrupting the data. e. The OS kernel can keep the first virtual page(virtual address 0-4095) as always unmapped. In this way, dereferencing a Null pointer will result in a page fault and trapped kernel.
Consider a memory system with a virtual address space of 32 bits, a physical address space of size 30 bits, and a page size of 4Kbytes. a. (1 point) Given the virtual address 0xff0beef, what is the value of the VPN and the offset? b. (1 point) Given two pointers (i.e., virtual addresses) VA and VB with values 0xff00423 and 0xff01321 respectively, which of the following is true about their physical addresses. Assume that both pages are in memory. c. (1 point) Consider now the following two addresses PA and PB with values 0xff00423 and 0xff00321 respectively. d. (1 point) Can the virtual address of a global array change over the lifetime of a program (without the program copying/moving it)? Can the physical address? e. Someone argues that the clock algorithm is supposed to be an approximation of LRU. Take a position for or against this statement and justify.
a. VPN: 0xff0b Offset: 0xeef b. it is impossible to tell c. VA's physical address is larger than VB's physical address d. VA of data structure won't change unless you move it. PA can change after a page moves to swap them back in. e. The reference bit being accessed allows a page not be replaced for a full round. So, the page that is being replaced has not been accessed for a full round. Note that this is approximately LRU in the sense that removed page was not accessed recently but it may not be the one that was least reccently used. Also, in situations where most pages are getting referenced, clock becomes almost FIFO.