> released: 04/01, 9:00 > due: 04/06, 23:59 > > Answer the following questions. > Submit your answers to Canvas assignments. There is an entry for this homework. > > > 1. Virtual memory (5 points) > > Below are five statements about virtual memory. > Write down True if you agree with the statement; otherwise, write False. > > 1.a Virtual memory provides programmability (or sometimes called > transparency) that multiple programs can use the same address say > 0x123456 without a conflict. > > > 1.b Each physical page can be mapped to multiple virtual pages in one process. > > > 1.c Each virtual page can map to multiple physical pages. > > > 1.d On a 32 bit machine with 8 GB RAM installed, the physical address would be > larger than the virtual address space of one process. > > > 1.f TLB accelerates VM translation by assuming spatial and temporal locality. > If the assumptions do not hold, TLB is unable to speed up VM translation. > [see what is "locality" here: https://en.wikipedia.org/wiki/Locality_of_reference] [Answers: True: this is true; see notes of our first VMem class. True: this is how kernel maps the pages twice. False: this is impossible given the VM->PM translation is 1-on-1. (note that the above statement is true because there can be multiple translations: VM1->PM, VM2->PM) True: this is true because 2^32 Bytes => 4GB True: that is true for all cache, TLB included ] > > 2. Run the mmap experiment (2 points) > > Read handout week11.a page 2 (https://naizhengtan.github.io/22spring/notes/handout_w11a.pdf), > Copy the mmap code to a file "mmap.c". > Do the exercise in the handout with 1G file and answer question: > > Question: > Which runs faster, option 1 or option 2? by how much on your machine? > [comments: ** in principle, mmap (option1) should run faster. ** anywhere between 1.1x - 1000x sounds reasonable to me. ] > > 3. Page replacement policy: CLOCK (3 points) > > Suppose you have a machine named CS5600-clover with 4 pages of memory (total 16KB) and a 1TB SSD. > A process uses 10 pages; page P0-P3 are in the memory; P4-P9 are on SSD. > OS runs CLOCK algorithm for page replacement, and a visualization is below. > > P0 (A=0) > ^ > | > P3 + P1 > (A=0) (A=0) > > P2 (A=0) > > For CLOCK algorithm: > - The "hand"/"pointer" will go clock-wise. > - When evicting page, check the page pointed by the "hand" > -- if access bit is set (A=1), clear the bit (A=0) and advance one position. > -- if A=0, evict the pointed page, load the new page, and advance one position. > -- what's the access bit of the newly loaded page? answer: A=1 > the page is now being used. > - note: CLOCK is a family of algorithms. You might see different variants but > the core never changes---CLOCK can be perfectly implemented on hardware. > > If the memory accesses in the following are: > P0, P2, P3, P4, P5, P0, P9 > > How many page swaps will happen? and for each swap, which page has been swapped > in and which page has been swapped out (namely, the victim)? [ Anaswer: 4 times (1) P4 replaces P1 P0 (A=0) P3 +--> P4 (A=1) (A=1) P2 (A=1) (2) P5 replaces P0 P5 (A=1) ^ | P3 + P4 (A=0) (A=1) P2 (A=0) (3) P0 replaces P2 P5 (A=1) P3 + P4 (A=0) | (A=0) v P5 (A=1) (4) P9 replaces P3 P5 (A=1) P9 <--+ P4 (A=1) (A=0) P5 (A=1) ]