Skip to content

記憶體、I/O 與檔案系統複習 ​

保留期末筆記中的名詞解釋、對照表與複習範例。各架構及檔案系統的設計歸屬依段落標示。

對照 WUWAOS 章節:08 · 頁面、虛擬記憶體與 COW · 07 · 資料怎麼進出:I/O 與磁碟 · 09 · 資料怎麼存下來:WUFS 與磁碟復原

教材:恐龍書第 10 版 第 9–15 章選讀。 原始課堂筆記

9.4.1&9.6 ​

可以,這次照前面定好的格式重新整理。 9.4.1 主要是 Hierarchical Paging;9.6 主要是 Intel IA-32 / x86-64 位址轉換。課本 9.4.1 的核心是分頁表太大,所以把 page table 拆成多層;9.6 則是 IA-32 的 logical address → linear address → physical address 流程。

text
9.4.1 Hierarchical Paging

Hierarchical Paging(階層式分頁):
階層式分頁是將過大的 page table 拆成多層小表格的技術。
其目的,是避免每個 process 都需要一整張巨大且連續的 page table。
簡單說,就是把 page table 自己也分頁管理。

Two-Level Paging(二層分頁):
二層分頁是 hierarchical paging 的典型形式。
它把原本單層 page table 拆成 outer page table 與 inner page table。
位址轉換時,先查外層表,再查內層表,最後得到 physical frame number。

Outer Page Table(外部分頁表):
outer page table 是二層分頁中的第一層表格。
它的 entry 不直接指向資料所在的 physical frame,
而是指向某個 inner page table。

Inner Page Table(內部分頁表):
inner page table 是二層分頁中的第二層表格。
它的 entry 才會指向真正的 physical frame。
因此位址轉換時,outer page table 先找到 inner page table,
inner page table 再找到 frame number。

Forward-Mapped Page Table(前向映射分頁表):
forward-mapped page table 是 two-level paging 的另一種稱呼。
因為位址轉換是從 outer page table 一路往 inner page table 查進去,
所以稱為 forward-mapped。

p1(Outer Page Table Index,外層分頁表索引):
p1 是 logical address 中用來查 outer page table 的欄位。
在 32-bit address、4 KB page 的二層分頁例子中,
p1 佔 10 bits,用來選 outer page table 的某個 entry。

p2(Inner Page Table Index,內層分頁表索引):
p2 是 logical address 中用來查 inner page table 的欄位。
在 32-bit address、4 KB page 的二層分頁例子中,
p2 佔 10 bits,用來選 inner page table 的某個 entry。

d(Page Offset,分頁內位移):
d 是 page offset,表示資料在某個 page 內部的位移。
在 4 KB page 中,page size = 2^12 bytes,所以 offset 需要 12 bits。

32-bit Two-Level Address Format(32 位元二層分頁位址格式):
在 32-bit logical address、4 KB page 的例子中,
位址會被拆成 p1、p2、d 三個部分:

p1 = 10 bits
p2 = 10 bits
d  = 12 bits

p1 查 outer page table,
p2 查 inner page table,
d 表示 page 內部 offset。

Page Table Too Large Problem(分頁表過大問題):
在 32-bit address space 且 page size 為 4 KB 的情況下,
page table 會有 2^20 個 entries。
若每個 entry 佔 4 bytes,單一 process 的 page table 就可能需要 4 MB。
因此 OS 不希望配置一整塊巨大且連續的記憶體來存放 page table,
這就是 hierarchical paging 的動機。

課本 IA-32 說明中,CPU 先產生 logical address,segmentation unit 產生 linear address,paging unit 再產生 physical address;LDT/GDT 的 entry 是 8-byte segment descriptor,包含 segment 的 base location 與 limit。

text
9.6 Example: Intel 32- and 64-bit Architectures

IA-32 Architecture(Intel Architecture 32-bit):
IA-32 是 Intel 的 32-bit architecture。
在 IA-32 中,memory management 分成 segmentation 和 paging 兩部分。
CPU 先產生 logical address,經過 segmentation 轉成 linear address,
再經過 paging 轉成 physical address。

Segmentation Unit(分段單元):
segmentation unit 負責將 logical address 轉換成 linear address。
它會利用 selector 找到 segment descriptor,
再根據 descriptor 中的 base 與 limit 檢查 offset 是否合法。
若合法,linear address = base + offset。

Paging Unit(分頁單元):
paging unit 負責將 linear address 轉換成 physical address。
在 IA-32 中,segmentation 之後得到的 linear address
會交給 paging unit 查 page directory 與 page table,
最後產生真正的 physical address。

Logical Address(邏輯位址):
在 IA-32 中,logical address 由 selector 和 offset 組成。
selector 用來選擇 segment descriptor,
offset 則表示在該 segment 內部的位移。

Linear Address(線性位址):
linear address 是 IA-32 中 segmentation unit 產生的 32-bit address。
它不是 physical address,而是 paging unit 的輸入。
也就是 logical address 先被 segmentation 轉成 linear address,
linear address 再被 paging 轉成 physical address。

Physical Address(實體位址):
physical address 是 paging unit 產生的最終位址。
它是真正送到 physical memory 的位址。

Selector(選擇子):
selector 是 IA-32 logical address 的一部分,大小為 16 bits。
它用來選擇 descriptor table 中的某個 segment descriptor。
selector 內部包含 segment number、選擇 GDT 或 LDT 的欄位,
以及 protection 相關欄位。

Offset(位移):
offset 是 logical address 的一部分,表示某個 byte 在 segment 內部的位置。
segmentation unit 會檢查 offset 是否超過 segment limit;
若沒有超過,就用 base + offset 產生 linear address。

Segment Descriptor(段描述子):
segment descriptor 是 GDT 或 LDT 中的一筆 entry,
用來描述某個 segment。
它包含 segment 的 base location、limit,以及 protection 資訊。
segmentation unit 會根據 descriptor 進行位址合法性檢查與位址轉換。

LDT(Local Descriptor Table,區域描述表):
LDT 用來存放某個 process 私有 segments 的 segment descriptors。
IA-32 中,每個 process 最多可有 8K 個 private segments,
這些資訊會放在 LDT 中。

GDT(Global Descriptor Table,全域描述表):
GDT 用來存放所有 processes 共享 segments 的 segment descriptors。
IA-32 中,最多可有 8K 個 shared segments,
這些資訊會放在 GDT 中。

Segment Register(段暫存器):
segment register 會指向目前使用的 segment descriptor。
IA-32 有多個 segment registers,
讓 process 在同一時間可定址多個 segments。

Descriptor Cache / Microprogram Register(描述子快取 / 微程式暫存器):
IA-32 會用特殊暫存器保存從 LDT 或 GDT 取出的 descriptors。
這樣每次 memory reference 時,不必都重新從 memory 讀取 descriptor,
可以加速 segmentation。

IA-32 paging 支援 4 KB 或 4 MB page;4 KB page 使用 two-level paging,其中 CR3 指向目前 process 的 page directory,高 10 bits 查 page directory,中間 10 bits 查 page table,低 12 bits 是 page offset。Page Size flag 若設定,page directory 會直接指向 4 MB page frame。

text
IA-32 Paging 相關名詞

Page Directory(分頁目錄):
page directory 是 IA-32 two-level paging 的第一層表格。
CR3 register 會指向目前 process 的 page directory。
page directory entry 會指向第二層的 page table。

Page Table(分頁表):
page table 是 IA-32 two-level paging 的第二層表格。
page table entry 會記錄對應的 physical frame number。
在 4 KB page 的情況下,linear address 的 p2 會用來查 page table。

CR3 Register(CR3 暫存器):
CR3 register 指向目前 process 的 page directory。
在 IA-32 paging 中,位址轉換會先從 CR3 找到 page directory,
再根據 linear address 進行查表。

4-KB Page(4 KB 分頁):
4-KB page 是 IA-32 支援的標準 page size。
因為 4 KB = 2^12 bytes,所以 page offset 需要 12 bits。
在 4-KB page 下,32-bit linear address 通常切成 10 bits、10 bits、12 bits。

4-MB Page(4 MB 分頁):
4-MB page 是 IA-32 支援的大型 page。
若 page directory entry 中的 Page Size flag 被設定,
page directory entry 會直接指向 4-MB page frame,
不需要再查 inner page table。

Page Size Flag(分頁大小旗標):
Page Size flag 是 page directory entry 中的旗標。
如果被設定,代表此 entry 指向的是 4-MB page frame,
而不是指向第二層 page table。
因此位址轉換可以跳過 inner page table。

Invalid Bit for Page Table(分頁表無效位元):
IA-32 的 page table 本身也可以被 swapped to disk。
page directory entry 中的 invalid bit 可表示它指向的 page table
目前是在 memory 還是在 disk。
若 page table 在 disk,OS 可利用其他 bits 記錄它的 disk location,
需要時再載回 memory。

Page Table Swapping(分頁表換出):
page table swapping 是指 page table 本身也可以被換到 disk。
這樣可以節省 physical memory,
因為不是每個 process 的所有 page tables 都必須常駐 RAM。

PAE 的重點是讓 32-bit processor 存取超過 4 GB 的 physical memory;它把 paging 從 two-level 變成 three-level,新增 page directory pointer table,且 PDE/PTE 由 32 bits 變 64 bits,使 physical address 可到 36 bits、最多 64 GB。

text
PAE 相關名詞

PAE(Page Address Extension,頁面位址延伸):
PAE 是 IA-32 的位址延伸技術。
它讓 32-bit processor 可以存取超過 4 GB 的 physical memory。
PAE 擴大的是 physical address ability,不是讓單一 32-bit process
擁有超過 4 GB 的 linear address space。

Page Directory Pointer Table, PDPT(分頁目錄指標表):
PDPT 是 PAE 中新增的最上層 paging table。
在 PAE 下,32-bit linear address 的最高 2 bits 會用來選擇 PDPT entry。
PDPT entry 再指向 page directory。

PDE(Page Directory Entry,分頁目錄項目):
PDE 是 page directory 中的一筆 entry。
在一般 IA-32 中 PDE 是 32 bits;
在 PAE 中 PDE 變成 64 bits,
因此可以記錄更長的 physical base address。

PTE(Page Table Entry,分頁表項目):
PTE 是 page table 中的一筆 entry。
它通常記錄 physical frame 的位置與控制資訊。
在 PAE 中 PTE 從 32 bits 變成 64 bits,
因此可支援更大的 physical address。

36-bit Physical Address(36 位元實體位址):
PAE 讓 IA-32 支援 36-bit physical address。
原因是 PAE 讓 page frame base address 從 20 bits 擴成 24 bits,
再加上 4-KB page 的 12-bit offset,
形成 36-bit physical address。

64-GB Physical Memory(64 GB 實體記憶體):
36-bit physical address 可定址 2^36 bytes,
也就是最多 64 GB physical memory。
這是 PAE 讓 32-bit processor 可以使用超過 4 GB RAM 的原因。

PAE Address Format(PAE 位址格式):
在 PAE 的 4-KB page 架構下,
32-bit linear address 會被拆成:

2 bits + 9 bits + 9 bits + 12 bits

最高 2 bits 查 PDPT,
接著 9 bits 查 page directory,
再接著 9 bits 查 page table,
最後 12 bits 是 page offset。

x86-64 是 IA-32 指令集延伸出的 64-bit architecture;課本指出 x86-64 使用 48-bit virtual address、可支援 52-bit physical address,並使用四層 paging hierarchy,page size 可為 4 KB、2 MB、1 GB。

text
x86-64 相關名詞

x86-64 Architecture(x86-64 架構):
x86-64 是從 IA-32 instruction set 延伸出的 64-bit architecture。
它支援比 IA-32 更大的 virtual address space 與 physical address space。

48-bit Virtual Address(48 位元虛擬位址):
雖然 x86-64 是 64-bit architecture,
但目前設計實際使用 48-bit virtual address。
這代表 virtual address space 比 IA-32 大很多,
但不是完整使用 64 bits。

52-bit Physical Address(52 位元實體位址):
x86-64 可支援 52-bit physical address。
這讓系統可以定址非常大的 physical memory。

Four-Level Paging Hierarchy(四層分頁架構):
x86-64 使用四層 paging hierarchy 來轉換 virtual address。
相較 IA-32 的二層分頁與 PAE 的三層分頁,
x86-64 為了支援更大的 address space,需要更多層 page tables。

PML4(Page Map Level 4,第四層頁面映射表):
PML4 是 x86-64 四層分頁中的最上層表格。
它會指向下一層的 page directory pointer table。
位址轉換會從 PML4 開始往下查。

Large Pages(大型分頁):
x86-64 支援多種 page size,包括 4 KB、2 MB、1 GB。
大型 page 可以減少 page table 數量與 TLB 壓力,
但可能造成較多 internal fragmentation。

4 KB / 2 MB / 1 GB Page Sizes(x86-64 分頁大小):
x86-64 支援 4 KB、2 MB、1 GB 的 page size。
4 KB 是一般小 page,
2 MB 和 1 GB 則是 large pages。
text
最後速背版

9.4.1:
Hierarchical Paging:page table 太大,所以把 page table 自己分層。
Two-Level Paging:外層表找內層表,內層表找 frame。
Outer Page Table:第一層,entry 指向 inner page table。
Inner Page Table:第二層,entry 指向 physical frame。
Forward-Mapped Page Table:two-level paging 的別名。
p1 / p2 / d:p1 查外層,p2 查內層,d 是 offset。

9.6:
IA-32:先 segmentation,後 paging。
Logical Address:selector + offset。
Selector:選 segment descriptor。
Segment Descriptor:segment 的資料卡,含 base、limit、protection。
Linear Address:segmentation 後、paging 前的 32-bit address。
LDT:process 私有 segments。
GDT:全系統共享 segments。
CR3:指向目前 process 的 page directory。
Page Directory:第一層 paging table。
Page Size Flag:設定後使用 4-MB page。
PAE:讓 32-bit processor 可用超過 4 GB physical memory。
PDPT:PAE 新增最上層表格。
PDE / PTE:Page Directory Entry / Page Table Entry,PAE 中變 64 bits。
x86-64:IA-32 的 64-bit 延伸。
PML4:x86-64 四層 paging 的最上層。

10.1~10.6 ​

以下整理 Chapter 10.1~10.6 Virtual Memory 的考古型名詞,格式照: 名詞(全稱):簡答題版本解釋敘述。 範圍依課本 Chapter 10 的 Background、Demand Paging、Copy-on-Write、Page Replacement、Allocation of Frames、Thrashing。

text
10.1 Background

Virtual Memory(虛擬記憶體):
Virtual memory 是一種讓 process 不必完全載入 physical memory 就能執行的技術。
它將使用者看到的 logical memory 與實際 physical memory 分離,使程式可以使用比實體記憶體更大的位址空間。

Virtual Address Space(虛擬位址空間):
Virtual address space 是 process 在執行時所看到的 logical address 範圍。
在 virtual memory 系統中,process 會認為自己擁有一段連續的記憶體空間,但實際上 pages 可能分散在 physical memory 或 backing store 中。

Sparse Address Space(稀疏位址空間):
Sparse address space 是指 process 的 virtual address space 很大,但實際使用到的區域很少且分散。
Virtual memory 可讓 OS 只為實際使用到的部分配置 physical memory。

Shared Pages(共享頁面):
Shared pages 是多個 processes 可以共同映射到同一份 physical memory 的 pages。
常用於 shared libraries 或 shared memory,可節省 physical memory。

Shared Library(共享函式庫):
Shared library 是可被多個 processes 共用的 library code。
透過 virtual memory,多個 processes 可以將同一份 library code 映射到自己的 address space 中,而不必各自保留一份完整 copy。

Memory-Mapped File(記憶體映射檔案):
Memory-mapped file 是將檔案內容映射到 process 的 virtual address space 中。
process 可以像存取 memory 一樣讀寫檔案內容,OS 會負責將 memory access 轉成檔案 I/O。
text
10.2 Demand Paging

Demand Paging(需求分頁):
Demand paging 是只在 page 被實際需要時,才將該 page 載入 main memory 的技術。
如果 process 存取的 page 不在 memory 中,就會產生 page fault,OS 再從 backing store 將該 page 載入。

Lazy Swapper(懶惰交換器):
Lazy swapper 是指不會一開始就把整個 process 載入 memory,而是只在需要時才載入 page 的機制。
在 demand paging 中,更精確地說應稱為 pager,因為它處理的是 page,不是整個 process。

Pager(分頁器):
Pager 是負責在 demand paging 中決定哪些 pages 需要載入 memory 的系統元件。
它只將真正需要的 pages 載入,而不是一次載入整個 process。

Backing Store(後備儲存區):
Backing store 是用來存放暫時不在 physical memory 中 pages 的 secondary storage。
當 page fault 發生時,OS 會從 backing store 將需要的 page 讀入 memory。

Valid-Invalid Bit(有效-無效位元):
Valid-invalid bit 是 page table entry 中用來表示 page 狀態的位元。
valid 表示該 page 在 process 的 logical address space 中且可合法存取;invalid 可能表示該 page 不合法,或目前尚未載入 memory。

Page Fault(分頁錯誤):
Page fault 是當 process 存取的 page 不在 physical memory 中時,由硬體產生的 trap。
OS 會檢查該 reference 是否合法,若合法就從 backing store 將 page 載入 free frame,更新 page table,然後重新執行被中斷的指令。

Pure Demand Paging(純需求分頁):
Pure demand paging 是一開始不載入任何 page,直到 process 第一次 reference 某個 page 時才載入。
因此 process 剛開始執行時可能連第一個 instruction 都會造成 page fault。

Effective Access Time, EAT(有效存取時間):
EAT 是考慮 page fault rate 後的平均記憶體存取時間。
Demand paging 的效能高度依賴 page fault rate;page fault rate 越高,effective access time 越長。

Page-Fault Rate(分頁錯誤率):
Page-fault rate 是 memory references 中造成 page fault 的比例。
在 demand paging 中,page-fault rate 會直接影響系統效能。

課本在 page fault 的處理流程中強調:page fault 需要 trap 到 OS、檢查 reference 合法性、從 secondary storage 讀入 page、更新 page table,最後重新啟動被中斷的指令;EAT 則會隨 page-fault rate 增加而明顯變差。

text
10.3 Copy-on-Write

Copy-on-Write, COW(寫入時複製):
Copy-on-write 是一種讓 parent process 與 child process 先共享相同 pages 的技術。
只有當其中一方要修改某個 shared page 時,OS 才會複製該 page,讓修改者擁有自己的 private copy。

Private Copy(私有副本):
Private copy 是在 copy-on-write 中,當 process 嘗試修改 shared page 時,OS 為該 process 建立的獨立 page。
如此可避免不必要的 page 複製,節省 memory 與 process creation time。

Zero-Fill-on-Demand Page(需求零填充分頁):
Zero-fill-on-demand page 是一種在需要時才配置且內容初始化為 0 的 page。
常用於 heap 或 stack 成長時,OS 不必事先配置所有 pages,而是在 page 被第一次存取時才建立。

vfork(Virtual-memory fork):
vfork 是 fork 的變形,建立 child process 時不複製 parent address space。
child 會暫時使用 parent 的 address space,通常用於 child 馬上呼叫 exec() 的情況,以減少建立 process 的成本。

課本總結中明確指出,copy-on-write 可讓 child process 先與 parent 共享 address space;若 parent 或 child 修改某個 page,才會建立該 page 的 copy。

text
10.4 Page Replacement

Page Replacement(頁面置換):
Page replacement 是當 page fault 發生且沒有 free frame 時,OS 必須選擇某個已在 memory 中的 page 移出,以便放入新的 page。
被選中的 page 稱為 victim page。

Victim Page(犧牲頁面):
Victim page 是 page replacement algorithm 選定要被換出的 page。
選擇 victim page 的目標是降低未來 page fault 次數。

Dirty Bit / Modify Bit(修改位元):
Dirty bit 又稱 modify bit,用來表示某個 page 自載入 memory 後是否被修改過。
若 dirty bit = 1,page 被 replacement 前必須寫回 disk;若 dirty bit = 0,可直接丟棄。

Reference String(參考字串):
Reference string 是 process 在執行期間產生的一串 page references。
它常用來分析不同 page replacement algorithms 會造成多少 page faults。

FIFO Page Replacement(First-In, First-Out Page Replacement):
FIFO page replacement 會淘汰最早進入 memory 的 page。
它實作簡單,但可能發生 Belady's anomaly。

Belady's Anomaly(Belady 異常):
Belady's anomaly 是指在某些 page replacement algorithms 中,分配更多 frames 反而造成更多 page faults 的異常現象。
此現象典型發生於 FIFO page replacement。

Optimal Page Replacement, OPT(最佳頁面置換):
Optimal page replacement 會淘汰未來最久不會再被使用的 page。
它能產生最低 page-fault rate,但需要知道未來 reference string,因此主要作為理論比較標準。

LRU Page Replacement(Least Recently Used Page Replacement,最近最少使用置換):
LRU page replacement 會淘汰最久沒有被使用的 page。
它利用過去的存取情形近似預測未來,但精確實作成本高。

Stack Algorithm(堆疊演算法):
Stack algorithm 是一類不會發生 Belady's anomaly 的 replacement algorithm。
其特性是給 n 個 frames 時的 pages 集合,一定包含在給 n+1 個 frames 時的 pages 集合中。

LRU Approximation Algorithm(LRU 近似演算法):
LRU approximation algorithm 是用硬體提供的 reference bit 等資訊近似 LRU。
因為純 LRU 實作成本太高,實務系統常使用近似版本。

Reference Bit(參考位元):
Reference bit 是用來記錄 page 最近是否被存取過的位元。
當 page 被存取時,硬體會將 reference bit 設為 1,OS 可利用它做 page replacement 判斷。

Additional-Reference-Bits Algorithm(額外參考位元演算法):
Additional-reference-bits algorithm 會定期記錄 reference bit 的歷史值,形成一串位元來近似 page 的近期使用情況。
位元值越小,通常代表該 page 越久沒有被使用。

Second-Chance Algorithm(二次機會演算法):
Second-chance algorithm 是 FIFO 的改良版。
若最舊 page 的 reference bit = 0,直接淘汰;若 reference bit = 1,將其清為 0 並給它第二次機會,再檢查下一個 page。

Clock Algorithm(時鐘演算法):
Clock algorithm 是 second-chance algorithm 的環狀佇列實作。
它用一個指標像時鐘指針一樣掃描 frames,根據 reference bit 決定是否淘汰 page。

Enhanced Second-Chance Algorithm(增強二次機會演算法):
Enhanced second-chance algorithm 同時使用 reference bit 與 dirty bit 選擇 victim page。
通常會優先淘汰最近未使用且未修改的 page,因為不需要寫回 disk。

Counting Algorithm(計數演算法):
Counting algorithm 會記錄每個 page 被 reference 的次數,並依次數選擇 victim page。
常見形式包含 LFU 與 MFU。

LFU Page Replacement(Least Frequently Used Page Replacement,最少使用次數置換):
LFU 會淘汰 reference count 最小的 page。
它假設使用次數少的 page 未來也較不重要。

MFU Page Replacement(Most Frequently Used Page Replacement,最多使用次數置換):
MFU 會淘汰 reference count 最大的 page。
它的想法是:使用次數很大的 page 可能已經完成主要用途,之後反而較少再用。

課本總結列出 FIFO、optimal、LRU 等 page-replacement algorithms,並指出純 LRU 難以實作,因此多數系統使用 LRU-approximation algorithms。

text
10.5 Allocation of Frames

Frame Allocation(頁框配置):
Frame allocation 是 OS 決定每個 process 可以分配到多少 physical frames 的問題。
分配太少會增加 page faults;分配太多則可能浪費 memory 並降低 multiprogramming。

Minimum Number of Frames(最小頁框數):
Minimum number of frames 是一個 process 能正常執行所需的最低 frames 數量。
此限制通常和 CPU instruction set 有關,因為一個 instruction 可能同時需要多個 pages。

Equal Allocation(平均配置):
Equal allocation 是將可用 frames 平均分配給所有 processes 的方法。
它簡單但不考慮 process 大小差異。

Proportional Allocation(比例配置):
Proportional allocation 是依照 process 大小比例分配 frames。
較大的 process 會獲得較多 frames,較小的 process 則獲得較少 frames。

Priority Allocation(優先權配置):
Priority allocation 是依照 process priority 分配 frames 的方法。
高優先權 process 可獲得較多 frames,或在 replacement 時從低優先權 process 中選擇 victim frame。

Global Replacement(全域置換):
Global replacement 允許 process 從全系統所有 frames 中選擇 victim frame。
因此一個 process 可能會拿走其他 process 的 frame,通常可提升 throughput,但各 process 的執行時間較不穩定。

Local Replacement(區域置換):
Local replacement 限制 process 只能從自己已分配的 frames 中選擇 victim frame。
它可讓每個 process 的效能較穩定,但可能導致 memory 使用不夠彈性。

NUMA(Non-Uniform Memory Access,非一致性記憶體存取):
NUMA 是一種多處理器記憶體架構,不同 CPU 存取不同區域 memory 的速度不一定相同。
OS 在分配 memory 時應盡量將 memory 配置在靠近執行該 thread 的 CPU,以降低 memory access latency。

講義在 frame allocation 部分列出 equal allocation、proportional allocation、priority allocation、global replacement、local replacement 與 NUMA,並說明 global replacement 可從所有 frames 選 victim,local replacement 則只能從該 process 自己的 frames 選。

text
10.6 Thrashing

Thrashing(抖動 / 顛簸):
Thrashing 是系統花大量時間在 paging,而不是執行 process 指令的狀態。
通常是因為 process 沒有足夠 frames,導致 page-fault rate 非常高,一直把 pages 換入換出。

Degree of Multiprogramming(多工程度):
Degree of multiprogramming 是系統中同時存在於 memory、可競爭 CPU 的 processes 數量。
若 degree of multiprogramming 過高,每個 process 分到的 frames 可能太少,容易造成 thrashing。

Locality of Reference(參考區域性):
Locality of reference 是指程式在某段時間內傾向重複存取相同或相近的 pages。
Virtual memory、cache、working set 等機制都依賴 locality 才能有效運作。

Locality(區域集合):
Locality 是 process 在某段執行階段中會密集使用的一組 pages。
程式執行時會在不同 localities 之間移動。

Working Set(工作集合):
Working set 是 process 在最近一段時間內實際使用到的 pages 集合。
它用來近似 process 目前的 locality,OS 可根據 working set 判斷 process 需要多少 frames。

Working-Set Window(工作集合視窗):
Working-set window 是用來觀察最近 page references 的時間或 reference 數量範圍,通常記為 Δ。
OS 會用最近 Δ 次 references 中出現的 pages 估計 working set。

Working-Set Size, WSS(工作集合大小):
WSS 是某個 process 的 working set 中 pages 的數量。
若 OS 分配給 process 的 frames 少於 WSS,該 process 很可能產生大量 page faults。

Total Demand, D(總需求頁框數):
Total demand 是系統中所有 processes 的 working-set sizes 總和。
若 D 大於 available frames,系統可能發生 thrashing,OS 需要降低 degree of multiprogramming。

Page-Fault Frequency, PFF(分頁錯誤頻率):
PFF 是利用 page-fault rate 控制 frame allocation 的方法。
若 page-fault rate 太高,代表 process 需要更多 frames;若太低,代表可能可回收部分 frames。

Swapping Pages In and Out(頁面換入換出):
Swapping pages in and out 是指 OS 不斷將 pages 從 backing store 載入 memory,或將 memory 中的 pages 寫回 backing store。
Thrashing 發生時,系統會過度進行這種動作,導致 CPU utilization 降低。

課本總結指出:thrashing 是系統花在 paging 的時間多於真正執行的時間;locality 是一組會被一起活躍使用的 pages,而 working set 是根據 locality 定義、表示 process 目前正在使用的 pages 集合。

text
10.1~10.6 最容易考的速背版

Virtual Memory:讓 process 不必全部載入 physical memory 也能執行。
Demand Paging:page 用到才載入,沒用到先不載。
Page Fault:存取的 page 不在 memory,trap 到 OS 處理。
Backing Store:存放不在 memory 中 pages 的 secondary storage。
Copy-on-Write:先共享 page,寫入時才複製。
Dirty Bit:page 被改過,replacement 前要寫回 disk。
FIFO:淘汰最早進入 memory 的 page。
Belady's Anomaly:frames 變多,page faults 反而變多。
OPT:淘汰未來最久不用的 page,理論最佳。
LRU:淘汰最久沒用過的 page。
Second Chance:reference bit = 1 給第二次機會,= 0 淘汰。
Clock Algorithm:second chance 的環狀實作。
Global Replacement:可從所有 processes 的 frames 選 victim。
Local Replacement:只能從自己 process 的 frames 選 victim。
Thrashing:一直 page fault,一直換頁,CPU 幾乎沒做正事。
Working Set:最近正在使用的 pages 集合。
PFF:用 page-fault rate 控制 frame allocation。
NUMA:不同 CPU 存取不同 memory 區域速度不同。

11.1~11.4 11.7~11.8 ​

可以,這次照前面喜歡的格式整理: 名詞(全稱放旁邊):簡答題版本解釋敘述。 範圍是 11.1~11.4、11.7~11.8,也就是 Mass-Storage、Disk/NVM scheduling、錯誤偵測、更後面的 Storage attachment 與 RAID。課本 Sample 裡已經出現 SAN、NAS、ECC、RAID、SCAN 這些名詞,代表這幾節超容易考。

text
11.1 Overview of Mass-Storage Structure

HDD(Hard-Disk Drive,硬碟機):
HDD 是使用旋轉磁盤與磁頭來儲存資料的 secondary storage device。
因為它有機械移動,所以存取時間主要受到 seek time 與 rotational latency 影響。

NVM(Nonvolatile Memory,非揮發性記憶體):
NVM 是斷電後仍能保留資料的記憶體型儲存裝置,例如 flash memory 與 SSD。
相較 HDD,NVM 沒有磁頭移動與旋轉延遲,但有抹除、寫入壽命與控制器管理問題。

SSD(Solid-State Drive,固態硬碟):
SSD 是以 NVM,通常是 NAND flash,實作的儲存裝置。
它沒有 HDD 的機械式 seek time 與 rotational latency,因此隨機存取通常比 HDD 快。

NAND Flash Memory(NAND 快閃記憶體):
NAND flash memory 是 SSD 常用的非揮發性儲存媒體。
其特性是已寫入的 page 不能直接覆寫,通常必須先 erase block 後才能重新寫入。

Sector(磁區):
sector 是磁碟上可定位與傳輸資料的基本實體區塊。
傳統磁碟會把 track 切成多個 sectors,OS 或磁碟控制器會將 logical blocks 對應到 sectors。

Track(磁軌):
track 是磁碟盤面上的同心圓軌道。
資料會沿著 track 被切成多個 sectors 儲存。

Cylinder(磁柱):
cylinder 是多個磁碟盤面上,半徑相同的一組 tracks。
磁頭若停在某個 cylinder,就可以切換不同盤面上的 track,而不必移動磁臂。

Seek Time(尋道時間):
seek time 是磁碟臂將磁頭移動到目標 cylinder 所需的時間。
在 HDD 中,seek time 是影響 access time 的主要因素之一。

Rotational Latency(旋轉延遲):
rotational latency 是磁頭到達正確 track 後,等待目標 sector 旋轉到磁頭下方的時間。
它是 HDD access time 的另一個主要組成。

Access Time(存取時間):
access time 是從發出 I/O request 到開始取得所需資料之間的時間。
對 HDD 而言,主要由 seek time 與 rotational latency 組成。

Transfer Rate(傳輸率):
transfer rate 是資料真正從儲存裝置傳到主機,或從主機寫入儲存裝置的速率。
它描述的是資料搬移速度,不是定位資料的位置所需時間。

Device Bandwidth(裝置頻寬):
device bandwidth 是一段時間內完成傳輸的總 bytes 數除以總服務時間。
OS 可透過安排 I/O request 順序,提高整體頻寬。

Logical Block(邏輯區塊):
logical block 是 OS 看到的磁碟資料傳輸最小單位。
OS 通常把磁碟視為一個連續的 logical block array,而不是直接操作 cylinder、track、sector。

LBA(Logical Block Addressing,邏輯區塊定址):
LBA 是用連續 logical block number 來定址磁碟資料的方法。
OS 發出 I/O request 時通常指定 logical block number,底層再由裝置控制器映射到實體位置。

Low-Level Formatting(低階格式化):
low-level formatting 是在實體媒體上建立 sectors 或 logical blocks 的程序。
它讓儲存裝置能以固定區塊為單位進行讀寫。

FTL(Flash Translation Layer,快閃轉譯層):
FTL 是 flash/NVM controller 用來維護 logical blocks 到 physical pages 對應關係的表格。
因為 NAND flash 不能直接覆寫,所以 FTL 需要追蹤哪個 physical page 存著目前有效的 logical block。:contentReference[oaicite:1]{index=1}

Invalid Page(無效頁):
invalid page 是 NAND flash 中已經不再代表最新資料的舊 page。
當同一個 logical block 被重新寫入時,舊 physical page 會變成 invalid,新 page 才存放最新資料。

Garbage Collection(垃圾回收):
garbage collection 是 SSD/NVM controller 將仍有效資料搬到其他位置,並清除含有無效資料 blocks 的程序。
其目的,是釋放可重新寫入的 erased blocks。

Over-Provisioning(預留空間):
over-provisioning 是 SSD/NVM 裝置預留一部分實體空間,不直接給使用者使用。
它可提供寫入緩衝、幫助 garbage collection,並改善寫入效能與壽命。:contentReference[oaicite:2]{index=2}

Wear Leveling(磨耗平均):
wear leveling 是 SSD controller 將 erase/write 次數平均分散到不同 blocks 的技術。
其目的是避免少數 blocks 過度磨損,延長整個 NVM 裝置壽命。:contentReference[oaicite:3]{index=3}
text
11.2 HDD Scheduling

HDD Scheduling(Hard-Disk Drive Scheduling,硬碟排程):
HDD scheduling 是 OS 或 device driver 安排磁碟 I/O request 服務順序的技術。
目的在於減少不必要的磁頭移動、降低 access time,並提升 disk bandwidth。課本指出 HDD 效能主要受到 seek time、rotational latency 與 request ordering 影響。:contentReference[oaicite:4]{index=4}

Disk Queue(磁碟佇列):
disk queue 是當磁碟或 controller 忙碌時,用來存放 pending I/O requests 的佇列。
disk scheduling algorithm 會根據此佇列決定下一個要服務的 request。

FCFS Scheduling(First-Come, First-Served Scheduling,先來先服務排程):
FCFS 是最簡單的 disk scheduling algorithm。
它依照 I/O request 到達順序服務,優點是公平且容易實作,缺點是可能造成大量磁頭移動,效能不一定好。

FIFO(First-In, First-Out,先進先出):
FIFO 是 FCFS 的佇列實作概念。
先進入 disk queue 的 request 會先被服務。

SCAN Algorithm(SCAN Algorithm,掃描演算法 / 電梯演算法):
SCAN 是一種 disk scheduling algorithm。
磁頭會從磁碟一端往另一端移動,沿路服務遇到的 requests,到端點後再反向移動。
它比 FCFS 更能降低來回大幅移動,也比較不容易讓某些 requests 長期飢餓。

Elevator Algorithm(電梯演算法):
elevator algorithm 是 SCAN 的別名。
因為磁頭移動方式像電梯一樣,一路往某方向服務請求,到端點後再反向。

C-SCAN(Circular SCAN,循環掃描演算法):
C-SCAN 是 SCAN 的變形。
磁頭只在一個方向上服務 requests,移到端點後直接回到另一端,再重新同方向掃描。
它讓等待時間分布更均勻。

Sequential I/O(循序 I/O):
sequential I/O 是資料位置連續或相近的 I/O 存取型態。
HDD 對 sequential I/O 的效能通常較好,因此 scheduling 會盡量把相鄰 requests 聚集處理。

Request Ordering(請求排序):
request ordering 是重新安排 I/O requests 服務順序的技術。
對 HDD 而言,好的排序可以減少 seek time、提升整體 disk bandwidth。
text
11.3 NVM Scheduling

NVM Scheduling(Nonvolatile Memory Scheduling,非揮發性記憶體排程):
NVM scheduling 是針對 SSD/NVM 裝置安排 I/O requests 的策略。
因為 NVM 沒有磁頭與旋轉磁盤,所以不需要像 HDD 那樣主要為了減少 seek time 排程;但仍可能根據 controller 特性、讀寫差異與佇列狀態調整 I/O 順序。

No Seek Time(無尋道時間):
NVM/SSD 沒有機械磁頭移動,所以沒有傳統 HDD 的 seek time。
因此 HDD 的磁頭移動最佳化策略不一定適用於 NVM。

No Rotational Latency(無旋轉延遲):
NVM/SSD 沒有旋轉磁盤,所以也沒有 rotational latency。
這使得隨機讀取成本通常比 HDD 低很多。

Read/Write Asymmetry(讀寫不對稱):
NVM 的讀取與寫入成本可能不同。
特別是 flash memory 通常寫入與 erase 比讀取更複雜,因此排程與 controller 需要考慮寫入放大、erase block、garbage collection 等問題。

Controller Algorithm(控制器演算法):
controller algorithm 是 SSD/NVM controller 內部負責 mapping、garbage collection、wear leveling、error correction 等工作的演算法。
NVM 裝置的實際效能不只由 OS scheduling 決定,也受到 controller algorithm 強烈影響。:contentReference[oaicite:5]{index=5}

TRIM(TRIM Command,修剪指令):
TRIM 是 OS 通知 SSD 哪些 logical blocks 已經不再使用的指令。
SSD controller 可利用此資訊提早回收 blocks,改善 garbage collection 與寫入效能。
text
11.4 Error Detection and Correction

Error Detection(錯誤偵測):
error detection 是判斷儲存資料是否在讀寫或保存過程中發生錯誤的技術。
儲存裝置通常會在資料旁存放額外檢查資訊,用來偵測 bit 是否損壞。

Error Correction(錯誤修正):
error correction 是在偵測到錯誤後,利用額外資訊修正錯誤資料的技術。
相較於只知道資料錯了,error correction 可在錯誤數量可處理時恢復正確資料。

ECC(Error-Correcting Code,錯誤修正碼):
ECC 是儲存裝置用來偵測並嘗試修正資料錯誤的額外編碼資訊。
資料寫入時會一起計算並存放 ECC;讀取時再用 ECC 檢查資料是否錯誤,必要時修正。Sample 第一大題也直接考 ECC 全稱。:contentReference[oaicite:6]{index=6}

Correctable Error(可修正錯誤):
correctable error 是可由 ECC 或其他錯誤修正機制修復的錯誤。
若某個 page 經常出現 correctable errors,裝置可能會將它標記為 bad,不再使用。:contentReference[oaicite:7]{index=7}

Uncorrectable Error(不可修正錯誤):
uncorrectable error 是超出 ECC 修正能力的錯誤。
此時裝置可能回報 I/O error,OS 或 RAID 才需要透過其他冗餘機制嘗試復原資料。

Bad Block / Bad Sector(壞區塊 / 壞磁區):
bad block 或 bad sector 是儲存媒體中無法可靠保存資料的位置。
磁碟或 SSD controller 可能會將其標記為不可用,並重新映射到 spare area。

Data Corruption(資料毀損):
data corruption 是資料內容因硬體故障、bit error、控制器錯誤或其他原因而變得不正確。
ECC、RAID、replication 等技術都可用來降低資料毀損造成的損害。
text
11.7 Storage Attachment

Storage Attachment(儲存裝置連接方式):
storage attachment 是主機連接 secondary storage 的方式。
課本將其分成 host-attached storage、network-attached storage 與 cloud storage 三種。:contentReference[oaicite:8]{index=8}

Host-Attached Storage(主機直連式儲存):
host-attached storage 是透過本機 I/O ports 直接連到主機的儲存裝置。
常見例子包含 SATA、USB、Thunderbolt 或 Fibre Channel 連接的裝置。:contentReference[oaicite:9]{index=9}

SATA(Serial ATA,序列 ATA):
SATA 是常見的本機儲存裝置連接介面。
一般 PC 常用 SATA 連接 HDD 或 SSD。

FC(Fibre Channel,光纖通道):
FC 是高速序列式儲存連接架構,可透過光纖或銅線傳輸。
它常用於高階伺服器與 storage-area network,讓多個 hosts 與 storage devices 接到同一個 fabric。:contentReference[oaicite:10]{index=10}

Fabric(交換式結構):
fabric 是由交換器連接多個 hosts 與 storage devices 的儲存網路結構。
它讓多台主機和多個儲存設備可以彈性連接與存取。

NAS(Network-Attached Storage,網路附加儲存):
NAS 是透過一般網路提供檔案存取的儲存系統。
NAS 可以是專用儲存設備,也可以是提供儲存服務的電腦;client 通常透過 NFS 或 CIFS/SMB 等 RPC-based 協定存取。:contentReference[oaicite:11]{index=11}

NFS(Network File System,網路檔案系統):
NFS 是 UNIX/Linux 常用的 network file access protocol。
它讓 client 可以透過網路存取遠端 NAS 上的檔案,就像存取本機檔案一樣。

CIFS(Common Internet File System,通用網際網路檔案系統):
CIFS 是 Windows 系統常用的 network file access protocol。
它讓 Windows client 能透過網路共享與存取遠端檔案。

RPC(Remote Procedure Call,遠端程序呼叫):
RPC 是讓 client 像呼叫本機函式一樣呼叫 server 端服務的機制。
NAS 的 NFS/CIFS 操作可透過 RPC 在網路上傳送。

SAN(Storage-Area Network,儲存區域網路):
SAN 是使用儲存協定的 private network,用來連接 servers 與 storage units。
它的重點是讓多台 hosts 與多個 storage arrays 可透過專用儲存網路彈性連接。:contentReference[oaicite:12]{index=12}

Storage Array(儲存陣列):
storage array 是專門設計的儲存設備,內含多個 drives、controller、SAN ports 或 network ports。
它可以提供 RAID、snapshots、replication、compression、deduplication、encryption 等功能。:contentReference[oaicite:13]{index=13}

JBOD(Just a Bunch of Disks,一堆磁碟):
JBOD 是沒有 RAID 保護或特殊冗餘設計的一組磁碟。
在 SAN 或 storage array 中,某些 storage units 可能只是 JBOD,也可能有 RAID protection。

Cloud Storage(雲端儲存):
cloud storage 是透過網際網路存取遠端資料中心儲存資源的方式。
相較 NAS 常用於 LAN,cloud storage 更可能面對 WAN 延遲、斷線與應用層暫停存取等問題。
text
11.8 RAID Structure

RAID(Redundant Array of Independent Disks,獨立磁碟冗餘陣列):
RAID 是將多個 drives 組合成一個邏輯儲存系統的技術。
其目的通常是透過 parallelism 提升效能,並透過 redundancy 提高可靠性。Sample 第一大題也直接考 RAID 全稱。:contentReference[oaicite:14]{index=14}

Reliability(可靠度):
reliability 是系統能持續正確運作、不發生資料遺失或服務中斷的能力。
RAID 透過 mirroring 或 parity 提升 storage reliability。

MTTF(Mean Time To Failure,平均故障時間):
MTTF 是某個裝置平均多久會發生故障的時間。
在多顆磁碟陣列中,任一顆磁碟故障的平均時間會比單顆磁碟短,因為磁碟數量越多,發生某顆故障的機率越高。

MTBF(Mean Time Between Failures,平均故障間隔時間):
MTBF 是可修復系統中,兩次故障之間的平均時間。
在儲存系統可靠度討論中,常用來評估 RAID 或磁碟系統的可靠性。

Mirroring(鏡像):
mirroring 是把同一份資料寫到兩顆或多顆 drives 上。
若其中一顆 drive 故障,仍可從另一份 copy 讀取資料,因此可提升可靠性與讀取可用性。

Striping(資料分散 / 條帶化):
striping 是將資料切分並分散寫到多顆 drives 上。
它可讓多顆 drives 平行讀寫,提高傳輸率,但單獨 striping 不提供冗餘保護。課本指出 striping 可提升多個小存取的 throughput 與大型存取的 response time。:contentReference[oaicite:15]{index=15}

Bit-Level Striping(位元層級條帶化):
bit-level striping 是將每個 byte 的不同 bits 分散到不同 drives 上。
它可提升單次存取的資料量,但每次存取通常需要所有 drives 共同參與。

Block-Level Striping(區塊層級條帶化):
block-level striping 是將不同 blocks 分散到多顆 drives 上。
例如 n 顆 drives 時,block i 可放到 drive (i mod n)+1;這是實務上常見的 striping 型態。:contentReference[oaicite:16]{index=16}

Redundancy(冗餘):
redundancy 是為了容錯而額外保存的資料或資訊。
RAID 可用 mirroring 或 parity 形成 redundancy,使某顆 drive 故障時仍能復原資料。

Parity(奇偶校驗):
parity 是由多個 data blocks 計算出的冗餘資訊,常用 XOR 產生。
當其中一個 data block 遺失時,可用剩餘 data blocks 和 parity 重建遺失資料。課本 RAID 4 說明中也提到可利用 parity recalculates bad data。:contentReference[oaicite:17]{index=17}

XOR(Exclusive OR,互斥或):
XOR 是 parity RAID 常用的位元運算。
其特性是只要知道 parity 和其他資料 blocks,就能反推出缺失的 block。

RAID Level 0(RAID 0):
RAID 0 是只有 striping、沒有 redundancy 的 RAID level。
它效能高,但任一 drive 故障都可能造成資料遺失,因此可靠度低。:contentReference[oaicite:18]{index=18}

RAID Level 1(RAID 1):
RAID 1 是 mirroring。
資料會完整複製到另一顆 drive,因此可靠度高、復原快,但儲存空間成本高。:contentReference[oaicite:19]{index=19}

RAID Level 4(RAID 4):
RAID 4 使用 block-level striping,並用一顆 dedicated parity drive 存放 parity。
它可在單顆 drive 故障時用 parity 重建資料,但 parity drive 可能成為寫入瓶頸。

Read-Modify-Write Cycle(讀取-修改-寫回循環):
read-modify-write cycle 是 parity RAID 小型寫入時常見的流程。
因為更新資料 block 時也要更新 parity,所以通常要讀 old data 與 old parity,再寫 new data 與 new parity。課本指出小型寫入可能需要四次 drive accesses。:contentReference[oaicite:20]{index=20}

RAID Level 5(RAID 5):
RAID 5 是 block-interleaved distributed parity。
它不像 RAID 4 固定一顆 parity drive,而是將 data 與 parity 分散在所有 drives 上,以減少單一 parity drive 瓶頸。:contentReference[oaicite:21]{index=21}

Distributed Parity(分散式奇偶校驗):
distributed parity 是將 parity blocks 分散到多顆 drives,而不是固定存在某一顆 drive。
RAID 5 使用 distributed parity 來改善 RAID 4 的 parity drive 瓶頸。

RAID Level 6(RAID 6):
RAID 6 使用額外的冗餘資訊,使系統可容忍兩顆 drives 故障。
它比 RAID 5 可靠,但需要更多冗餘空間與計算成本。

RAID 0+1(RAID 0 plus RAID 1):
RAID 0+1 是先做 striping,再將整組 stripe 做 mirroring。
它結合 RAID 0 的效能與 RAID 1 的可靠性,但空間成本高。:contentReference[oaicite:22]{index=22}

RAID 1+0 / RAID 10(RAID 1 plus RAID 0):
RAID 1+0 是先將 drives 成對 mirroring,再對 mirrored pairs 做 striping。
它通常比 RAID 0+1 在單顆 drive failure 時更有彈性。:contentReference[oaicite:23]{index=23}

Hot Spare(熱備援磁碟):
hot spare 是平常不存放資料、但已配置好等待故障時接手的備用 drive。
當 RAID 中某顆 drive 故障時,hot spare 可自動用來 rebuild,使 RAID 保護層級盡快恢復。:contentReference[oaicite:24]{index=24}

Rebuild(重建):
rebuild 是在 drive 故障並更換或啟用 hot spare 後,利用 mirror copy 或 parity 重新建立遺失資料的程序。
RAID 1 重建通常較簡單,RAID 5/6 則可能需要讀取其他多顆 drives,時間較長。:contentReference[oaicite:25]{index=25}

Snapshot(快照):
snapshot 是某個時間點檔案系統或儲存 volume 的視圖。
它可用於備份、還原或建立一致性資料版本;課本提到 storage array 或 RAID 層級也可能提供此功能。:contentReference[oaicite:26]{index=26}

Replication(複寫):
replication 是將寫入自動複製到不同位置或不同 storage site 的技術。
它可提供 redundancy 與 disaster recovery,也可增加讀取效能。:contentReference[oaicite:27]{index=27}

Synchronous Replication(同步複寫):
synchronous replication 要求資料同時寫入本地與遠端後,才算 write complete。
它資料一致性較強,但延遲較高,距離限制也較明顯。

Asynchronous Replication(非同步複寫):
asynchronous replication 會將寫入先群組起來,之後週期性寫到遠端。
它較快、距離限制較小,但 primary site 故障時可能遺失尚未複寫的資料。:contentReference[oaicite:28]{index=28}
text
最後速背版

11.1:
HDD:機械式磁碟,受 seek time 和 rotational latency 影響。
NVM / SSD:非揮發性、無機械延遲,但有 erase、GC、wear leveling 問題。
Logical Block / LBA:OS 以連續 logical block number 存取磁碟。
FTL:SSD controller 的 logical-to-physical mapping 表。
Garbage Collection:搬移有效資料、清出可 erase blocks。
Over-Provisioning:SSD 預留空間改善寫入與壽命。
Wear Leveling:平均分散 erase/write 次數。

11.2:
FCFS:依 request 到達順序服務,公平但可能磁頭移動大。
SCAN:電梯演算法,往一方向掃,沿路服務,到端點再反向。
C-SCAN:只單方向服務,到端點後回另一端重新掃。
Disk Scheduling:重排 I/O requests 以降低 access time、提高 bandwidth。

11.3:
NVM Scheduling:不需為 seek time 排程,但仍要考慮 controller、讀寫差異、GC。
TRIM:OS 告訴 SSD 哪些 blocks 不再使用。

11.4:
ECC:Error-Correcting Code,用來偵測並修正資料錯誤。
Bad Block / Bad Sector:不可靠的儲存位置,需要標記或重新映射。

11.7:
Host-Attached Storage:本機 I/O port 直接連 storage。
NAS:Network-Attached Storage,用一般網路提供檔案層級存取。
SAN:Storage-Area Network,專用儲存網路連接 servers 和 storage units。
FC:Fibre Channel,常見 SAN 高速連接技術。
Storage Array:含多顆 drives 和 controller 的專用儲存設備。

11.8:
RAID:多顆磁碟組成陣列,提升效能與可靠度。
Striping:資料分散到多顆 disks,提高效能。
Mirroring:資料複製到另一顆 disk,提高可靠度。
Parity:用 XOR 產生冗餘資訊,可重建遺失資料。
RAID 0:striping only,快但無容錯。
RAID 1:mirroring,可靠但成本高。
RAID 4:dedicated parity disk。
RAID 5:distributed parity。
RAID 6:可容忍兩顆 disk failure。
Hot Spare:故障時自動接手的備援磁碟。
Rebuild:用 mirror/parity 重建故障磁碟資料。

12.4 ​

可以,12.4 這節是 Kernel I/O Subsystem,主軸是:Kernel 幫 I/O 做排程、緩衝、快取、spooling、錯誤處理、保護、資料結構管理與電源管理。 課本開頭直接列出 kernel I/O subsystem 提供 scheduling、buffering、caching、spooling、device reservation、error handling,也負責保護自己免於錯誤 process 或惡意使用者破壞。

text
12.4 Kernel I/O Subsystem

Kernel I/O Subsystem(核心 I/O 子系統):
Kernel I/O subsystem 是作業系統核心中負責管理 I/O 的部分。
它提供 I/O scheduling、buffering、caching、spooling、device reservation、
error handling、I/O protection、kernel data structures 與 power management 等功能。
其目的,是讓不同 I/O devices 能被安全、有效率且一致地使用。

I/O Scheduling(I/O 排程):
I/O scheduling 是決定多個 I/O requests 執行順序的機制。
OS 會重新排列 requests 的服務順序,以提升整體效能、降低平均等待時間,
並讓不同 processes 能較公平地共享 device access。

Wait Queue(等待佇列):
wait queue 是每個 I/O device 用來存放 pending I/O requests 的佇列。
當 process 發出 blocking I/O system call 時,該 request 會被放入對應 device 的 wait queue,
再由 I/O scheduler 決定服務順序。

Device-Status Table(裝置狀態表):
device-status table 是 kernel 用來追蹤 I/O devices 狀態的資料結構。
每個 table entry 會記錄某個 device 的 type、address、state,
例如 not functioning、idle 或 busy;若 device 正忙,也會記錄目前 request 的相關資訊。

Asynchronous I/O Tracking(非同步 I/O 追蹤):
當 kernel 支援 asynchronous I/O 時,必須同時追蹤許多尚未完成的 I/O requests。
OS 可透過 device-status table 與 wait queues 記錄每個 device 的狀態與 pending requests。

課本說,I/O scheduling 的本質是決定一組 I/O requests 的良好執行順序;實作上 OS 會為每個 device 維護 wait queue,並可把 wait queue 接到 device-status table 上,表中記錄 device type、address、state 與目前 request。

text
12.4.2 Buffering

Buffer(緩衝區):
buffer 是一塊 memory area,用來暫時存放正在 device 與 application 之間,
或兩個 devices 之間傳輸的資料。
buffering 的目的,是處理速度不匹配、資料傳輸大小不匹配,
以及維持 copy semantics。

Buffering(緩衝):
buffering 是利用 buffer 暫存 I/O 資料的技術。
它主要有三個目的:
第一,處理 producer 與 consumer 速度不一致;
第二,處理 devices 之間 transfer size 不一致;
第三,保證 application copy semantics。

Speed Mismatch(速度不匹配):
speed mismatch 是指資料來源與資料接收者速度不同。
例如 network 速度比 SSD 慢很多,OS 會先用 buffer 累積資料,
再一次寫入 storage,以減少低效率的小量 I/O。

Double Buffering(雙緩衝):
double buffering 是使用兩個 buffers 交替傳輸資料。
當第一個 buffer 被某個 device 處理時,另一個 buffer 可以繼續接收新資料,
以減少等待並提高 I/O throughput。

Transfer-Size Mismatch(傳輸大小不匹配):
transfer-size mismatch 是指兩個 device 或 software layer 使用的資料單位大小不同。
buffer 可以累積或切分資料,使不同單位大小的 I/O 能順利銜接。

Copy Semantics(複製語意):
copy semantics 是指 system call 發生時,OS 必須保證它處理的是當時傳入資料的內容,
而不會受到 application 後續修改 user buffer 的影響。
OS 可透過把資料複製到 kernel buffer,確保 I/O 操作使用的是正確版本。

課本定義 buffer 是用來保存兩個 devices 或 device 與 application 間正在傳輸資料的 memory area;buffering 有三個理由:處理速度不匹配、transfer size 不匹配、以及支援 copy semantics。

text
12.4.3 Caching

Cache(快取):
cache 是保存資料副本的高速儲存區。
若之後再次需要同一份資料,系統可以直接從 cache 讀取,
避免重新進行較慢的 device I/O。

Caching(快取):
caching 是把常用資料的 copy 放在較快 storage 中的技術。
在 I/O subsystem 中,caching 可以減少實體 disk I/O,
提升 shared files 或短時間重複讀寫資料的效率。

Buffer Cache(緩衝快取):
buffer cache 是 kernel 使用 main memory buffers 來保存 disk data 的區域。
它同時可作為 buffer 與 cache:既可暫存正在傳輸的資料,
也可保存 disk blocks 的 copy,讓後續 I/O 可避免或延後真正的 disk access。

Buffer vs. Cache(緩衝區與快取差異):
buffer 可能保存某個 data item 的唯一 copy;
cache 則一定是保存某個存在於其他地方資料的 copy。
因此 buffer 強調資料傳輸過程中的暫存,cache 強調重複使用與加速。

課本很愛考這個差異:buffer 可能是某資料唯一存在的 copy;cache 則是較快 storage 上的副本。同時,實務上同一塊 memory 可以兼具 buffering 與 caching,例如 buffer cache 可避免或延後 physical disk I/O。

text
12.4.4 Spooling and Device Reservation

Spool(Simultaneous Peripheral Operations On-Line / 排存):
spool 是一種 buffer,用來保存某個不能接受 interleaved data streams 的 device 的輸出資料。
典型例子是 printer;多個 applications 可以同時送出列印工作,
但 OS 會先把每個 job 的輸出存成 spool file,再一個一個送到 printer。

Spooling(排存):
spooling 是 OS 攔截多個 applications 對某個 device 的輸出,
先分別存成 secondary storage 上的 spool files,
再依序送給該 device 處理的機制。
它常用於 printer 這類一次只能處理一個 job 的 device。

Spool File(排存檔案):
spool file 是 spooling system 為某個 application 的輸出建立的暫存檔。
當 application 完成輸出後,該 spool file 會被排入 queue,
等待 spooling system 依序送到 device。

Print Queue(列印佇列):
print queue 是保存等待列印 spool files 的 queue。
使用者或系統管理員通常可以查看 queue、刪除工作、暫停列印或恢復列印。

Device Reservation(裝置保留):
device reservation 是讓 process 對某個 device 取得 exclusive access 的機制。
某些 devices 不能合理地同時服務多個 applications,例如 tape drive 或 printer,
因此 OS 可提供 allocate / deallocate device 的機制,避免輸出混雜或互相干擾。

Exclusive Device Access(獨占式裝置存取):
exclusive device access 是指同一時間只允許一個 process 或 thread 使用某個 device。
這可防止多個 concurrent applications 同時操作不能共享的 device。

Sample 題目也有考 spool 名詞,這個超重要。課本定義 spool 是保存輸出給不能接受 interleaved data streams 的 device 的 buffer,例如 printer;OS 會把每個 application 的輸出存到不同 spool file,再一個一個送到 printer。

text
12.4.5 Error Handling

Error Handling(錯誤處理):
error handling 是 OS 在 I/O device 或 I/O transfer 發生錯誤時進行偵測、回報與復原的機制。
OS 通常可以處理暫時性錯誤,例如 read retry 或 network resend;
但若重要硬體永久故障,OS 通常無法完全復原。

Transient Failure(暫時性故障):
transient failure 是短暫且可能可恢復的 I/O 錯誤。
例如 network overload 或 disk read 暫時失敗。
OS 通常可透過 retry 或 resend 補救。

Permanent Failure(永久性故障):
permanent failure 是硬體元件真正故障或長期不可用的錯誤。
例如 disk controller 壞掉。
這類錯誤通常無法單靠 OS 重試完全恢復。

Retry(重試):
retry 是 OS 在某些 I/O operation 失敗後重新嘗試該操作的錯誤處理方式。
例如 disk read 失敗時,OS 可以再次 read,以處理暫時性錯誤。

errno(Error Number,錯誤碼變數):
errno 是 UNIX 中用來回傳 system call 失敗原因的整數變數。
I/O system call 通常只回傳 success 或 failure,
而 errno 會進一步表示錯誤類型,例如 argument out of range、bad pointer、file not open。

SCSI Sense Key(SCSI 感知鍵):
sense key 是 SCSI protocol 回報錯誤時的第一層資訊,
用來描述錯誤的一般種類,例如 hardware error 或 illegal request。

Additional Sense Code(額外感知碼):
additional sense code 是 SCSI protocol 回報錯誤時的第二層資訊,
用來描述更具體的錯誤類別,例如 bad command parameter 或 self-test failure。

Additional Sense-Code Qualifier(額外感知碼限定值):
additional sense-code qualifier 是 SCSI protocol 回報錯誤時更細節的第三層資訊。
它可指出更精確的錯誤位置或失敗子系統。

課本說 OS 對 transient failures 通常可以補救,例如 disk read() failure 會 retry、network send() error 可 resend;UNIX 用 errno 回傳錯誤碼,而 SCSI 可提供 sense key、additional sense code、additional sense-code qualifier 三層錯誤細節。

text
12.4.6 I/O Protection

I/O Protection(I/O 保護):
I/O protection 是防止 user process 直接執行非法 I/O instructions 或破壞 I/O devices 的機制。
OS 會將所有 I/O instructions 定義為 privileged instructions,
使 user process 必須透過 system call 請 OS 代為執行 I/O。

Privileged Instruction(特權指令):
privileged instruction 是只有 kernel mode 才能執行的指令。
I/O instructions 通常屬於 privileged instructions,
所以 user mode 程式不能直接操作 device controller 或 I/O ports。

System Call for I/O(I/O 系統呼叫):
user program 若要做 I/O,必須透過 system call 向 OS 發出 request。
OS 進入 kernel mode 後,會檢查 request 是否合法;
若合法,OS 才執行實際 I/O,完成後再回到 user mode。

Memory-Mapped I/O Protection(記憶體映射 I/O 保護):
memory-mapped I/O protection 是用 memory-protection system
保護 memory-mapped device registers 或 I/O port memory locations,
避免 user process 直接存取不該碰的 I/O 區域。

Locking Mechanism for Graphics Memory(圖形記憶體鎖定機制):
某些 graphics 或 video applications 需要直接存取 memory-mapped graphics controller memory。
kernel 可提供 locking mechanism,使某一段 graphics memory 同一時間只分配給一個 process 使用。

課本說,為了防止非法 I/O,所有 I/O instructions 都被定義為 privileged instructions;user program 不能直接發 I/O,只能透過 system call 讓 OS 在 monitor/kernel mode 檢查合法性後代為執行。

text
12.4.7 Kernel Data Structures

Kernel Data Structures(核心資料結構):
kernel data structures 是 OS 在 kernel 中用來記錄 I/O 狀態與 I/O objects 的資料結構。
kernel 需要保存 open files、network connections、character-device communication、
device state 與 pending requests 等資訊。

Open-File Table(開啟檔案表):
open-file table 是 kernel 用來追蹤目前已開啟檔案的資料結構。
它記錄檔案狀態、file position、access mode、reference count,
並讓 read/write/close 可透過 file descriptor 找到對應的 kernel I/O object。

File-System Record(檔案系統紀錄):
file-system record 是 system-wide open-file table 中代表一般檔案的紀錄。
它通常包含 inode pointer,以及指向 read、write、select、ioctl、close 等操作函式的指標。

Inode Pointer(inode 指標):
inode pointer 是 file-system record 中指向 active-inode table 的指標。
kernel 可透過 inode pointer 找到該檔案的 metadata 與 data block 位置。

Active-Inode Table(活躍 inode 表):
active-inode table 是 kernel 中保存目前正在使用的 inodes 的表格。
已開啟檔案可透過 system-wide open-file table 中的 inode pointer 連到 active-inode table。

Socket Record(通訊端紀錄):
socket record 是 kernel 用來代表 network socket 的 I/O record。
它會包含指向 network information 與 read/write/select/ioctl/close 等操作函式的指標。

Network-Information Table(網路資訊表):
network-information table 是 kernel 用來追蹤 network connection 狀態的資料結構。
socket record 可透過指標連到 network-information table。

Function Pointers for I/O Operations(I/O 操作函式指標):
kernel I/O object 常包含指向 read、write、select、ioctl、close 等函式的 pointers。
這讓 UNIX 可以用統一的 file descriptor 介面操作不同 objects,
例如一般檔案、device、socket,但底層語意由不同函式實作。

課本 12.4.7 說 kernel 需要用 in-kernel data structures 追蹤 I/O components 的使用狀態,例如 open-file table,也追蹤 network connections、character-device communications 等;UNIX 也會用 file-system access 統一 user files、raw devices、process address spaces 等不同 entities。

text
12.4.8 Power Management

Power Management(電源管理):
power management 是 OS 控制 hardware components 電力狀態的機制。
在 mobile computing 中,power management 特別重要,因為它直接影響 battery life。

Power Collapse(深度省電狀態):
power collapse 是讓 device 進入非常深的 sleep state 的能力。
device 幾乎像關機一樣省電,但仍可回應外部事件,例如按鍵或電話,
並快速喚醒恢復運作。

Component-Level Power Management(元件層級電源管理):
component-level power management 是 OS 根據各硬體元件之間的關係與使用狀態,
分別關閉未使用 components 的技術。
例如 flash storage、USB storage、I/O subsystem、system bus 都可根據使用情況被關閉。

Device Tree(裝置樹):
device tree 是描述實體 device topology 的資料結構。
Android 可用 device tree 理解元件之間的從屬關係,
例如 flash storage 是 I/O subsystem 的 sub-node,I/O subsystem 又連到 system bus。

Wakelock(喚醒鎖):
wakelock 是 Android 中讓 application 暫時阻止系統進入 power collapse 的機制。
當 application 持有 wakelock 時,kernel 會防止系統進入深度睡眠,
確保正在播放影片、遊戲或等待網頁載入等工作不中斷。

課本在 12.4 power management 部分用 Android 當例子,說 mobile OS 會靠 power collapse、component-level power management、wakelocks 來延長 battery life;wakelock 被 application 持有時,kernel 會阻止系統進入 power collapse。

text
12.4 最後速背版

Kernel I/O Subsystem:
kernel 管理 I/O 的核心部分,提供 scheduling、buffering、caching、spooling、
device reservation、error handling、protection、data structures、power management。

I/O Scheduling:
重排 I/O requests,提高效能、降低等待時間、維持公平。

Device-Status Table:
kernel 追蹤每個 I/O device 的 type、address、state 與 pending request。

Buffer:
暫存正在傳輸的資料;處理速度不匹配、傳輸大小不匹配、copy semantics。

Cache:
較快 storage 上的資料副本,用來避免或延後實體 I/O。

Buffer vs Cache:
buffer 可能是唯一 copy;cache 一定是其他地方資料的副本。

Spool:
給 printer 這種不能混合輸出的 device 用的 output buffer。
多個 jobs 先存成 spool files,再一個一個輸出。

Device Reservation:
讓 process 對某些不能共享的 device 取得 exclusive access。

Error Handling:
處理 I/O failures;transient failure 可 retry/resend,permanent failure 較難恢復。

errno:
UNIX 用來表示 system call 失敗原因的錯誤碼。

I/O Protection:
I/O instructions 是 privileged instructions,user program 必須透過 system call 做 I/O。

Open-File Table:
kernel 追蹤已開啟檔案與 I/O objects 的資料結構。

Function Pointers:
讓同一套 read/write/close 介面可對不同 I/O objects 執行不同底層操作。

Power Collapse:
讓裝置進入深度睡眠但可被外部事件喚醒。

Wakelock:
application 暫時阻止系統進入 power collapse 的機制。

13.3~13.4 ​

可以,13.3~13.4 這邊很適合用「考古名詞解釋」整理。主軸是:13.3 在講 directory 怎麼組織檔名;13.4 在講 file protection 怎麼控制誰能做什麼操作。 課本總結也明確列出 single-level、two-level、tree、acyclic graph、general graph directory,以及 protection 可控制 read、write、execute、append、delete、list 等不同 access type。

text
13.3 Directory Structure

Directory(目錄):
directory 是用來管理檔案名稱與檔案資訊的資料結構。
它會列出檔案名稱,並記錄或連到檔案的位置、長度、型態、擁有者、建立時間、最後使用時間等資訊。

Single-Level Directory(單層目錄):
single-level directory 是所有 files 都放在同一個 directory 下面的結構。
它實作簡單,但在 multiuser system 中會造成 naming problem,因為每個 file 都必須有唯一名稱。

Naming Problem(命名問題):
naming problem 是指在 single-level directory 中,不同使用者不能建立相同檔名的檔案。
這會讓多使用者系統很不方便,因為檔名容易衝突。

Two-Level Directory(二層目錄):
two-level directory 會替每個 user 建立一個獨立的 user directory。
因此不同 users 可以在自己的 directory 中使用相同 file name,解決 single-level directory 的命名衝突問題。

MFD(Master File Directory,主檔案目錄):
MFD 是 two-level directory 的第一層目錄。
它記錄每個 user 對應到哪一個 UFD,也就是每個使用者自己的目錄。

UFD(User File Directory,使用者檔案目錄):
UFD 是 two-level directory 中每個 user 自己的 directory。
使用者的 files 會放在自己的 UFD 中,因此不同 users 的檔名可以重複。

Path Name(路徑名稱):
path name 是用來唯一指定某個 file 的名稱序列。
在 two-level directory 中,user name 加上 file name 就可以形成 path name;在 tree-structured directory 中,path name 則是一串 directory names 加上 file name。

Tree-Structured Directory(樹狀目錄):
tree-structured directory 是 two-level directory 的自然延伸。
它允許 users 建立 subdirectories 來組織 files,因此可以形成多層 directory tree。

Root Directory(根目錄):
root directory 是 tree-structured directory 的最上層目錄。
所有 absolute path names 都會從 root directory 開始。

Subdirectory(子目錄):
subdirectory 是位於另一個 directory 底下的 directory。
它讓使用者可以依照主題、用途或資料型態分類檔案。

Current Directory(目前目錄):
current directory 是 process 目前所在的 directory。
使用 relative path name 時,路徑會從 current directory 開始解析。

Absolute Path Name(絕對路徑名稱):
absolute path name 是從 root directory 開始描述的完整路徑。
它不依賴 current directory,因此可以唯一指定某個 file 或 directory。

Relative Path Name(相對路徑名稱):
relative path name 是從 current directory 開始描述的路徑。
例如 current directory 在 /spell/mail 時,relative path name prt/first 可表示 /spell/mail/prt/first。:contentReference[oaicite:1]{index=1}

Directory Deletion Policy(目錄刪除政策):
directory deletion policy 是 OS 對刪除 directory 的處理規則。
有些系統只允許刪除 empty directory;有些系統允許遞迴刪除整個 directory tree。
後者較方便,但若誤刪會更危險。:contentReference[oaicite:2]{index=2}

Acyclic-Graph Directory(無環圖目錄):
acyclic-graph directory 是允許 files 或 subdirectories 被共享,但不允許形成 cycle 的 directory structure。
它比 tree-structured directory 更彈性,因為同一個 file 或 subdirectory 可以同時出現在兩個以上位置。

Shared File / Shared Directory(共享檔案 / 共享目錄):
shared file 或 shared directory 是在 file system 中同時出現在兩個或多個位置的同一個實體。
它不是複製品;若其中一個使用者修改 shared file,其他路徑看到的內容也會改變。:contentReference[oaicite:3]{index=3}

Link(連結):
link 是讓某個 directory entry 指向既有 file 或 directory 的機制。
它可用來實作 shared files 或 shared directories,使同一個實體能從不同路徑被存取。

Hard Link(硬連結):
hard link 是多個 directory entries 指向同一個實際 file 的連結方式。
只要還有 hard link 存在,通常檔案實體內容不會被真正刪除。

Symbolic Link / Soft Link(符號連結 / 軟連結):
symbolic link 是一種特殊檔案,其內容通常是另一個 file 或 directory 的 path name。
它比較像捷徑;如果目標檔案被刪除,symbolic link 可能會失效。

Reference Count(參考計數):
reference count 是用來記錄某個 shared file 或 directory 目前有多少 links 指向它的計數。
當 reference count 變成 0 時,代表沒有任何 directory entry 再指向該 file,系統才可真正回收其空間。

General Graph Directory(一般圖目錄):
general graph directory 是允許 directory graph 中出現 cycles 的結構。
它提供最完整的 sharing 彈性,但會讓搜尋、刪除與空間回收變複雜,可能需要 garbage collection。

Cycle(循環):
cycle 是 directory graph 中可以沿著 links 走一圈又回到原本 directory 的情況。
cycle 會造成搜尋可能無限迴圈,也會讓刪除與回收 unused files 更困難。

Garbage Collection(垃圾回收):
garbage collection 是在 general graph directory 中,用來找出已經無法從 root 存取但仍佔用空間的 files 或 directories,並回收其 storage 的技術。
text
13.4 Protection

Protection(保護):
protection 是控制使用者或 process 對 files 的 access 權限的機制。
因為 files 是大多數系統的主要資訊儲存方式,所以 multiuser system 必須防止未授權的讀取、修改、刪除或執行。

Access Type(存取型態):
access type 是對 file 或 directory 可執行的操作種類。
常見 access types 包含 read、write、execute、append、delete、list 等。
OS 可以對每一種 access type 分別控制權限。:contentReference[oaicite:4]{index=4}

Read Permission(讀取權限):
read permission 允許使用者讀取 file 的內容。
若沒有 read permission,即使知道檔名,也不能查看檔案資料。

Write Permission(寫入權限):
write permission 允許使用者修改 file 的內容。
此權限通常不一定代表可刪除檔案,因為刪除可能由 directory 權限控制。

Execute Permission(執行權限):
execute permission 允許使用者將 file 當作程式執行。
在 UNIX/Linux 中,script 或 binary file 若沒有 execute permission,就不能直接執行。

Append Permission(附加權限):
append permission 允許使用者將資料加到 file 末端,但不一定允許修改 file 原本內容。
它常用於 log file 等只允許新增紀錄的情境。

Delete Permission(刪除權限):
delete permission 允許使用者刪除 file。
在某些系統中,刪除檔案主要取決於對該 file 所在 directory 的權限。

List Directory Permission(列目錄權限):
list directory permission 允許使用者列出 directory 內的 file names。
如果沒有此權限,使用者可能無法查看該 directory 中有哪些檔案。

ACL(Access-Control List,存取控制串列):
ACL 是附加在 file 或 object 上的權限表。
它列出哪些 users 可以對該 file 執行哪些 operations,例如 read、write、execute。
ACL 的優點是權限可細分到個別使用者;缺點是若 users 很多,list 可能變得很長。

Access List(存取串列):
access list 是 ACL 的概念,表示從 object 的角度列出所有被允許存取它的 domains/users 與其 rights。
在 access matrix 觀念中,access list 就是某個 object 的 column。

Capability List(能力串列):
capability list 是從 user / domain 的角度列出其可存取的 objects 與對應 rights。
在 access matrix 觀念中,capability list 就是某個 domain 的 row。

Password Protection(密碼保護):
password protection 是替 file 或 directory 加上密碼,只有知道密碼者才能存取。
它簡單但缺點是密碼管理困難,且若每個 file 都有不同密碼會很不方便。

Owner(擁有者):
owner 是 file 的擁有者,通常是建立該 file 的 user。
owner 通常可以設定該 file 的權限,並擁有較高的 access rights。

Group(群組):
group 是一組 users 的集合。
file 可以指定某個 group 擁有特定權限,讓同一組合作 users 共享 file access。

Universe / World / Others(全體使用者 / 其他人):
universe、world 或 others 指系統中除了 owner 和 group 之外的其他所有 users。
UNIX/Linux 權限通常會分成 owner、group、others 三類。

Protection Mask(保護遮罩):
protection mask 是用一組 bits 表示某類使用者能否 read、write、execute 某個 object。
Linux/UNIX 常用 owner、group、world 三組 rwx bits 形成 protection mask。:contentReference[oaicite:5]{index=5}

UID(User Identifier,使用者識別碼):
UID 是 OS 用來識別使用者身分的數值。
在 UNIX/Linux 中,如果 process 的 UID 與 file 的 UID 相同,該 process 會取得 owner rights。

GID(Group Identifier,群組識別碼):
GID 是 OS 用來識別群組身分的數值。
若 process 的某個 GID 與 file 的 GID 相同,且 UID 不符合 owner,則會套用 group rights。

Root UID(Root User Identifier,超級使用者識別碼):
root UID 是 UNIX/Linux 中的特權使用者身分。
擁有 root UID 的 process 通常可以繞過一般 access checks,存取系統中的大多數 objects。:contentReference[oaicite:6]{index=6}

rwx Permission(Read / Write / Execute Permission,讀寫執行權限):
rwx permission 是 UNIX/Linux 常見的檔案保護方式。
r 表示 read,w 表示 write,x 表示 execute;每個 file 通常分別為 owner、group、others 設定 rwx 權限。

Permission Bits(權限位元):
permission bits 是用位元記錄 file access rights 的方式。
例如 UNIX/Linux 中,每個 file 通常有三組權限位元,分別對應 owner、group、others。

Access Check(存取檢查):
access check 是 OS 在 process 嘗試開啟或操作 file 時,檢查該 process 是否具有所要求權限的動作。
若權限不符,OS 會拒絕該操作並回傳錯誤。
text
13.3~13.4 最後速背版

13.3 Directory Structure:
Single-Level Directory:全部 files 放同一層,簡單但容易檔名衝突。
Two-Level Directory:每個 user 有自己的 UFD,解決檔名衝突。
MFD:Master File Directory,記錄 users 對應到哪些 UFD。
UFD:User File Directory,每個 user 自己的 file directory。
Tree-Structured Directory:允許 subdirectories,形成多層樹狀結構。
Absolute Path:從 root 開始的完整路徑。
Relative Path:從 current directory 開始的路徑。
Acyclic-Graph Directory:可共享 files/directories,但不允許 cycle。
Shared File:同一個實體出現在多個路徑,不是複製品。
Link:讓 directory entry 指向既有 file/directory。
General Graph Directory:允許 cycle,彈性大但需要處理搜尋與 garbage collection。
Garbage Collection:回收無法再被存取但仍佔空間的檔案。

13.4 Protection:
Protection:控制誰可以對 file 做什麼操作。
Access Type:read、write、execute、append、delete、list。
ACL:Access-Control List,列出哪些 users 對此 file 有哪些 rights。
Access List:從 object 角度看,誰可以存取它。
Capability List:從 domain/user 角度看,它可以存取哪些 objects。
Owner:檔案擁有者。
Group:共享權限的一組 users。
Universe / World / Others:除了 owner、group 之外的其他 users。
Protection Mask:用 bits 表示 owner/group/world 的 rwx 權限。
UID:User Identifier,使用者識別碼。
GID:Group Identifier,群組識別碼。
rwx:read、write、execute 權限。

14.1~14.5-14.7 ​

可以,這邊整理 Chapter 14.1~14.5 與 14.7。 主軸是:14.1~14.2 講 file system 內部層次與資料結構;14.3 講 directory 怎麼實作;14.4 講 file 的 disk blocks 怎麼配置;14.5 講 free blocks 怎麼管理;14.7 講 crash 後怎麼 recovery。 課本目錄也明確列出這幾節:File-System Structure、File-System Operations、Directory Implementation、Allocation Methods、Free-Space Management、Recovery。

text
14.1 File-System Structure

File-System Structure(檔案系統結構):
file-system structure 是作業系統將 logical file system 映射到 physical storage device 的內部組織方式。
它需要解決兩個問題:第一,使用者看到的 file、attribute、operation、directory structure 長什麼樣子;
第二,OS 如何用資料結構與演算法把 logical file system 對應到實體儲存裝置。

Layered File System(分層式檔案系統):
layered file system 是將 file system 實作分成多個層次的設計。
每一層使用下層提供的功能,並提供更高階功能給上層。
優點是減少重複程式碼;缺點是可能增加 OS overhead,降低效能。

I/O Control(I/O 控制層):
I/O control 是 file system 最底層,包含 device drivers 與 interrupt handlers。
它負責在 main memory 與 storage device 之間搬移資料,並把高階命令轉成硬體控制器可理解的低階指令。

Device Driver(裝置驅動程式):
device driver 是作業系統與硬體控制器之間的翻譯器。
它接收高階命令,例如「讀取 logical block 123」,
再轉成特定硬體控制器需要的低階操作。

Basic File System(基本檔案系統):
basic file system 負責對 device driver 發出 generic read/write block commands。
它使用 logical block address 存取儲存裝置,也負責 I/O request scheduling、
buffer 與 cache 管理。

Block I/O Subsystem(區塊 I/O 子系統):
block I/O subsystem 是 Linux 中 basic file system 類似的名稱。
它負責以 block 為單位進行 I/O,並處理與 storage device 之間的 block transfer。

File-Organization Module(檔案組織模組):
file-organization module 知道 file 與 logical blocks 的關係。
它負責將檔案的 logical block number 對應到實體 storage blocks,
也包含 free-space manager,負責追蹤與分配未使用 blocks。

Free-Space Manager(可用空間管理器):
free-space manager 負責追蹤 storage device 上哪些 blocks 尚未被配置。
當 file-organization module 需要新 block 時,
free-space manager 會提供可用 blocks。

Logical File System(邏輯檔案系統):
logical file system 負責管理 metadata。
它管理 directory structure,根據 symbolic file name 找到檔案資訊,
並透過 FCB 維護 file structure,也負責 protection。

Metadata(中繼資料):
metadata 是除了檔案實際內容以外的所有 file-system 管理資訊。
例如檔案名稱、權限、擁有者、大小、時間、block 位置、free-space 資訊等。

課本 14.1 的分層圖就是:application programs 上面呼叫 file system,底下依序經過 logical file system、file-organization module、basic file system、I/O control,最後到 devices;課本也說 FCB 在 UNIX 中就是 inode,包含 ownership、permissions、file contents location 等資訊。

text
14.2 File-System Operations

On-Storage Structures(磁碟上檔案系統結構):
on-storage structures 是存在 storage device 上的 file-system 資料結構。
它們用來保存檔案系統即使斷電後仍需要保留的資訊,例如 boot control block、
volume control block、directory structure、per-file FCB。

Boot Control Block(開機控制區塊):
boot control block 是每個 volume 上可能存在的開機資訊區塊。
如果該 volume 可以用來開機,裡面會包含載入 OS 所需資訊;
若該 volume 不含 OS,這個 block 可以是空的。
在 UFS 中稱為 boot block,在 NTFS 中稱為 partition boot sector。

Volume Control Block(磁碟區控制區塊):
volume control block 保存整個 volume 的資訊。
例如 volume 的 block 數量、block size、free-block count、free-block pointers、
free-FCB count、FCB pointers 等。
在 UFS 中稱為 superblock;在 NTFS 中則存在 master file table 中。

Superblock(超級區塊):
superblock 是 UFS 中 volume control block 的名稱。
它記錄整個 file system 的總體資訊,例如 block 數量、block size、free blocks 與 free FCB 等。

Directory Structure(目錄結構):
directory structure 是每個 file system 用來組織檔案的資料結構。
在 UFS 中,directory 包含 file names 與對應的 inode numbers;
在 NTFS 中,directory 資訊存在 master file table 中。

FCB(File Control Block,檔案控制區塊):
FCB 是描述一個 file 的資料結構。
它包含檔案權限、檔案時間、擁有者、group、ACL、file size、
以及 file data blocks 或指向 data blocks 的 pointers。
在 UNIX file system 中,FCB 就是 inode。

MFT(Master File Table,主檔案表):
MFT 是 NTFS 用來保存檔案與 file-system metadata 的核心資料表。
NTFS 中很多 file information 與 directory information 都存在 MFT 中。

In-Memory Structures(記憶體中檔案系統結構):
in-memory structures 是 OS 在記憶體中維護的 file-system 資料結構。
它們用於 file-system 管理與效能提升,通常在 mount 時載入,
在 file-system operations 中更新,dismount 時丟棄。

Mount Table(掛載表):
mount table 是 OS 在記憶體中維護的表格,用來記錄目前已掛載的 volumes。
它說明哪個 file system 被掛載到哪個 mount point,以及相關 volume 資訊。

Directory-Structure Cache(目錄結構快取):
directory-structure cache 保存最近存取過的 directory information。
它可以減少反覆從 storage 讀取 directory 的成本,提升 pathname lookup 效率。

System-Wide Open-File Table(全系統開啟檔案表):
system-wide open-file table 保存系統中所有已開啟檔案的共同資訊。
每個 entry 通常包含該 open file 的 FCB copy,以及其他與檔案狀態有關的資訊。

Per-Process Open-File Table(每行程開啟檔案表):
per-process open-file table 是每個 process 自己擁有的 open-file table。
它記錄該 process 開啟了哪些 files,並包含指向 system-wide open-file table entry 的指標。

Buffer(緩衝區):
buffer 是 memory 中用來暫存 file-system blocks 的空間。
當 blocks 正從 file system 讀入或寫回時,會先經過 buffers。

課本 14.2 明確列出 on-storage structures 包含 boot control block、volume control block、directory structure、per-file FCB;in-memory structures 包含 mount table、directory-structure cache、system-wide open-file table、per-process open-file table 與 buffers。

text
File Creation(檔案建立):
建立新檔案時,process 會呼叫 logical file system。
logical file system 會配置新的 FCB,接著把對應 directory 讀入 memory,
新增 file name 與 FCB 的對應,最後再寫回 file system。

Open Operation(open() 操作):
open() 會根據 file name 搜尋 directory structure,找到對應 FCB / inode。
若檔案尚未在 system-wide open-file table 中,OS 會把 FCB copy 放入 system-wide table;
接著在 per-process open-file table 建立 entry,最後回傳 file descriptor / file handle。

Read Operation(read() 操作):
read() 不再使用 file name 搜尋 directory。
它使用 file descriptor 查 per-process open-file table,
再透過 system-wide open-file table 找到 FCB / inode 與目前檔案位置,
接著讀取資料並更新 file pointer。

Close Operation(close() 操作):
close() 會移除該 process 的 per-process open-file table entry。
同時 system-wide open-file table 中對應 entry 的 open count 會減少;
若 open count 變成 0,OS 可移除該 system-wide entry 並釋放相關資源。

Sample 考古題有直接考 FCB、inode 與 open() 操作,也有考 FAT 與 bit vector,代表 14.2~14.5 是重點區。

text
14.3 Directory Implementation

Directory Implementation(目錄實作):
directory implementation 是指 OS 如何用資料結構管理 directory entries。
不同實作方式會影響 file lookup、file creation、file deletion 的效率與可靠性。

Linear List(線性串列):
linear list 是最簡單的 directory implementation。
它用一串 file names 與 pointer / FCB information 儲存 directory entries。
優點是簡單;缺點是尋找檔案需要 linear search,directory 大時效能差。

Linear Search(線性搜尋):
linear search 是從 directory list 開頭逐一比對 file name。
在 linear list directory 中,建立檔案時要先搜尋是否已有同名檔案;
讀取檔案時也要搜尋名稱,因此速度較慢。

Unused Directory Entry(未使用目錄項目):
當刪除 file 後,directory entry 可以被標記為 unused。
常見方式包含設特殊空白名稱、invalid inode number,或 used/unused bit,
讓該位置之後能被新 file 重用。

Sorted List(排序串列):
sorted list 是將 directory entries 按照 file name 排序。
它可支援 binary search,降低平均搜尋時間;
但建立與刪除檔案時可能需要搬移大量 directory entries 以維持排序。

Hash Table(雜湊表):
hash table 是用 file name 計算 hash value,快速找到 directory entry 的資料結構。
它可大幅減少 directory search time,但需要處理 collision,
而且 hash table 大小與 hash function 通常會影響彈性。

Collision(雜湊碰撞):
collision 是不同 file names 經 hash function 後得到相同位置的情況。
directory hash table 必須處理 collision,否則不同檔案名稱可能互相衝突。

Chained-Overflow Hash Table(鏈結溢位雜湊表):
chained-overflow hash table 是用 linked list 處理 hash collision 的方法。
每個 hash entry 可以連到一串同 hash value 的 directory entries;
查詢時只需要搜尋該 linked list,而不是整個 directory。

課本 14.3 說 linear list 簡單但找檔案需要 linear search;hash table 會用 file name 算出位置並回傳 pointer,因此能大幅降低搜尋時間,但要處理 collision,也可能遇到固定大小與 hash function 依賴表格大小的問題。

text
14.4 Allocation Methods

Allocation Methods(配置方法):
allocation methods 是 file system 將 file 的 logical blocks 配置到 physical storage blocks 的方法。
主要方法包含 contiguous allocation、linked allocation、indexed allocation。
目標是有效利用 storage space,並讓 file access 速度夠快。

Contiguous Allocation(連續配置):
contiguous allocation 要求每個 file 佔用一組連續的 device blocks。
優點是 sequential access 與 direct access 都很快;
缺點是容易產生 external fragmentation,而且 file 大小成長不易。

External Fragmentation(外部碎片):
external fragmentation 是 free space 被切成許多零散小區塊,
雖然總空間足夠,但可能沒有足夠大的連續區塊放入新 file。
contiguous allocation 會受到 external fragmentation 影響。

Extent(範圍 / 延伸區段):
extent 是一段連續 blocks 的集合。
extent-based allocation 讓一個 file 由一個或多個 extents 組成,
比單純 contiguous allocation 更能支援檔案成長,也保留連續配置的部分效能優勢。

Linked Allocation(鏈結配置):
linked allocation 讓每個 file 由一串 blocks 組成,每個 block 指向下一個 block。
優點是沒有 external fragmentation,file 可以容易成長;
缺點是 direct access 效率差,因為要從頭沿著 links 找到第 n 個 block。

Pointer Overhead(指標負擔):
pointer overhead 是 linked allocation 中,每個 block 需要額外空間存放下一個 block 指標的成本。
這會減少每個 block 可存放實際資料的空間。

FAT(File Allocation Table,檔案配置表):
FAT 是 linked allocation 的變形。
每個 disk block 在 FAT 中都有一個 entry,entry 內容表示該 block 的下一個 block number。
directory entry 只需要記錄 file 的 starting block,接著可沿著 FAT 找完整個 file。

Directory Entry in FAT(FAT 中的目錄項目):
在 FAT 系統中,directory entry 會保存 file name 與 starting block number。
file 的後續 blocks 不放在 directory entry 中,而是透過 FAT entry 一路追蹤。

Indexed Allocation(索引配置):
indexed allocation 為每個 file 建立一個 index block。
index block 內含該 file 所有 data blocks 的 pointers。
優點是支援 direct access,且沒有 external fragmentation;
缺點是需要額外 index block 空間。

Index Block(索引區塊):
index block 是 indexed allocation 中專門存放 data block pointers 的 block。
每個 file 可以有自己的 index block,用來指出該 file 的資料 blocks 在哪裡。

Linked Scheme for Index Blocks(索引區塊鏈結法):
linked scheme 是當一個 index block 不夠存放所有 pointers 時,
將多個 index blocks 串成 linked list。
它可支援大檔案,但存取後段 blocks 可能需要沿著 index blocks 逐步查找。

Multilevel Index(多層索引):
multilevel index 是用多層 index blocks 管理大型 file。
第一層 index 指向第二層 index blocks,第二層再指向 data blocks;
這能支援更大的 file,但可能增加查表成本。

Combined Scheme(混合索引配置):
combined scheme 是同時使用 direct blocks 與 indirect blocks 的配置方式。
小檔案可直接用 direct pointers 存取,大檔案則透過 single、double、triple indirect blocks 擴充。

inode(index node,索引節點):
inode 是 UNIX 中代表一個 file 的 FCB。
它保存 file metadata,以及指向 data blocks 的 direct pointers 與 indirect pointers。
檔名通常存在 directory entry 中,directory entry 會把 file name 對應到 inode number。

Direct Block Pointer(直接區塊指標):
direct block pointer 是 inode 中直接指向 data block 的 pointer。
適合小檔案,因為不需要額外查 indirect block。

Single Indirect Block(單層間接區塊):
single indirect block 是 inode 中某個 pointer 指向的一個 block,
該 block 內部再存放許多 data block pointers。
它用來支援比 direct pointers 能涵蓋更大的 file。

Double Indirect Block(雙層間接區塊):
double indirect block 是 inode pointer 指向一個 index block,
該 index block 再指向其他 index blocks,最後才指向 data blocks。
它可支援更大型 file。

Triple Indirect Block(三層間接區塊):
triple indirect block 是三層 index 的間接配置方式。
它可支援非常大的 file,但存取時可能需要更多次 index block lookup。

課本 14.4 明確說 secondary storage 的 allocation 有三大方法:contiguous、linked、indexed;FAT 是 linked allocation 的變形,indexed allocation 則用 index block 保存指向 data blocks 的 pointers。

text
14.5 Free-Space Management

Free-Space Management(可用空間管理):
free-space management 是 file system 追蹤哪些 device blocks 尚未被配置的方法。
當建立新 file 時,OS 會從 free-space list 找出可用 blocks;
當 file 被刪除時,原本使用的 blocks 會被加回 free-space list。

Free-Space List(可用空間串列):
free-space list 記錄所有尚未配置給 file 或 directory 的 free device blocks。
名稱雖然叫 list,但實作方式不一定真的是 linked list,也可能是 bit vector、grouping、counting 等。

Bit Vector / Bitmap(位元向量 / 位元圖):
bit vector 是用一個 bit 表示一個 disk block 是否 free 的方法。
通常 bit = 1 表示 free,bit = 0 表示 allocated。
它的優點是容易找到連續 free blocks,也容易實作;缺點是需要一段 memory 儲存 bitmap。

Bit Map Indexing(位元圖索引):
bit map indexing 是用 bit 的位置對應 block number。
例如第 i 個 bit 對應第 i 個 block,因此只要檢查 bit value,
就能知道該 block 是否可用。

Linked Free-Space List(鏈結式可用空間串列):
linked free-space list 是把所有 free blocks 用 pointer 串起來的方法。
OS 只需保存第一個 free block 的位置;配置時拿走第一個 free block 即可。
缺點是若要找連續 free blocks,效率可能不好。

Grouping(分組法):
grouping 是 linked free-list 的改良。
第一個 free block 內存放 n 個 free blocks 的 addresses;
其中前 n-1 個是真正 free blocks,最後一個則指向下一組 free blocks 的 address list。
這樣可以一次快速取得多個 free block addresses。

Counting(計數法):
counting 利用許多 free blocks 常常是連續出現的特性。
它不逐一記錄每個 free block,而是記錄第一個 free block 的 address
以及後面連續 free blocks 的數量 count。
每個 entry 由 device address 與 count 組成。

Free Block(可用區塊):
free block 是尚未配置給任何 file 或 directory 的 device block。
file system 會透過 free-space management 記錄並重複使用 free blocks。

Allocated Block(已配置區塊):
allocated block 是已經被某個 file 或 directory 使用的 block。
在 bitmap 中,allocated block 通常用 0 表示。

課本 14.5 說 free-space list 記錄所有未配置給 file 或 directory 的 free device blocks;建立檔案時從 free-space list 找空間,刪除檔案時把空間加回。bit vector、linked list、grouping、counting 都是這節重點,其中 grouping 會在第一個 free block 存 n 個 free blocks 的地址,counting 則記錄起始 free block 與連續數量。

text
14.7 Recovery

Recovery(復原):
recovery 是 file system 在 crash、power failure 或 storage failure 後,
恢復 file-system data structures 一致性與資料可用性的機制。
主要方法包含 consistency checking、journaling / log-based recovery、
no-overwrite design、backup and restore。

Consistency Checking(一致性檢查):
consistency checking 是在 crash 後檢查 file-system metadata 是否一致,
並嘗試修復錯誤的技術。
傳統做法是允許 file-system structures 先壞掉,之後再透過 checker 修復。

Consistency Checker(一致性檢查器):
consistency checker 是執行 consistency checking 的系統程式。
它會比較 directory structure、metadata 與實際 storage 狀態,
並嘗試讓 file system 回到一致狀態。
UNIX 中常見例子是 fsck。

fsck(file system check,檔案系統檢查):
fsck 是 UNIX / 類 UNIX 系統中常見的 consistency checker。
它會檢查 file-system data structures,並嘗試修復 crash 後造成的不一致。

Metadata Corruption(中繼資料毀損):
metadata corruption 是 file-system metadata 因 crash 或寫入中斷而變得不一致或損壞。
例如 directory 已指向某 block,但 free-space structure 又認為該 block 是 free,
就會造成 file-system inconsistency。

Journaling File System(日誌式檔案系統):
journaling file system 又稱 log-based transaction-oriented file system。
它會先把 metadata changes 依序寫入 log,再實際更新 file-system structures。
crash 後可透過 log 完成已 committed transactions 或 undo 未完成 transactions。

Log-Based Recovery(日誌式復原):
log-based recovery 是利用 log records 進行 crash recovery 的方法。
當系統 crash 後,OS 可根據 log 判斷哪些 operations 已 committed 但尚未完成,
並重新執行或復原它們,使 metadata 回到一致狀態。

Transaction(交易):
transaction 是一組為完成某個 file-system operation 所需的 metadata updates。
在 journaling file system 中,一個 transaction 要嘛全部完成,要嘛 crash 後被回復,
以避免 file-system structures 處於半更新狀態。

Commit(提交):
commit 表示 transaction 的 changes 已經被寫入 log,
系統可視為該 transaction 成功。
之後即使 crash,也可以透過 replay log 完成這些 changes。

Log(日誌):
log 是用來順序記錄 file-system metadata changes 的區域。
把 changes 先寫入 log 的優點是 sequential I/O 較快,
也方便 crash 後做 recovery。

Circular Buffer(環狀緩衝區):
circular buffer 是 log file 常用的儲存方式。
寫到尾端後會回到開頭繼續寫,但必須避免覆蓋尚未安全寫入 file-system structures 的 log records。

Redo(重做):
redo 是 crash recovery 中,重新套用已 committed transaction 的操作。
目的在於確保那些已承諾成功的 metadata changes 真正反映到 file-system structures 中。

Undo(復原 / 回復):
undo 是 crash recovery 中,撤銷未 committed 或 aborted transaction 已經部分套用的操作。
目的在於避免 file-system structures 保留半完成的更新。

Checkpoint(檢查點):
checkpoint 是定期寫入 log 的紀錄,用來表示在此之前的 log records 已不再需要用於 recovery。
有 checkpoint 後,系統 crash recovery 不必從 log 開頭重做,可縮短 recovery time。

No-Overwrite File System(不覆寫式檔案系統):
no-overwrite file system 是更新資料時不直接覆寫舊 blocks,
而是把新的 data 和 metadata 寫到新 blocks,最後再原子性地更新 pointers。
如果 old pointers 保留,就可以形成 snapshot。

Snapshot(快照):
snapshot 是 file system 在某個時間點的視圖。
如果 no-overwrite file system 保留舊 blocks 與舊 pointers,
就能讓使用者看到更新前某一刻的 file system 狀態。

Checksum(檢查和):
checksum 是用來檢查 metadata 或 data blocks 是否正確的驗證資訊。
ZFS 對 metadata 和 data blocks 都做 checksumming,
搭配 RAID 可提高資料正確性。

Backup(備份):
backup 是將資料從一個 storage device 複製到另一個 storage medium 的動作。
其目的,是在個別 file 或整個 device 遺失時,仍能從備份中恢復資料。

Restore(還原):
restore 是從 backup 中把遺失或損壞的 file / file system 資料復原回來的動作。
storage device 失效或資料誤刪後,可以透過 restore 復原。

課本 14.7 指出,傳統 consistency checking 可能耗時、需要人工介入,甚至無法修復;journaling / log-based transaction-oriented file system 則將 metadata changes 先寫入 log,crash 後完成 committed transactions 或 undo 未 committed transactions;WAFL/ZFS 類方法則避免覆寫舊 blocks,ZFS 甚至對 metadata 與 data blocks 都做 checksumming。

text
14.1~14.5、14.7 最後速背版

14.1:
Layered File System:分層實作 file system。
I/O Control:device drivers + interrupt handlers,負責硬體 I/O。
Basic File System:發出 generic block read/write commands。
File-Organization Module:管理 file logical blocks 到 physical blocks 的 mapping。
Logical File System:管理 metadata、directory、FCB、protection。
FCB:File Control Block,檔案 metadata 與資料 block 指標;UNIX 中是 inode。

14.2:
Boot Control Block:volume 開機資訊。
Volume Control Block / Superblock:volume 整體資訊。
Mount Table:記錄已掛載 volumes。
Directory-Structure Cache:快取最近用過的 directory。
System-Wide Open-File Table:保存所有已開啟檔案的共同資訊。
Per-Process Open-File Table:保存某 process 開啟檔案的 fd 對應。
open():檔名 → directory → FCB/inode → open-file table → fd。

14.3:
Linear List:directory entries 線性串列,簡單但搜尋慢。
Hash Table:用 file name hash 加速 directory lookup。
Collision:不同 file names hash 到同一位置。
Chained Overflow:用 linked list 處理 hash collision。

14.4:
Contiguous Allocation:file blocks 連續配置,快但有 external fragmentation。
Linked Allocation:blocks 用 pointer 串起來,成長容易但 direct access 慢。
FAT:File Allocation Table,用表格保存每個 block 的下一個 block。
Indexed Allocation:用 index block 保存 file 所有 data block pointers。
inode:UNIX 的 FCB,存 metadata 與 direct/indirect block pointers。

14.5:
Free-Space List:記錄所有 free blocks。
Bit Vector / Bitmap:一個 bit 對應一個 block,1 free、0 allocated。
Linked Free-Space List:free blocks 串成 linked list。
Grouping:一個 free block 裡存多個 free block addresses。
Counting:記錄起始 free block address + 連續 free blocks 數量。

14.7:
Consistency Checker / fsck:檢查並修復 file-system metadata inconsistency。
Journaling File System:metadata changes 先寫 log,crash 後可 recovery。
Transaction:一組 metadata updates,要嘛完成,要嘛回復。
Commit:transaction 已寫入 log,被視為成功。
Redo:重做 committed transaction。
Undo:撤銷未 committed transaction。
Checkpoint:縮短 log recovery 範圍。
Snapshot:某一時間點的 file-system view。
Backup / Restore:備份與還原資料。

15.5/15.8 ​

可以,最後整理 15.5 Virtual File Systems 跟 15.8 NFS。 這兩節在考古裡超像會考:VFS 架構圖、NFS 架構圖、RPC/XDR、mount protocol、file handle、stateless server 都很關鍵。課本 15.5 說 VFS 用來把不同 file-system implementations 整合在同一個目錄結構下;15.8 則說 NFS 透過 RPC/XDR,在異質機器與不同 file systems 間提供透明的遠端檔案存取。

text
15.5 Virtual File Systems

VFS(Virtual File System,虛擬檔案系統):
VFS 是作業系統中介於 system-call interface 與實際 file-system implementations 之間的抽象層。
它定義統一的 file-system interface,使不同類型的 file systems,
例如 local file system、remote file system、NFS,
都可以被整合到同一個 directory structure 中。

VFS Interface(虛擬檔案系統介面):
VFS interface 是 VFS 提供給不同 file-system implementations 實作的一組標準介面。
它把一般檔案操作,例如 open、read、write、close,
和底層不同 file system 的實作細節分離。

File-System Interface(檔案系統介面):
file-system interface 是使用者程式透過 system calls 看到的檔案操作介面。
它以 open()、read()、write()、close() 與 file descriptor 為基礎,
讓使用者不必知道底層是哪一種 file system。

File-System Implementation(檔案系統實作):
file-system implementation 是某種特定 file system 的實際底層程式碼。
例如 UNIX file system、FAT、NTFS、NFS client 等,都可以透過 VFS 介面接到 OS 中。

File-System-Generic Operations(檔案系統通用操作):
file-system-generic operations 是不依賴特定 file system 的一般操作。
VFS 會把這些通用操作與特定 file system 實作分離,
使同一個 system call 可以套用到不同 file systems。

Transparent Access(透明存取):
transparent access 是指使用者可以用相同方式存取不同種類的 file systems,
不需要知道檔案實際上位於 local disk、remote server,或其他 file system type。
例如 read() 對 local file 和 NFS remote file 都能使用同一個介面。

Multiple File-System Support(多檔案系統支援):
multiple file-system support 是現代 OS 同時支援多種 file systems 的能力。
VFS 的目的就是讓這些不同 file systems 可以共存在同一個 OS 與同一個 directory tree 中。

Vnode(Virtual Node,虛擬節點):
vnode 是 VFS 用來代表一個 active file 或 directory 的資料結構。
它提供 network-wide unique file representation,
也就是在網路檔案系統中,可以唯一表示某個 file。
UNIX inode 只在單一 file system 內唯一,而 vnode 可支援跨網路的唯一表示。

Active Node(活躍節點):
active node 是目前正在被 kernel 使用的 file 或 directory。
kernel 會為每個 active node 維護一個 vnode structure,
用來讓 VFS 追蹤與操作該 file 或 directory。

Network-Wide Unique File Representation(網路範圍唯一檔案表示):
network-wide unique file representation 是 VFS 支援 network file systems 所需的能力。
因為同一台機器可能掛載多個遠端 file systems,
所以 VFS 需要一種比本機 inode 更廣泛的方式唯一識別 file。

Local File System(本地檔案系統):
local file system 是資料實際存在本機 storage device 上的 file system。
在 VFS 架構中,local file system 只是 VFS interface 底下的一種 implementation。

Remote File System(遠端檔案系統):
remote file system 是資料實際存在遠端機器上的 file system。
使用者可透過 VFS 和 network protocol 存取它,就像存取本機檔案一樣。

Object-Oriented File-System Implementation(物件導向檔案系統實作):
object-oriented file-system implementation 是用物件導向方法組織 file-system code 的設計。
它讓不同 file system types 可以用相同抽象介面實作,
使 file-system code 更模組化、可擴充。

課本 15.5 特別強調 VFS 的兩個功能:第一,把 file-system-generic operations 和各 file system implementation 分離;第二,用 vnode 提供 network-wide unique file representation。

text
15.8 NFS

NFS(Network File System,網路檔案系統):
NFS 是一種分散式檔案系統協定,
讓 client 可以透過網路存取 server 上的 remote file system,
就像存取本機 file system 一樣。

DFS(Distributed File System,分散式檔案系統):
DFS 是讓多台機器透過網路共享檔案的 file system。
理想上,DFS 應該讓 client 不需要分辨 local file 和 remote file,
由系統負責定位檔案與傳輸資料。

Client(客戶端):
client 是發出檔案存取請求的機器。
在 NFS 中,client 會將 remote file system mount 到自己的 directory tree,
之後透過 NFS protocol 向 server 發出 file operations。

Server(伺服器):
server 是實際保存 exported file systems 的機器。
在 NFS 中,server 會提供遠端檔案存取服務,
並根據 export list 決定哪些 clients 可以 mount 哪些 directories。

NFS Client(NFS 客戶端):
NFS client 是 client 端 OS 中負責處理遠端 NFS 檔案操作的模組。
當 VFS 判斷某個 file 是 remote NFS file 時,
會呼叫 NFS client,再透過 RPC/XDR 將請求送到 server。

NFS Server(NFS 伺服器):
NFS server 是 server 端負責接收並處理 NFS RPC requests 的服務。
它會把收到的遠端操作重新導入 server 端 VFS,
再由本地 file system 執行真正的 file operation。

RPC(Remote Procedure Call,遠端程序呼叫):
RPC 是讓 client 像呼叫本機 procedure 一樣呼叫遠端 server procedure 的機制。
NFS 的 mount protocol 和 NFS protocol 都是用一組 RPCs 來描述,
RPC 是實作透明遠端檔案存取的基本 building block。:contentReference[oaicite:2]{index=2}

XDR(External Data Representation,外部資料表示法):
XDR 是一種系統無關的資料表示格式。
它負責讓不同 machine、OS、CPU architecture、byte order 的系統,
能用一致格式傳遞 RPC 的參數與回傳值。
NFS 透過 RPC primitives 搭配 XDR 達到異質系統間的相容性。:contentReference[oaicite:3]{index=3}

Heterogeneous Environment(異質環境):
heterogeneous environment 是指系統中有不同機器、不同作業系統與不同網路架構。
NFS 的設計目標之一,就是能在這種異質環境中運作。

Transparent Remote File Access(透明遠端檔案存取):
transparent remote file access 是指使用者以一般檔案操作方式存取遠端檔案,
不需要知道底層經過 network、RPC 或 remote server。
NFS 透過 mount protocol、NFS protocol、RPC/XDR 與 VFS 達成這種透明性。

Mount Protocol(掛載協定):
mount protocol 負責在 NFS client 和 server 之間建立初始 logical connection。
client 會指定要掛載的 remote directory 與 server machine;
server 檢查 export list 後,若允許,就回傳 file handle 給 client。

NFS Protocol(NFS 協定):
NFS protocol 提供一組 RPCs,用來執行 remote file operations。
它支援在 directory 中搜尋 file、讀取 directory entries、操作 links/directories、
存取 file attributes,以及讀寫 files。:contentReference[oaicite:4]{index=4}

Export List(匯出清單):
export list 是 server 維護的一份清單,
記錄哪些 local file systems 或 directories 可以被遠端 mount,
以及哪些 client machines 被允許 mount。
它也可以指定 access rights,例如 read-only。:contentReference[oaicite:5]{index=5}

Exported File System(匯出的檔案系統):
exported file system 是 server 允許 client 遠端掛載的 local file system。
client 只有符合 server export list 的授權條件,才能 mount 其中的 directory。

Component Unit(組成單位):
component unit 是 exported file system 中可被遠端 mount 的 directory。
課本指出,exported file system 裡的任何 directory 都可以被 accredited machine 遠端 mount。

Accredited Machine(已授權機器):
accredited machine 是 server export list 中被允許 mount 某個 exported file system 的 client machine。
只有這類 client 的 mount request 會被 server 接受。

File Handle(檔案控制代柄 / 檔案句柄):
file handle 是 server 在 NFS mount 成功後回傳給 client 的識別資訊。
它是 client 後續存取 mounted file system 的 key。
在 UNIX terms 中,file handle 通常包含 file-system identifier 與 inode number,
使 server 能辨識 exported file system 中的特定 directory 或 file。:contentReference[oaicite:6]{index=6}

File-System Identifier(檔案系統識別碼):
file-system identifier 是 file handle 的一部分,
用來指出某個 file 屬於哪一個 file system。
它和 inode number 搭配,可讓 server 唯一辨識檔案。

Inode Number(inode 編號):
inode number 是 UNIX file system 中識別某個 inode 的編號。
在 NFS file handle 中,inode number 可用來指出 exported file system 內的特定 file 或 directory。

Stateless Server(無狀態伺服器):
stateless server 是指 server 不保留 client 前後兩次 access 之間的狀態。
NFS server 不維護類似 UNIX open-file table 或 file pointer 的 client 狀態;
每個 request 都必須帶完整參數,例如唯一 file identifier 與 file offset。:contentReference[oaicite:7]{index=7}

Idempotent Operation(冪等操作):
idempotent operation 是同一個操作執行多次,效果與只執行一次相同的操作。
因為 NFS server 是 stateless,為了 crash recovery 與 request retransmission,
NFS file operations 需要具有 idempotent 特性。:contentReference[oaicite:8]{index=8}

Sequence Number(序號):
sequence number 是 NFS request 中用來判斷 request 是否重複或遺漏的資訊。
它協助 server 判斷 client 的 request 是否已經被處理過,
以支援 idempotent operation。

Synchronous Write(同步寫入):
synchronous write 是 server 必須在將 modified data 寫到 disk 後,
才把結果回傳給 client 的寫入方式。
NFS 因為 stateless server 與 RPC synchrony,server 必須同步寫入資料,
使 server crash and recovery 對 client 幾乎不可見。:contentReference[oaicite:9]{index=9}

Nonvolatile Cache(非揮發性快取):
nonvolatile cache 是斷電後仍可保留資料的快取,通常由電池備援記憶體提供。
它可以讓 storage controller 很快回應 synchronous write,
同時確保 crash 後資料仍能安全寫回 disk。

Atomic Write Procedure Call(原子寫入程序呼叫):
NFS 保證單一 NFS write procedure call 是 atomic,
也就是不會和對同一 file 的其他 write calls 交錯混合。
但一個 write() system call 可能被拆成多個 NFS RPC writes,
所以多個 users 同時寫同一 remote file 時,資料仍可能交錯。

Concurrency Control(並行控制):
concurrency control 是處理多個 clients 同時存取或修改同一 file 的控制機制。
NFS protocol 本身不提供完整 concurrency-control mechanisms;
因為 lock management 是 stateful,通常需要由 NFS 之外的服務提供 locking。:contentReference[oaicite:10]{index=10}

NFS Architecture(NFS 架構):
NFS architecture 是 client 與 server 透過 VFS、NFS client/server、RPC/XDR 和 network 連接的架構。
client 的 system call 會被轉成 VFS operation;
VFS 若判斷是 remote file,會呼叫 NFS procedure,
再透過 RPC/XDR 傳到 server,server 再經由自己的 VFS 呼叫 local file system。:contentReference[oaicite:11]{index=11}

Path-Name Translation(路徑名稱轉譯):
path-name translation 是將 path name 拆成多個 directory components 並逐步查找的過程。
在 NFS 中,跨過 mount point 後,每個 component lookup 都可能造成一次獨立 RPC 到 server。:contentReference[oaicite:12]{index=12}

Lookup Call(查找呼叫):
lookup call 是 NFS 在 path-name translation 中,
針對某個 directory vnode 與 component name 發出的 RPC。
每解析一層路徑,就可能需要一次 lookup call。

Cascading Mounts(串接掛載):
cascading mounts 是指 mount 的 remote file system 內部又掛載了另一個 file system。
NFS 允許 file systems of different types both locally and remotely mounted,
因此可能形成多層掛載關係。
text
15.5~15.8 最後速背版

15.5:
VFS:Virtual File System,統一不同 file systems 的抽象層。
VFS Interface:讓不同 file-system implementations 都接到同一個 OS 介面。
Vnode:Virtual Node,VFS 用來代表 active file/directory 的結構,可支援 network-wide unique file。
Transparent Access:local file 和 remote file 用同一套 system calls 操作。
Remote File System:資料在遠端,但透過 VFS 看起來像本機檔案。

15.8:
NFS:Network File System,透過網路存取遠端 file system。
RPC:Remote Procedure Call,讓 client 呼叫 server 上的遠端程序。
XDR:External Data Representation,跨機器、跨 OS 的標準資料表示格式。
Mount Protocol:建立 client 與 server 的初始 logical connection。
NFS Protocol:真正執行 remote file operations 的 RPC 集合。
Export List:server 記錄哪些 directories 可被哪些 clients mount。
File Handle:server 回傳給 client 的遠端檔案識別 key。
Stateless Server:server 不保存 client 的 open-file state,每次 request 都要帶完整資訊。
Idempotent Operation:重複執行多次效果仍等同一次,方便 crash recovery。
Synchronous Write:server 寫入 disk 後才回覆 client。
NFS Architecture:client system call → VFS → NFS client → RPC/XDR → network → NFS server → VFS → local file system。
Path-Name Translation:路徑拆成 components,一層一層 lookup;跨 NFS mount 後 lookup 會變成 RPC。