解析
youtube上有关于多级页表的很好的教程。
2
-
Paging Mechanisms
You are working on a new paging system for Better Paging Incorporated.
The system has a frame size of 64 bytes and has 4 frames.
Each process has 16 pages available to it.
The system
uses a three-level forward-mapped page table where the first level contains two entries and the
last level of the page table contains four entries.
(a) [2pts] What is the size of the physical address space?
256 byte
实际具有的内存,系统有4 X 64 bytes内存
(b) [2pts] What is the size of the virtual address space?
系统给进程提供的内存地址。
page = frame = block
16 X 256 = 1024 bytes
© [2pts] How many bits are in a physical address?
总共有256 bytes, 每个bytes都要给一个地址,所以就是 2^8 = 256, 总共用8位就可以给每一个bytes一个地址。
(d) [2pts] How many bits are used to index in to the second level page table?
原文
-
Overview
In class, we’ve been implementing virtual memory—but we’ve forgotten why.
(a) [2pts] Before virtual memory, in a uniprogramming environment, how did the system
allocate memory to processes?
(b) [3pts] In early multiprogramming environments, there existed a rudimentary form for
virtual memory called relocation. What were the limitations of relocation? Name three
that applied to both static and dynamic relocation.
© [3pts] Upon consideration of the problems of relocation, systems programmers moved to
a technique called paging. Name three advantages of paging.
(d) [4pts] How does paging prevent a process from accessing another process’s data?
2
-
Paging Mechanisms
You are working on a new paging system for Better Paging Incorporated. The system has a
frame size of 64 bytes and has 4 frames. Each process has 16 pages available to it. The system
uses a three-level forward-mapped page table where the first level contains two entries and the
last level of the page table contains four entries.
(a) [2pts] What is the size of the physical address space?
(b) [2pts] What is the size of the virtual address space?
© [2pts] How many bits are in a physical address?
(d) [2pts] How many bits are used to index in to the second level page table?
(e) [4pts] Draw the page table for a process in this system that is currently using 260 bytes of
its virtual address space. Remember that these bytes are allocated contiguously starting
from address zero.
3
-
Paging Policies
As part of your new paging system for Better Paging Incorporated, you have been asked to
implement the clock page replacement algorithm. The system that you are working in still has
4 frames. Assume for all questions that main memory starts off completely empty.
(a) [3pts] You’re feeling lazy so you decide to implement FIFO instead of clock. Given the
access order below, how many page faults will occur?
A, B, C, D, E, B, F, B
(b) [3pts] Your boss is pretty upset with the performance of your algorithm on his test cases
and suggests keeping the frame size the same but using a system with a larger physical
address space. How will this impact the performance of FIFO? Remember we don’t know
the contents of your boss’s test cases. Defend your answer.
© Your boss finally caught on and realized that you didn’t implement clock.
i. [5pts] Describe an implementation of clock. Be certain to include which part of the
system is responsible for each step.
ii. [3pts] Using the clock algorithm how many page faults will occur? You are still in the
system described above and you should consider the same access order:
A, B, C, D, E, B, F, B
4
(d) After implementing clock you decide you could do better and implement Second Chance++.
Second Chance++ is the same as second chance but the programmer assigns an impor-
tance to each page in memory. You then calculate a priority for a page by adding the
reference bit, the dirty bit, and the importance. When main memory is full the page with
the lowest priority is evicted.
i. [2pts] Are there any advantages to this algorithm? If so, list and explain one. If not,
defend your answer.
ii. [4pts] List and explain two disadvantages.
5
-
Heap Memory Management: Explicit
The TAs are trying to rewrite Piazza in C, but we’ve had some pointer trouble. We decided
to put our code on the exam so y’all can help us out–Alison is very disappointed, and we are
ashamed.
1
struct
help_msg {
2
char *text;
3
int views;
4
};
5
6
void
create_msg (struct
help_msg
**msg , char *text) {
7
struct
help_msg *new_msg = malloc(sizeof(struct
help_msg ));
8
new_msg ->text = *text;
9
new_msg ->views = 0;
10
11
printf(" debug: %p\n" , new_msg );
12
13
*msg = new_msg;
14
}
15
16
void
main () {
17
struct
help_msg *msg;
18
create_msg (&msg , " Help! I’m crying in Pintos." );
19
/do some stuff/
20
free(msg);
21
}
(a) [2pts] Identify all the lines of code where potential errors could occur and suggest a fix.
(b) [2pts] What simple step could help us identify memory errors when they first occur?
© [2pts] What type of address, physical or virtual, is printed by the statement on line 11?
(d) [2pts] In what part of the process’s address space is new
msg’s data allocated?
(e) [2pts] Describe what happens in the system when the data for new
msg is allocated. You
may assume that is the first call to malloc().
(f) [2pts] Assuming the system is managing the heap using a free list without binning, describe
the steps taken when free() is called on line 20.
-
Heap Memory Management: Automatic
The TAs have such bad pointer management skills that we have given up on C and are trying to
rewrite Piazza in Java. Consider the revised code and answer the following questions—you may
assume a generational garbage collector. (You’ll notice that the TAs can’t code Java either,
but this time Alison doesn’t know! )
1
public class HelpMsg{
2
String text;
3
int views;
4
}
5
6
public static void
createMsg (HelpMsg msg , String
text) {
7
HelpMsg
newMsg = new HelpMsg ();
8
newMsg.text = text;
9
newMsg.views = 0;
10
msg = new_msg ;
11
}
12
13
public static void
main(String [] args) {
14
HelpMsg
msg;
15
createMsg (msg , " Help! I’m crying in Pintos." );
16
//do some stuff
17
}
(a) [2pts] By making the switch to Java, did the TAs avoid pointers all together? (i.e., are
there any pointers in the above code?) Explain.
(b) [2pts] In what part of the process’s address space is newMsg’s data allocated?
© Consider a process that has been running for some time. That process calls new (again! ),
and a garbage collection is triggered.
i. [2pts] What happened in the heap to trigger this garbage collection?
ii. [4pts] Describe the steps taken by the generational garbage collection algorithm to
collect the heap.
-
Files
(a) Consider a system where the disk partition has 18KB of remaining free space in three
contiguous sections: 4KB, 8KB, and 6KB. The file system manages that partition using
1KB blocks, and it is now trying to allocate 14.5KB of file data for a new file.
i. [4pts] How would FFS allocate this file data?
ii. [4pts] How would NTFS allocate this file data?
iii. [3pts] How would ext4 allocate this file data?
(b) [4pts] There is a new hardware development in spinning disk technology, and now you can
read from all disk heads at once! How would you change your file layout to adapt to this
development? Defend your answer.
8
-
Consistency and Reliability
(a) Consider a system using a Fast File System, which was an early UNIX file system. One
day, as you are working in this system, you try to save a file after adding at least 6KB of
data—as you do, someone trips over the power cord and your system crashes.
Given that the file system was performing the following operations:
i. Write data block
ii. Update inode
iii. Update data bitmap
and assuming your system crashes between steps ii and iii above, answer the following
questions about the state of your file system on recovery.
i. [3pts] Is your file system in an inconsistent or a consistent state? Defend your answer.
ii. [3pts] Could access to your newly added data be restored? Defend your answer.
iii. [3pts] How does your answer change if you are using ext4, a journaling file system?
(b) One way to get more reliability from unreliable parts is to implement a RAID.
i. [2pts] If you have two disks and desire reliability, which RAID level would you choose?
Why?
ii. [2pts] Why is RAID-4, which is block-striped, considered more efficient than RAID-3?
-
Projects and Overview
(a) [3pts] In class and in Project 2, you learned about file descriptors. What is the purpose
of a file descriptor? Where is it created and maintained?
(b) [3pts] Assuming a disk is divided into 512-byte sectors and the system is using 4KB block.
Also realize that a call to disk
write() only writes a single sector. How many times must
the kernel call disk
write() to write a block?
© As we discussed virtual memory, we discussed that the system could write pages that were
not currently being used to swap.
i. [3pts] What is swap?
ii. [3pts] What is the effect of swapping on an SSD?
10
Scratch Paper
11
Scratch Paper
12
Scratch Paper
13