OSTEP:Laboratory:Systems Projects
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 Project | sort utility 与 systems programming 入门 |
| UNIX Shell | process、pipe、redirection 与 batch |
| Memory-allocation Library | mmap()、free list 与 allocator policies |
| Intro to Concurrency | POSIX threads、locking 与 scalability |
| Concurrent Web Server | thread pool、bounded buffer 与 worker |
| File System Checker | on-disk structure 与 consistency |
| File System Defragmenter | layout、fragmentation 与 performance |
| Concurrent File Server | network、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 风格 allocator | mmap、pointer、free list、fit policy |
| Intro to Concurrency | 实现 thread-safe list/hash table | POSIX threads、locks、scalability |
| Concurrent Web Server | 为 web server 加 thread pool | producer/consumer、bounded buffer |
| File System Checker | 检查并修复 file-system image | on-disk structure、consistency |
| File System Defragmenter | 重新布局 fragmented image | file-system layout、performance |
| Concurrent File Server | 实现类似 NFS 的 file server | concurrency、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:
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:
- 遍历 image;
- 找出未 sequentially laid out 的 file;
- 生成新的 defragmented image;
- 报告 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 已完成。
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: Systems Projects(官方 PDF)
- OSTEP 官方项目仓库
- Moss: A System for Detecting Software Plagiarism
- [M94] “Moss: A System for Detecting Software Plagiarism”,Alex Aiken;官方 PDF 给出的地址为 theory.stanford.edu/~aiken/moss。
评论 (0)