Operating System: Chapter 11 HomeWork

11.1
所有extent都為same size的情況下,block allocation很簡單,只要一個bit map或是free list for extents就能完成。如果extents的size可以是任何數值,那麼就會需要更複雜的allocation scheme,可能會找不到合適size的extent,且可能會有external fragmentation。如果extent可以是數種可能的fixed size,那可能會需要maintain數個不同的bitmap或是free list。這種方式的複雜度和flexibility都介於前面兩者之間。

11.2
Contiguous Sequential - File是以contiguous的方式儲存,因此運作得很好
Contiguous Random - Works very well as you can easily determine the adjacent disk block containing the position you wish to seek to。很容易找到鄰近區塊?
Linked Sequential - 只要讀取下一個block即可。
Linked Random - 效果不好,因為要找到intended seek point可能需要透過好幾個disk blocks。
Indexed Sequential - 只要依序讀取每個index即可。
Indexed Random - 效果好,因為很容易找到包含有seek point的block的index。

11.3
當讀取儲存在file中間的block時,可以直接讀取儲存在FAT中的pointers,而不用sequentailly讀取每個block來找出target block。且大多數的FAT可以cache在memory中,因此pointer只需要memory access就能找到,而不用access disk blocks。

11.4
a. 為了要重建free list,必須進行garbage collection。這會搜尋整個directory structure來判斷哪些page已經被allocate to jobs。那些unallocate的會被加入至free-space list中。
b. 首先要讀入包含root directory的disk block(/),接著分別讀入包含directory b和c的disk block(/a/)(/a/b/),最後讀入包含file c的disk block。
c. 可以將free-space list pointer存在disk中,可以存好幾個位置。

11.5
這樣的scheme可以降低internal fragmentation。例如說5KB的檔案可以被分配到一個4KB的block和兩個contiguous的512-byte的blocks。
為了要maintain free blocks的bitmap,同時也要maintain紀錄block之中有哪些subblock正在被使用的紀錄。Allocator野會需要這些資訊來allocate subblock並且合併(coalesce)多個subblock。

11.6
Data和metadata的update可能會delay。Update可能會延遲,因為這個版本的update可能過不久就會被取代。但如果system在delayed update被上傳之前就crash的話那麼the consistency of the file system就會失敗。

11.7
Contiguous.
將logical address除以512之後得到X和Y
X+Z即是physical block number,Y則是displacement
只要1次就可以讀取,因為可以直接獲得地址

Linked.
Block之中第一個byte是用來紀錄往下一個block的位址,因此:
除數要-1,所以是511。
Chase down the linked list為X+1,因為第一個block為空的
Displacement為Y+1,因為第一個byte為地址。
必須讀取4個block,按照順序。

Indexed.
首先將index block讀入memory。Index block中儲存了block的地址,第X個即是我們要的physical block address。Y則是displacement。
2次,一次是讀取index block,一次是讀取target block。

11.8
???

11.9
Relocation在secondary storage上會造成顯著的overhead - data blocks必須先讀入main memory在寫回他們新的location。除此之外,relocation register只能apply to sequential files,而很多disk files並非sequential的。因此很多檔案並不需要contiguous disk space,即使是sequential files,也能透過links between sequential blocks來連接。

11.10
可能會發生inconsistency。如果發生inconsistency,那麼必須有方法update或在下一次使用的時候detect。如果detect到inconsistency,那麼必須要有fallback mechanism來得知新的name translation。
另外一個issue是a name lookup是否要讀取pathname中的每一個subdirectory,還是只讀取目標檔案。如果全部讀取的話client可以獲得許多中間directories的資訊,但是會增加許多network traffic。

11.11
File system要能夠在crash之後recover的條件是,他必須要是consistent的。
也就是說logging metadata update必須要能夠讓file system保持在consistent state。
若是file system變成inconsistent,那麼meta data一定是被不完全的寫入或是按照錯誤的順序寫入。
有了meta data loggin,寫入資訊會記錄成sequential log。
The complete transaction在進入file system structure之前就已經被記錄。
如果system crashes during file system data update,那麼可以根據log之中的紀錄復原。
Log之中的changes保證是正確的,順序也是。如果有個change寫入不完全,那他會被discard掉。

11.12
Restore更加簡單因為可以直接讀取最後一個tape(medium)。但是需要用來儲存的媒體更多。










留言