目录
正在加载目录…
正在阅读专栏 OSTEP 操作系统专栏 第 61 篇 · 共 62 篇 · 98%

OSTEP:Laboratory:Systems Projects

发布于 2026-09-17 21:42 · 最后编辑于 2026-09-17 22:08 · 版本 v2 · 字数 5,602 · 预计阅读 12 分钟 👁 20 次阅读

OSTEP:Laboratory:Systems Projects

本篇对应 OSTEP Version 1.10 的 Appendix G “Laboratory: Systems Projects”。它给出与 OSTEP 主线配套的 Linux/C systems programming project ideas。

类型与定位

  • 笔记类型:实验项目翻译/知识整理
  • 翻译基准:官方 Laboratory: Systems Projects
  • 保真约定:项目名称、API、测试工具与 repository 地址保留原样;每项记录目标、核心知识和对应章节。
  • 图件说明:原文没有独立图片。

目录

章节内容
项目安排semester 结构、分组、评分和官方仓库
项目清单八类 systems projects 总览
Intro Projectsort utility 与 systems programming 入门
UNIX Shellprocess、pipe、redirection 与 batch
Memory-allocation Librarymmap()、free list 与 allocator policies
Intro to ConcurrencyPOSIX threads、locking 与 scalability
Concurrent Web Serverthread pool、bounded buffer 与 worker
File System Checkeron-disk structure 与 consistency
File System Defragmenterlayout、fragmentation 与 performance
Concurrent File Servernetwork、file system 与 concurrency
项目验收reproducibility、corner cases 与 measurement
当前撰写与执行记录各项目当前状态
已执行的材料级验证baseline build 与缺失实现说明

项目安排

官方项目会逐步加入 ostep-projects,其中包含 project descriptions 和一个简单的 testing framework;如果要实际完成这些 projects,应以该仓库和 book web page 的最新说明为准。

一个 15-week semester 通常安排约 6–7 个 project,平均每两周一个。前几个 project 通常由单人完成,后几个可以由两人合作完成。每个 semester 的总体 outline 大致相同,但 project 细节会被调整,让课程保持新鲜,也让跨 semester “sharing” code 更困难(当然,没人会这么做!)。原课程还会使用 Moss tool [M94] 检查这类 code sharing。

评分可以使用 demo 或 automated test scripts:

  • demo 直观但耗时;
  • automated tests 节省时间,但必须认真覆盖 corner cases;
  • 如果需要 automated test scripts,应查看 book web page 或官方项目仓库的说明。

项目清单

项目核心任务主要对应
Intro Project实现 sort utility 的变体system call、error code、data structure
UNIX Shell实现 shell 变体process、pipe、redirection、batch
Memory-allocation Library实现 malloc/free 风格 allocatormmap、pointer、free list、fit policy
Intro to Concurrency实现 thread-safe list/hash tablePOSIX threads、locks、scalability
Concurrent Web Server为 web server 加 thread poolproducer/consumer、bounded buffer
File System Checker检查并修复 file-system imageon-disk structure、consistency
File System Defragmenter重新布局 fragmented imagefile-system layout、performance
Concurrent File Server实现类似 NFS 的 file serverconcurrency、network、file system

Intro Project

第一个 project 是 systems programming 的入门。常见任务是实现 sort utility 的不同变体,并施加不同 constraints:

  • sort text data;
  • sort binary data;
  • 处理不同 input/output 约束;
  • 使用 system call 及其 return error code;
  • 使用简单 data structure。

例如,sorting text data、sorting binary data,以及其他类似但有不同约束的任务都很合适。完成它不需要太多额外内容,但必须熟悉一些 system calls 及其 return error codes,并能使用少量简单 data structures。

UNIX Shell

实现 UNIX shell 的变体,理解:

  • process creation 与 process management;
  • pipe 如何连接 process;
  • redirection 如何改变 file descriptor;
  • batch mode 如何一次处理多项 request;
  • 不同 scheduling discipline 的实验变体。

项目也可以加入不寻常的 feature,例如某种同时通过 gzip 压缩 output 的 redirection symbol;另一种 variant 是 batch mode:先收集若干 requests,再执行它们,甚至使用不同 scheduling disciplines。

重点不是复制 shell,而是把 OSTEP:Process API 中的 fork/exec/wait/redirection 变成可运行系统。

Memory-allocation Library

使用 mmap 获取 anonymous memory,构建另一个 allocator:

  • free list;
  • pointer arithmetic;
  • chunk header;
  • split/coalescing;
  • best fit、worst fit、buddy 等 policy;
  • throughput 和 fragmentation 测量。

这个 project 的变体包括 best fit、worst fit、buddy 以及其他 allocators。

这个 project 直接对应 OSTEP:Free-Space Management。

Intro to Concurrency

使用 POSIX threads 构建 thread-safe library,例如:

  • linked list;
  • hash table;
  • 更复杂的 concurrent data structure;
  • coarse-grained 与 fine-grained locking 对比;
  • correctness 与 performance measurement。

不同 variant 也可以聚焦于不同、甚至更复杂的 concurrent data structures。

Concurrent Web Server

给简单 web server 添加 fixed-size thread pool:

mermaid
flowchart LR
  A[Main thread] --> B[Bounded buffer]
  B --> C[Worker thread 1]
  B --> D[Worker thread 2]
  B --> E[Worker thread N]
  C --> F[Serve request]
  D --> F
  E --> F

main thread 接收 request,放入 producer/consumer bounded buffer;worker threads 从 queue 取 request 并发处理。这个 project 综合 threads、locks、condition variables 和真实 application design。

thread pool 应当是 fixed-size;variant 还可以为这些 threads 加入不同的 scheduling policies。

File System Checker

针对真实 file-system image:

  • 使用 debugfs 等工具创建或操作 image;
  • 遍历 on-disk data structures;
  • 检查 pointer、link count、indirect block 等一致性;
  • 发现问题后尝试修复。

它对应 OSTEP:Crash Consistency:FSCK 与 Journaling 与 OSTEP:Data Integrity and Protection。

File System Defragmenter

输入包含已知 fragmentation 问题的 file-system image:

  1. 遍历 image;
  2. 找出未 sequentially laid out 的 file;
  3. 生成新的 defragmented image;
  4. 报告 layout 和 performance statistics。

该 project 将 file-system implementation 与 disk access performance 联系起来。

Concurrent File Server

构建一个简单的 concurrent file server,protocol 可以类似 NFS:

  • lookup;
  • read;
  • write;
  • stat;
  • 多个 client 并发访问;
  • file 存储在单一 disk image 中;
  • 设计 on-disk format 和 network protocol。

它综合 concurrency、file system 和 distributed systems,是 systems projects 的高阶收束项目。

项目验收

  • [ ] 每个 project 固定 source version、compiler 和运行环境;
  • [ ] 记录 build、run、test 命令;
  • [ ] 说明使用了哪些 OS abstraction;
  • [ ] 记录 corner case 与 failure behavior;
  • [ ] 记录 performance measurement,而不只记录功能正确;
  • [ ] 不把自动测试通过误认为设计已经正确;
  • [ ] 保存可复现的 commit、输入和输出。

当前撰写与执行记录

项目文档状态实现/运行状态首轮验收重点
Intro Project✅ 已整理⬜ 未执行system call、error path、输入边界
UNIX Shell✅ 已整理⬜ 未执行fork/exec/wait、pipe、redirection、signal
Memory-allocation Library✅ 已整理⬜ 未执行split/coalesce、alignment、fragmentation
Intro to Concurrency✅ 已整理⬜ 未执行race、lock correctness、contention measurement
Concurrent Web Server✅ 已整理⬜ 未执行bounded buffer、worker lifecycle、shutdown
File System Checker✅ 已整理⬜ 未执行image invariant、bad pointer、repair safety
File System Defragmenter✅ 已整理⬜ 未执行layout correctness、data preservation、performance
Concurrent File Server✅ 已整理⬜ 未执行protocol、partial failure、concurrent update

在固定 ostep-projects commit、compiler 和 OS 之前,项目状态保持“未执行”;运行后必须把 command、input、output 和失败原因追加到对应项目下。

已执行的材料级验证

当前固定的 ostep-projects HEAD 为 76cff3f89f4bf337af6e02e53a831b7eeb1396df。在 macOS + Apple clang 21.0.0 环境中,对 concurrency-webserver/src 的 supplied baseline 运行 make 成功,生成 wserver、wclient 和 spin.cgi;这证明 baseline 能构建,不等于尚未实现的 concurrent web server project 已完成。

text
cd concurrency-webserver/src
make clean
make
gcc -Wall -o wserver.o -c wserver.c
gcc -Wall -o request.o -c request.c
gcc -Wall -o io_helper.o -c io_helper.c
gcc -Wall -o wserver wserver.o request.o io_helper.o
gcc -Wall -o wclient.o -c wclient.c
gcc -Wall -o wclient wclient.o io_helper.o
gcc -Wall -o spin.cgi spin.c

initial-utilities 当前 checkout 只包含 README、test scripts 和 test data,没有学生提交的 wcat.c、wgrep.c、wzip.c 或 wunzip.c,因此只能核对 specification,不能声称项目测试通过。

原文逐段复核补充

本篇按官方 Version 1.10 的 4 页 lab-projects-systems.pdf 逐段核对,覆盖项目安排、评分方式、G.1–G.8 八类 systems projects 和 [M94] References。原文没有独立 raster image;项目描述中的 code/API 名称、mmap()、malloc()/free()、POSIX threads、NFS-like protocol、Moss 与官方 repository 均在原语义位置保留。PDF 页眉、页脚、页码和版本标识不作为项目内容录入。

翻译与实验状态严格分开:本篇已经完成材料级翻译和源文档核对;ostep-projects 中 supplied baseline 的构建证据只证明基线可构建,不代表任一 student project 已实现或测试通过。

参考资料

← 返回列表
← 上一篇 OSTEP:Laboratory Tutorial 下一篇 → OSTEP:Laboratory:xv6 Projects

评论 (0)

暂无评论,来留下第一条吧。
登录 或 注册 后才能发表评论