Plan 9 from Bell Labs

Plan 9 System (Bell Lab) 硬件设备 目标环境: 便宜的小型机(办公室个人使用)+ 集中管理的大型服务器(file server, cpu server) 分布式环境设计, 强调网络互联和资源共享 UTF-8 /proc rfork 硬件存储抽象 软件文件系统抽象 包括网络的分布式一致性 创新点 设计目标 maintainence: 分布式的个人 pc 进行 administer 一个系统的开销太大太困难了 也就是通过 centralized administration 来实现集中管理 统一接口: 一切皆文件, 通过 9P 协议访问 每个进程拥有独立的命名空间, 可通过 bind 和 mount 重新组合 支持透明分布式: 远程资源与本地资源无差别 简洁内核, 核心任务是 9P 消息的 multiplex/demultiplex ...

2025-09-13 · 2 min · Yuchen You

The Performance of μ-Kernel-Based Systems

Motivation 和论文目标 守旧派往往认为, 第一代 $\mu$-kernel 微内核具有非常低的 performance/flexibility, 但是本文希望能测试第二代微内核的性能和灵活性, 实验手段是测试一些老的系统性能测试以及加上一些新的有针对的测试 微内核的优点之一是, 内核小巧, 部件坏的概率小 微内核只提供 mechanism 但是不提供 policy, 但是也需要上面一层安全控制的 pager, FS 等资源, 这些往往依赖于 UNIX Server 实现 ...

2025-09-08 · 3 min · Yuchen You

7. Gray Failure the Achilles' Heel of Cloud-Scale Systems

Introduction 这篇文章系统性地提出并定义了云计算系统中的"灰色故障"(Gray Failure)问题, 认为它是当前云基础设施高可用性的一大障碍 gray failure component failures whose manifestations are fairly subtle and thus defy quick and definitive detection 系统某部分发生了轻微但持续的问题, 这些问题不易被传统故障检测机制发现, 但已经影响了应用层的性能和可用性;它不同于"失败即停" (fail-stop) 故障, 后者更易被监测和处理 ...

2025-06-01 · 2 min · Yuchen You

6. Fail Stutter Fault Tolerance

Introduction 背景问题缺陷 Byzantine 模型假设组件可能出现任意错误甚至恶意行为, 过于复杂难以实施; Fail-stop 模型假设组件要么正常工作, 要么完全停止, 虽然简单易用, 但忽视了现代硬件中常见的"性能故障"; 本文特点 Fail-Stutter 模型: a realistic and yet tractable fault model that accounts for both absolute failure and a new range of performance failures common in modern components. ...

2025-05-31 · 6 min · Yuchen You

5. Fail-Slow at Scale

Introduction 这篇论文 Fail-Slow at Scale: Evidence of Hardware Performance Faults in Large Production Systems 由Haryadi S. Gunawi等人发表在第16届USENIX文件与存储技术会议(FAST 2018)上 系统性地揭示了在大规模生产系统中"fail-slow"(故障-缓慢)硬件现象的存在与影响;这类故障指的是硬件仍在运行, 但其性能严重退化, 未达到应有的标准; ...

2025-05-27 · 13 min · Yuchen You

3. Metastable Failures in Distributed Systems

Introduction metastable failures 亚稳态故障 a failure pattern in distributed systems Currently, metastable failures manifest themselves as black swan events(黑天鹅事故) they are outliers(异常事故) because nothing in the past points to their possibility have a severe impact much easier to explain in hindsight(事后) than to predict. Although instances of metastable failures can look different at the surface, deeper analysis shows that they can be understood within the same framework. By reviewing experiences from a decade of operating hyperscale distributed systems, we identify a class of failures that can disrupt them, even when there are no hardware failures, configuration errors, or software bugs. ...

2025-05-22 · 4 min · Yuchen You

4. Metastable Failures in the Wild

Introduction 这篇文章是基于 MetaStable Failures in Distributed Systems 的升级, in the wild 指的是不可控的实际世界 In this work, we study the prevalence(患病率) of such failures in the wild by scouring(冲刷) over publicly available incident reports from many organizations, ranging from hyperscalers to small companies In this paper, we make four contributions that extend the work of Bronson et al. and increase our understanding of metastable failures: A study of metastable failures in the wild that confirms metastable failures are universally observed and comprise a substantial fraction of the most severe outages (Section 2). An improved model that categorizes two types of triggers and two types of amplification mechanisms, which better explains how metastable failures happen (Section 3). An insider view at Twitter of a new type of metastable failure where garbage collection acts as an amplification mechanism (Section 4). Three example applications on which metastable failures are experimentally reproduced, which helps researchers propose and test solutions to metastable failures (Section 5). Metastability in the Wild 这一段主要讲了作者对近年来各大小厂的故障并且进行了原因分析和类型总结概括: ...

2025-05-22 · 5 min · Yuchen You

6. File System

文件系统抽象 File System Abstraction attribute Hardware Reality OS abstraction interface heterogeneous uniform storage objects a few (disks) many (files) name structure simple numeric name (id) rich name (symbolic, hierarchical, unified) access speed slow fast crash resilience unreliable reliable 硬件层到 os 的转变方式 Heterogeneity 原因: many i/o devices, each with its own idiosyncrasy Solution: abstraction build a common interface (Application 层和 File System 层之间设置统一接口 POSIX) write device driver for each device Linux src code 70% is drivers Disk interface 硬件接口表现为 linear array of sectors (扇区) 扇区为最小的物理存储单位, 每个扇区为512字节 (typically) write atomically, 要么全部写入要么全部没有写入 4KB in advanced format disk disk 会将逻辑 sector 映射到物理 sector 逻辑 sector: 由 OS 决定 物理 sector: 由 disk 决定 os 不知道 mapping 机械硬盘结构 Disk Geometry/Structure Platter: 磁盘盘片 Data is stored by inducing magnetic changes to it Each platter has 2 sides, each called a surface Spindle: 磁盘主轴 围绕 spindle 旋转 Spindle rotates the platters at a constant speed (unit RPM) Track: 磁道 A circular path on a platter (Concentric circles of sectors) All tracks at the same distance from the spindle form a cylinder 每个 surface 包含上千个 track Cylinder: 柱面 A stack of tracks of fixed radius Heads record and sense data along cylinders (不同层的head指向同一个 xy 坐标位置) Generally only one head active at a time 分区的最小单位 ext2 文件系统分区结构体: struct partition{ u8 drive; // 0x80 u8 head; u8 sector; u8 cylinder; u8 sys_type; //分区类型 5为扩展分区 u8 end_head; u8 end_sector; u8 end_cylinder; u32 start_sector; //起始扇区开始计数的第n个扇区 u32 nr_sectors; //分区中的扇区个数 } 磁盘分区是告诉操作系统"我这块磁盘在此分区可以访问的区域是A柱面到B柱面之间的块", 这样操作系统就知道它可以在所指定的块内进行文件数据的读, 写, 查找等操作;磁盘分区即指定分区的起始与结束柱面 机械硬盘访问 disk 的方式 流程: Seek, Rotate, Transfer Seek: 移动磁头到指定 track 花费时间: 1-10ms 是一个物理运动过程, 很难减少时间 Rotate: 等待 disk 旋转到读写头的位置上 花费时间: 取决于 rpm 转速, 一般 $(rpm/2)^{-1}$ 用来表示平均等待时间 Transfer: 读写数据 最终的 io 操作 非常快, 依赖于 rpm 和 sector density 能达到 100 MB/s 的最大传输速度 优化 i/o 性能 General Strategy Avoid doing I/O (disk is slow) 方法: 使用 write-back cache Reduce overhead (particularly seek time) 放置数据的位置很重要 disk 角度要用更好的 scheduler 来改变内存访问顺序 Amortize overhead over larger requests Disk Scheduling FIFO: 容易出现左右不断摇摆的情况, 读写头路程过大 SSTF (Shortest seek time first): 选取距离目前读写头最近的 track 访问 优点: 减少 seek time 缺点: 会导致 starvation SCAN: 电梯调度算法 Sweep across disk, servicing all requests passed Like SSTF, but next seek must be in same direction Switch directions only if no further requests 优点: 避免 starvation 缺点: 会导致某些 track 无法访问 CSCAN: only sweep in one direction Amortizing Overhead: Efficiency = transfer time / (overhead + transfer time) 为了达到 50% efficiency, 固态硬盘的结构 Solid State Disk (SSD, flash memory) Increasing popular storage medium remembering data by storing charge Low power consumption No mechanical seek time (better random read performance) Better shock resistance (抗冲击性) limited times of overwrite possible limited durability ...

2025-03-26 · 12 min · Yuchen You

5. 内存空间抽象 Address Space

地址空间与抽象 Address Space and Abstract os视角: 地址空间是在 process 内部的用于不同进程之间对物理内存高效, 安全访问的一种抽象方式; Process = one or more threads running in an address space; 组成: 包括 code, data, heap, stack Phisical Machine Interface: 多个任务共享同一个物理内存, 比如一个 config 文件 Virtual Machine Interface: 每个任务有独立的虚拟内存空间 地址空间抽象的三条准则 Address Space Independence: Protection (controlled isolation): Large Address Space: 单进程执行缺陷 多个进程执行 动态地址翻译 Dynamic Address Translation Method 1: Base + Bound 机制 优点 缺点 Method 2: Segmentation Method 3: Paging 页地址转换方式 页替换基础(Page Replacement Basics) 触发条件: 当发生页错误(Page Fault)且物理页框(Page Frame)已满时, 需选择牺牲页(Victim Page)替换; 目标: 最小化页错误率(Page Fault Rate), 提升虚拟内存(Virtual Memory)性能; 关键概念: 局部性原理(Locality): 时间局部性(Temporal Locality): 近期访问的页可能再次被访问; 空间局部性(Spatial Locality): 邻近地址的页可能被连续访问; 页替换算法(Page Replacement Algorithms) 1. 先进先出(First-In First-Out, FIFO) 机制: 淘汰最早进入内存的页; 缺陷: Belady异常(Belady’s Anomaly): (主要是fifo情况会导致)增加num of page in memory 可能增加 page fault; 2. 最优替换(Optimal Replacement, OPT) 机制: 淘汰 未来 最长时间不被访问的页(需预知未来访问序列); 困难: 很难预知未来访问模式, 仅作为理论基准; 意义: 作为理论 opt 基准(Yardstick)评估其他算法; 3. 最近最少使用(Least Recently Used, LRU) 机制: 淘汰最久未被访问的页, 基于最优 temporal locality, 对比 opt 更加展现过去的访问模式; 最不利于 lru 算法的访问顺序: 正序访问一个大于物理内存大小的page array, 使得每次访问都需要替换一个页; Implement Problem: 记录每次调用的时候的 cpu 时间, evict 的时候找到时间最老的 page: 占用内存更大, 且 Scanning 所有优先级的时间开销很大; 使用一个 doubly-linked list, 每次访问将当前 node 放到尾部: 内存开销很大 4. 时钟队列算法(Clock Queue Algorithm) MMU 存储每个 page 的访问位(Accessed/Referenced Bit); evict 未被访问的页(ref=0), 访问过的页 ref = 0 并跳过(防止死循环); 二次机会(Second-Chance): 别称 evict 页处理 data 写回? 可能有 write-back 和 write-through 策略; write-back: 仅dirty页且非swap数据页需写回, 需要额外记录 dirty-bit 页替换优化(Optimizations) 脏位管理(Dirty Bit Management): 脏位(Dirty Bit): 标记页是否被修改, 或者说内存中的数据和磁盘中的数据是否一致; 写回策略(Write-Back): 仅脏页需写回; 硬件支持: 访问位(Accessed Bit): 由内存管理单元(MMU)自动更新, 用于近似LRU; 页表项(Page Table Entry, PTE): 包含物理页号, 有效位(Valid), 驻留位(Resident), 保护位(Protection), 脏位(Dirty), 访问位(Accessed); pte 优化策略 valid: mmu 可以不用保存 valid bit, 而由 os (Pager) 根据 r/w 权限来判断是否 valid, 即将 invalid page 标记为 non-resident, 只需要判断是否 resident 就行; resident: mmu 可以不用保存 resident bit, 而由 os (Pager) 根据 r/w 来判断是否 resident, 即将 non-resident 标记为 r=0, w=0, 只需要判断是否 resident 就行; dirty: mmu 可以不用保存 dirty bit, 而由 os (Pager) 自行记录是否 dirty 就可以, 即将每次写入的 page 标记为 dirty ref: mmu 可以不用保存 ref bit, 而由 os (Pager) 自行记录是否 accessed 就可以, 即将每次访问的 page 标记为 accessed 算法对比与选择 算法 优点 缺点 FIFO 实现简单 Belady异常, 忽略访问模式 OPT 理论最优 不可实现(需预知未来) LRU 近似OPT, 利用时间局部性 实现开销大, 需硬件支持 时钟算法(Clock) 低开销, 近似LRU 可能淘汰频繁访问页(循环扫描)

2025-03-11 · 3 min · Yuchen You

4. 死锁 Deadlock

死锁简介 (Introduction to Deadlock) 定义 (Definition): 线程因循环等待资源 (Cyclical Resource Waiting) 而无限期阻塞的状态. 为了确保程序合理运行的必要条件: 安全性 (Safety): 所有操作必须正确 (避免非法交错). 活性 (Liveness): 操作必须持续进行; 死锁违反活性. Fix Attempts Ignore: 1. 0S会自己完成的; 2. 这个方法占用cpu时间为0; Detect and Fix: Kill the deadlock threads:会导致一定!的 invariant条件破裂 Rollback actions and then try again:某些指令如 output 并不能 roll back Prevent: 得知道有哪些造成 deadlock 的必要条件 等待图 (Wait-for Graph): 顶点 (Vertices): 线程和资源. 边 (Edges): 线程 → 资源 (线程等待资源). 资源 → 线程 (资源被线程持有). 循环检测 (Cycle Detection): 图中存在循环即表明死锁. 死锁的构成要素 (Components of Deadlock) 有限资源 (Limited Resources): 线程所需的实体 (如锁 Locks, CPU, Memory). 不可剥夺 (No Preemption): 不能强制线程放弃资源. Preemption: no indefinite waiting, 系统不能强制从资源占有者处释放资源 获取且等待 (Hold and Wait): 线程持有资源同时等待其他资源. 循环等待 (Circular Wait): 线程A等待线程B, 线程B等待线程C, 线程C等待线程A. Fix Attempts Limited Resources: increase the number of resources No Preemption: Enable preemption, Hold and Wait: 1. Move the resources acquisition to the first step; 2. Acquire all the resources atomically, if not, release all its resources and retry 仍然会导致问题: 如果对于中间用户左右资源被左右用户轮流占用,则中间用户本身也无法获取资源. 解决方案: 定义一个 Global Ordering 来规定资源的获取顺序. ...

2025-02-18 · 3 min · Yuchen You

3. 信号量 Semaphore

信号量基础 (Semaphore Basics) 定义 (Definition): 一种抽象的整数计数器 (Integer Counter), 用于控制多线程对共享资源的访问. 核心操作 (Core Operations): down() (或 P()/wait()): 原子性地减少计数器值; 若值为0则阻塞线程. up() (或 V()/signal()): 原子性地增加计数器值; 唤醒等待的线程. 类型 (Types): 二进制信号量 (Binary Semaphore): 值仅0或1, 初始化为 1 的情况下等效于锁 (Lock). 计数信号量 (Counting Semaphore): 值可为任意非负整数, 表示资源的可用数量. 信号量的应用场景 (Applications of Semaphores) 互斥 (Mutual Exclusion): semaphore sem(1); sem.down(); // 临界区 (Critical Section) sem.up(); 顺序约束 (Ordering Constraints): 例如确保线程A先执行任务再启动线程B, 功能类似cv: semaphore sem(0); // 线程A taskA(); sem.up(); // 线程B sem.down(); taskB(); ...

2025-02-18 · 3 min · Yuchen You

2. 线程调度的实现

Resource Acquisition Is Initialization (RAII) Resource 资源 定义: 持有价值昂贵的,可以被获取和释放的对象为资源,常见的有 Memory, Mutex, File Lifetime 生命周期 一个变量通过调用构造函数来实现 introduction 和 initialization 在退出 {} 的时候,系统会按照与定义相反的方向进行析构函数 RAII 定义: 利用变量的生命周期来实现资源的构造和析构管理 ...

2025-02-09 · 4 min · Yuchen You