This homework contains practice for thinking about virtual memory, which you will need in the remainder of the class. So you should totally work through the problems carefully even though, as usual, we're not going to grade these strictly.
Scheduling
This question is open-ended; there are many possible answers. You don't have to type very much, and you can think about these questions even when you are not in front of a computer.
There are many metrics that a scheduler has to balance: turnaround time, response time, throughput, and various definitions of fairness. We will consider the following types of systems in this question:
- A high-performance computer used for large number crunching tasks (genetic sequencing, graphics rendering...)
- A multimedia computer (video games, movies...)
- A smartphone
- A general-purpose computer on a corporate desktop
- For each of the system types above, which metrics do you think are the most important, and why? Some things to consider: How many users does the system have? Are user processes typically interactive? How long is a user willing to wait? What frustrations will users have if certain metrics are ignored? (There are many possible answers to this question.)
- Taking into consideration your answers above, propose a scheduling policy (FIFO, etc.) for each system above.
- For each of the systems above, what is the scheduling policy that would most completely undermine the purpose of the system?
Virtual memory: warmup
This question is borrowed from CS:APP3e [Computer Systems: A Programmer’s Perspective (Third Edition), by Randy Bryant and David R. O’Hallaron].
Complete the following table, filling in the missing entries and replacing each question mark with the appropriate integer. Use the following units: K = 210 (kilo), M = 220 (mega), G = 230 (giga), T = 240 (tera), P = 250 (peta), or E = 260 (exa).
Number of virtual address bits | Number of virtual addresses | Largest possible virtual address |
---|---|---|
4 | 16 | 16 − 1 = 15 |
8 | ____ | ____ |
____ | 2? = 64 K | ____ |
____ | ____ | 232 − 1 = ? G - 1 |
____ | 2? = 256 T | ____ |
64 | ____ | ____ |
Virtual memory: paging
This question is also borrowed from CS:APP3e.
Determine the number of page table entries (PTEs) that are needed for the following combinations of virtual address size (n) and page size (P).
n | P | Number of PTEs |
---|---|---|
16 | 4K | ____ |
16 | 8K | ____ |
32 | 4K | ____ |
32 | 8K | ____ |
48 | 4K | ____ |
Virtual memory: address translation
This question is also borrowed from CS:APP3e, and lightly modified.
Given a 32-bit virtual address space and a 24-bit physical address, determine the number of bits in the VPN, PPN (your book, OSTEP, calls this PFN), and offset, for the following page sizes P:
P | # of VPN bits | # of PPN bits | # of offset bits |
---|---|---|---|
1 KB | ____ | ____ | ____ |
2 KB | ____ | ____ | ____ |
4 KB | ____ | ____ | ____ |
8 KB | ____ | ____ | ____ |
WeensyOS
Begin Weensy OS:
Read the lab 4 description. Seriously, read it. (As opposed to skimming it.)
Fetch and build the code.
Now answer:
Where in physical memory—which pages or addresses—does the kernel’s code and data live? Give the range in hex. (Hint: you do not need to look at the code; you can simply
make run
ormake run-console
and read it off the graphical memory maps.)What physical address does the kernel’s stack live on?
Same two question as above, for virtual memory: what are the virtual addresses of the kernel’s code and data, and at what virtual address does the kernel’s stack live in virtual memory?
Use the constants and macros given in the assignment (in the sections “Memory system layout” and “Writing expressions for addresses”) to write an expression for the number of physical pages in memory. This will be handy to have as you begin coding the lab.
x86-64 multilevel page tables
Consider the x86-64 architecture. Below we are asking about the physical pages consumed by a process, including the page tables themselves. As you answer the question, assume that any allocated memory consumes physical pages in RAM; that is, there is no swapping or demand paging. Note that it may be helpful for you to draw pictures (but you don’t have to).
As a reminder, the x86-64 imposes a multi-level page table structure: pages are 4KB, each page table entry is 8 bytes, and each individual page table (a node in the “tree”) occupies one page. Thus, each page table holds 4 KB / 8 B = 512 = 29 entries. Recall that the structure is four levels; each level is indexed by 9 bits of the virtual address.
What is the minimum number of physical pages consumed by a process that allocates 12KB (for example, 1 page each for code, stack, and data)?
What is the minimum number of physical pages consumed by a process that makes 29 + 1 allocations of size 4KB each? You can leave your answer in terms of powers of 2, and sums thereof.
What is the minimum number of physical pages consumed by a process that makes 218 + 1 allocations of size 4KB each? You can leave your answer in terms of powers of 2, and sums thereof.
Handing in the homework
Use Gradescope.