Linux基礎練習_複習題

Q:It has been suggested that the first part of each UNIX file be kept in the same disk block as its i-node. What good would this do?

A:When reading the file, if the first partof file is kept in the same disk block with its i-node,fewer disk accesses will be needed.

In particular, if the file is short (i.e.the entire file is in one disk block), it costs only one disk access.


Q:The Unix File System uses i-nodes to index directories and files. Assume only the address of the data block for root directory is cached (known). All other contents stored in the File System are not cached. Assume the content of directories can be stored in only one data block. What are the disk operations needed to read the first byte of a file: /user/jlu/os_2015_exam.tex? Explain your answer.

A:The disk operations are as followings:
1. Directory for “/”
2. I-node for “/user”
3. Directory for “/user”
4. I-node for “/user/jlu”
5. Directory for “/user/jlu”
6. I-node for “/user/jlu/ os_2015_exam.tex”
In conclusion, we need six disk operations to read the first byte of this file.


Q:A computer has four page frames. The time of loading, time of last access, and the R (for read) and M (for modified) bits for each page are as shown below (the times are in clock ticks):

Pages

Loaded

Last ref

R

M

0

126

280

1

0

1

230

265

0

1

2

140

270

0

0

3

110

285

1

1

Consider four page replacementalgorithms:

a) Which page will FIFO replace?Justify!

b) Which page will NRU replace?Justify!

c) Which page will LRU replace?Justify!

d) Which page will secondchance replace?Justify!

A:

a) FIFO: Page 3 will be replaced.
Because the time of loading indicates that Page 3 is the oldest page.

b) NRU: Page 2 will be replaced.
Because the class order is:
Page2(class 0) < Page 1(class1) < Page 0(class2) < Page 3(class3).

c) LRU: Page 1 will be replaced.
Because the time of last reference indicates that Page 1 is the page that has been unused for the longest time.

d) Second chance: Page 2 will be replaced.
Because the algorithm works as followings:
-- It first looks at Page 3 which is the oldest. But the R bit is set, so it puts Page 3 onto the end of the list and clears the R bit.
-- Then it looks at Page 0 which is the second oldest. But again the R bit is set, so it does the same thing with Page 0.
-- Finally, when it looks at Page 2 which has the R bit cleared, it succeeds and Page 2 is removed.


Q:On a 32-bit machine, two-level page table are used. Top-level table uses 9 bits and second-level table uses 11 bits, what is the page size and how many pages?

A:There are 32-9-11=12 bits used for the offset, so the page size is 2^12=4096B=4KB. Since 20 bits are for virtual page table, we have 2^20=1048576 pages.
Conclusion: the page size is 4KB and there are 2^20(i.e.1048576) pages.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章