Review Problems for CS 302, Exam 2 The second exam will cover Chapters 11, 12, 13, and 14 of the operating systems textbook. In addition, the exam will cover the material we went over about how the C language stores various kinds of variables in virtual memory. In particular, you should be familiar with the following terms: storage classes, scope, lifetime, local and global variables, initialized and uninitialized variables, automatic variables, static variables, external variables, dynamic variables, code segment, data segment, bss segment, heap, stack, stack frames. 1. List the steps to process a page-fault. 2. In a paged virtual memory system, why does the page-size have to be a power of two? 3. What is the advantage of using multi-level page tables in a paged virtual memory system? 4. List an advantage and a disadvantage of increasing the size of a page frame in a paged virtual memory system. 5. In a paged virtual memory system, can the computer's physical memory space be larger than a process's virtual memory space? Explain your answer. 6. In a paged virtual memory system, explain how if a process modifies an arbitrary location in its memory space, the change is not reflected at the same address of other processes. 7. Does a paged virtual memory system have internal or external fragmentation? Explain your answer. 8. In a paged virtual memory system with 32 bit virtual addresses and 8KB page frames, how many bits of a virtual address are used as an offset into a page frame and at most how many page frames can a process have allocated to it? 9. Conceptually, how many entries are there in a page table? a) |virtual address space| b) |(virtual address space)/(page size)| c) (# of page frames allocated to the process) * (page size) d) (# of page frames allocated to the process) / (page size) e) # of page frames allocated to the process 10.In a translation lookaside buffer implementation of a page table, how many entries are in the page table? a) |virtual address space| b) |(virtual address space)/(page size)| c) (# of page frames allocated to the process) * (page size) d) (# of page frames allocated to the process) / (page size) e) # of page frames allocated to the process 11. Define spatial reference locality and explain how it is related to a process's working set. 12. In a demand paged virtual memory system, what is the purpose of the replacement policy? What is the purpose of the allocation policy? Name a few different replacement and allocation policies. 13. A paged virtual memory system must have a "fetch policy" that decides when a page should be loaded into primary memory. The simplest fetch policy is to load a page only when it has been page faulted. What is another possible fetch policy and what advantage might it have over the simplest one. (Hint: prefetch) 14. Match the following descriptions of page replacement policies for choosing how the replaced page y[t] is chosen with the following names for the policies. a) y[t] chosen randomly b) an oracle function selects y[t] c) y[t] = x such that x has maximum forward distance d) y[t] = x such that x has maximum backward distance e) None of the above i) least frequently used (LFU) strategy ii) least recently used (LRU) strategy iii) Belady's optimal strategy 15. Dynamic paging algorithms are said to be dynamic because a) they implement dynamic address binding b) they implement dynamic address translation c) they implement dynamic memory allocation 16. Assume that a computer has only three physical pages. The following diagrams show two sequences of referenced pages. Write down in the empty slots below each reference the pages that are loaded in physical memory at each page reference. Also, write down the number of page hits and misses. Use the LRU page replacing policy in both cases. Page Referenced: 1 2 3 4 1 2 3 4 Phys Page 1 Phys Page 2 Phys Page 3 # of hits = # of misses = Page Referenced: 1 2 1 2 3 4 3 4 Phys Page 1 Phys Page 2 Phys Page 3 # of hits = # of misses = 17. Suppose a computer has 4 physical pages, and a process references its virtual pages (page 0 through page 7) in the following order: 0 2 1 3 5 4 6 3 7 4 7 3 3 5 5 3 1 1 1 7 2 3 4 1 a) Suppose the kernel uses FIFO page replacement algorithm. How many page faults would the process have? Which page references are page faults? b) Suppose the kernel uses LRU as the page replacement algorithm. Answer the above two questions. c) Suppose the kernel uses the optimal page replacement algorithm. Answer the above two questions. 18. Let w = 0,4,1,4,1,5,1,6,2,6,3,6,2,6,4,5 be a page reference stream. Given a static page frame allocation of 3 and assuming the primary memory is initially unloaded, how many page faults will the given reference stream incur using the optimal strategy? Using the LRU strategy? 19. Assume the following 2-level page table. Translate the VM addresses 0x00801B4B and 0x00C01578 to their corresponding physical address. Assume a 32-bit word size. Assume a page size of 4KB and that the first 10 bits of the VM address index the level 1 page table, the next 10 bits index the second level and the bits left are the page offset. The third column in the level 2 page tables are physical page addresses. VM Address 0x00801B4B is ______________ in Physical Memory VM Address 0x00C00578 is ______________ in Physical Memory Level 1 0 0x38000 1 0x36000 2 0x32000 3 0x40000 Level 2 at 0x38000 0 0x42000 1 0x50000 2 0x70000 Level 2 at 0x32000 0 0x56000 1 0x58000 2 0x72000 Level 2 at 0x36000 0 0x5a000 1 0x5c000 2 0x62000 at 0x40000 0 0x89000 1 0x82000 2 0x86000 20. List five properties of a file that most file systems would store in a file descriptor. 21. List five operations on files that most file systems would implement. 22. For each of the following block allocation strategies, describe how efficiently the strategy handles sequential and random access of large files and why. Contiguous Allocation: Linked Allocation: UNIX inodes: 23. Contiguous allocation of files leads to disk fragmentation. Is this internal or external fragmentation? Explain your answer. 24. Could you simulate a multilevel directory structure with a single-level directory structure in which arbitrarily long file names can be used? If so, how? 25. Consider a file system where free blocks are kept in a free-block list. Suppose that the pointer to the beginning of the free-block list is lost. Can the system reconstruct the free- block list? Explain your answer. 26. Which of the following are the result of compile time processing, link time processing, and runtime processing? a) Executable in-memory image b) Absolute object modules c) Relocatable object modules 27. Assume the following program. int a[300]; int b = 25; void foo() { int d; } int main() { static int c; int * e = new int; } Write the memory section for the running program that corresponds to each of the following memory addresses (the memory sections are: TEXT, LIBRARY, DATA, BSS, STACK, HEAP). Memory Address &a &b &c &d &e e &main &printf 28. Explain in detail the difference between the following three functions. int functionA() { static int i; i++; return i; } int functionB() { static int i = 0; i++; return i; } int functionC() { static int i; i = 0; i++; return i; } 29. In what way is a static local variable like a global variable? In what way are they different? (Hint: Lifetime and scope.) 30. What does the following functionA() do? int functionA(int i) { static int j = 0; int k; k = j; j = i; if (k > j) return k; else return j; } 31. Determine which of the following C expressions are equivalent to a[i]. The type of a[0] is denoted by . Expression a + i a + i * sizeof() &a + i *(a + i) *(a[0] + i) *(&a[0] + i) *(&a[i]) &a[i] *( *) ((char *) &a[0] + i ) *( *) ((char *)&a[0] + i * sizeof(a[0]))