Linux 核心設計: 檔案系統概念及實作手法 === :::warning 注意!這是上課筆記 ::: :::info 原始課程在這裡 - [影片 Part 1](https://www.youtube.com/watch?v=d8ZN5-XTIJM) - [影片 Part 2](https://www.youtube.com/watch?v=BCPe0EICfwI) - [講義](https://hackmd.io/@sysprog/linux-file-system) Original by [jserv](http://wiki.csie.ncku.edu.tw/User/jserv) ::: --- # Part 1 | Section | Time| Description | | -------- | -------- | -------- | | 1 | [00:00:34](https://www.youtube.com/live/d8ZN5-XTIJM?si=0JVbYTwKrpPzneQA&t=34) | 1. 課程大綱。<br> 2. FUSE: Filesystem in Userspace.<br> 3. UNIX v1.<br> 4. Unix 歷史的重要性。 | | 2 | [00:22:25](https://www.youtube.com/live/d8ZN5-XTIJM?si=RgeitFfnldmCYjeY&t=1345) | 1. Unix 第一版的系統呼叫。<br>2. Universal I/O Model: open/read/write/close.<br> 3. BSD 與 Unix 的關聯。 | | 3 | [00:34:51](https://www.youtube.com/live/d8ZN5-XTIJM?si=URP-q3lkZbU3ZEvR&t=2091) | 1. Everything is a file descriptor.<br> 2. eventfd: event notification.<br> 3. timerfd: for timers.<br> 4. signalfd: accepting signals.<br>5. Plan 9 and KVM.| | 4 | [00:53:26](https://www.youtube.com/live/d8ZN5-XTIJM?si=-FgmtDz77dVIhPs_&t=3206) | 1. virtio.<br> 2. Plan 9 投影片。<br> 3. File Descriptor: open file table / I-node table.<br> 4. dup / dup2 / dup3: duplicate the file descriptor.<br> 5. vim 的保護機制。| | 5 | [01:11:10](https://www.youtube.com/live/d8ZN5-XTIJM?si=qwHtho_qbmlbSE5t&t=4270) | 1. Blocking I/O Model.<br> 2. I/O multiplexing: select(). | | 6 | [01:22:00](https://www.youtube.com/live/d8ZN5-XTIJM?si=CyMuvvw8-h1LphBp&t=4920) | 1. select().<br> 2. Linux 的設計哲學:簡單非簡陋。<br> 3. 使用 multi-threading 會讓系統變複雜。<br> 4. sehttpd: 高效能 Web 伺服器開發。 | | 7 | [01:41:30](https://www.youtube.com/live/d8ZN5-XTIJM?si=V4qX_983Gf8pFlPS&t=6090) | 1. timerfd 處理週期性任務。<br> 2. Linux virtual file system 介面。| | 8 | [01:51:50](https://www.youtube.com/live/d8ZN5-XTIJM?si=tdcRbFB5Oz-OlSnD&t=6710) | 1. eventfd.<br> 2. VFS 支援各種 file system。<br> 2. superblock / inode / dentry / file. | | 9 | [02:05:42](https://www.youtube.com/live/d8ZN5-XTIJM?si=7Ot3cUVZaQbq-nbU&t=7542) | 1. 投影片 “Virtual File System”.<br> 2. virtual and pseudo 差別。<br> 3. tmpfs.<br> 4. mount loopback.<br> 5. loopback device: simplefs. | | 10 | [02:24:00](https://www.youtube.com/live/d8ZN5-XTIJM?si=jq-kD0Q52h67T8k5&t=8640) | 1. FS developer's perspective: in-memory objects.<br> 2. linux kernel livepatch.<br> 3. Core VFS abstraction.<br> 4. fseek(高階) / lseek(低階)。<br> 5. super block object. | | 11 | [02:41:00](https://www.youtube.com/live/d8ZN5-XTIJM?si=Amyg2HnmPTIvT7pS&t=9660) | 1. Linking and unlinking 的意義。<br> 2. soft link / hard link<br> 3. Special bits.<br> 4. security sticky bit file system.<br> 5. dup: copy a file handle. # Part 2 | Section | Time| Description | | -------- | -------- | -------- | | 1 | [00:01:28](https://www.youtube.com/live/BCPe0EICfwI?si=dXL5DmPO4bd2WES8&t=88) | 1. 前情提要。<br> 2. USB composite device.<br> 3. VFS 的重要性。<br> 4. block size alignment. | | 2 | [00:13:40](https://www.youtube.com/live/BCPe0EICfwI?si=72_dx6Fi20J4FiJh&t=820) | 1. Network FS: NFS, samfs, ceph, coda.<br> 2. docker overlayfs.<br> 3. ecryptfs: 架在 ext4 上的檔案系統,用於加解密資料。<br> 4. unionfs: live CD. | | 3 | [00:28:30](https://www.youtube.com/live/BCPe0EICfwI?si=MBCCshopCSHQybpF&t=1710) | 1. OSDI / SOSP: 作業系統的奧斯卡。<br> 2. 小檔案存取的檔案系統。<br> 3. file system scalability. | | 4 | [00:36:15](https://www.youtube.com/live/BCPe0EICfwI?si=AbHQSs36Bf8ePHk4&t=2175) | 1. vfs mount: 掛載資訊。<br> 2. 物件以及物件導向的差別。 | | 5 | [00:48:48](https://www.youtube.com/live/BCPe0EICfwI?si=lWmUir9UhFCjrEKA&t=2928) | 1. 房仲物件的概念。<br> 2. dentry and inode object.<br> 3. block access.<br> 4. NOR/NAND flash 也是 block access. | | 6 | [01:01:43](https://www.youtube.com/live/BCPe0EICfwI?si=Seuivk9ALVMnSjHn&t=3703) | 1. Inode Stats.<br> 2. 利用八進位描述檔案系統的權限。<br> 3. man 2 stat.<br> 4. struct stat. | | 7 | [01:11:15](https://www.youtube.com/live/BCPe0EICfwI?si=pT3KHWMP10yd_MNj&t=4275) | 1. File objects.<br> 2. fork() 之後 file mapping 會變成獨立的兩份。<br> 3. Everything is a file descriptor.<br> 4. File descriptor table, open file table, I-node table.<br> 5. dup: duplicate a file descriptor. | | 8 | [01:26:38](https://www.youtube.com/live/BCPe0EICfwI?si=acbbMM8km8kHJaoO&t=5198) | 1. reference count.<br> 2. dup and dup2.<br> 3. man 2 seek / lseek. | | 9 | [01:43:32](https://www.youtube.com/live/BCPe0EICfwI?si=p06nJmAnuGFlxgjn&t=6212) | 1. fcntl system call.<br> 2. CLOSE_ON_EXEC.<br> 3. How does an editor save a file? | | 10 | [02:00:18](https://www.youtube.com/live/BCPe0EICfwI?si=w2TLIf6Wdo_QaGPL&t=7218) | 1. mazu-editor.<br> 2. Dentry caching.<br> 3. 磁帶機。<br> 4. Dentry tracking. | | 11 | [02:15:02](https://www.youtube.com/live/BCPe0EICfwI?si=MbfSsFjw_7bA6jME&t=8102) | 1. include/linux/fs.h<br> 2. fibdrv.<br> 3. include/linux/cdev.h<br> 4. kernel 物件導向程式設計。 | | 12 | [02:35:52](https://www.youtube.com/live/BCPe0EICfwI?si=DdM1o15MJ0IMkENl&t=9352) | 1. 依循 VFS 的檔案系統實作。<br> 2. fsck: 修正檔案系統。<br> 3. Journaling: 降低 fsck 的成本, keep a log of what you were doing. | | 13 | [02:47:48](https://www.youtube.com/live/BCPe0EICfwI?si=mVz6vT2d9-q6HIW0&t=10068) | 1. Undo and redo logging.<br> 2. Atomicity.<br> 3. fsync.<br> 4. Batching.<br> 5. JBD: Journaling Block Device.<br> 6. COW: Copy-On-Write. | | 14 | [02:56:43](https://www.youtube.com/live/BCPe0EICfwI?si=KFd5ld7N6-3dmo0a&t=10603) | 1. Linux Scalability 議題。<br> 2. vfsmount scalability problem.<br> 3. spin lock 的代價很高。 | | 15 | [03:11:14](https://www.youtube.com/live/BCPe0EICfwI?si=UWfk23o4g_yJyO6d&t=11474) | 1. 如何提高 scalability? 先找 local 再找 global。<br> 2. Encrypted File System.<br> 3. Netflix File system: Mezz FS.<br> 4. file sharing: virtio fs.<br> 5. vramfs: video RAM 轉為存儲裝置。<br> 6. simplefs: 自行開發的檔案系統。