系统与数据库2015scialex.github.io
Reenix:用 Rust 实现类 Unix 操作系统
Reenix: Implementing a Unix-Like Operating System in Rust
进阶 · 约 60 分钟读完前置知识:操作系统基础、Rust 语言基础
导读
Reenix 是一篇关于用 Rust 实现类 Unix 操作系统的技术报告,记录了作者把 Rust 用于内核/系统编程的实践过程与踩坑经验。文中提到的主要障碍包括:Rust 默认假定存在 malloc 式分配器、rustc 生成的镜像过大(早期连 Hello World 都超过 4MB,撞上 bootloader 的上限),以及虚拟终端切换缺乏干净的实现方式。
HN 关注点:Rust 究竟适不适合写内核与系统软件,讨论焦点集中在作者亲历的工具链限制和语言设计取舍上。
HN 评论精选
这几条评论里:支持 1 质疑 1 补充 2
质疑Rust 的分配器假设和所有权约束与内核编程需求存在摩擦,语言定位应有所区分。
“唯一的问题是 Rust 在设计时就假设会配合 malloc 风格的内存分配器使用,而这种分配器很难用 slab 分配器实现,因为 malloc 必须能分配任意大小的缓冲区。”……“唯一算得上棘手的挑战,是我找不到任何干净的方式在不同虚拟终端之间切换。最后只能更新一个指针,让中断子系统知道该把输入送到哪个 TTY。”(这在 Rust 里是不被鼓励的做法。)用一门有前景的语言去做系统任务是很好的练习,但有些语言需要成为系统语言、有些需要成为应用语言,因为我们要让开发者轻松做到的假设和默认情况并不相同。
fl0wenol查看英文原文
"The only problem is that rust was built with the idea that it will be used with a malloc style memory allocator. This kind of allocator is rather hard to implement using slab allocators since malloc must be able to allocate buffers of any size." ... "About the only somewhat difficult challenge was that I was unable to find any clean way to switch between different virtual terminals. I ended up having to just update a pointer so that the interrupt subsystem could know which TTY to send input to." (discouraged in rust). It's a good exercise to try to take a language with promise and use it for a systems task to understand what's possible. But sometimes some languages need to be systems languages, and others need to be application languages, because there are different assumptions and default cases we want to make easy/possible for developers.
补充把 Reenix 类比为 TUNIS,认为推倒重来的干净设计常能带来最好的系统实现。
基本上就是 Rust 时代的 TUNIS(用 C 重写 Unix 的教学项目)。这很合理:我见过的一些最出色的 Unix 实现工作(例如为多处理器、大型存储集群和可管理性重写 SVR4 的 DG/UX)都源自“干脆把一切重构一遍”的干净设计。
jonathaneunice查看英文原文
So basically TUNIS http://en.wikipedia.org/wiki/TUNIS for the Rust era and language. It makes sense. Some of the best Unix implementation work I've seen (e.g. the DG/UX reimplementation of SVR4 UNIX for multiprocessors, large storage farms, and manageability) came from the "let's consider refactoring everything" that comes with a clean-sheet design.
补充对 Hello World 二进制就超过 4MB 感到惊讶,侧面反映当时 rustc 的代码体积问题。
“这个 bootloader 不幸不支持加载大于 4MB 的内核镜像。这很快就成了问题,因为事实证明 rustc 在生成精简输出上远不如 gcc。实际上我很早就撞上了这个问题,几乎还没能跑出一个 Hello World 就得停下 Rust 代码的工作。”这段让我印象深刻。我没怎么玩过 Rust,但一个 Hello World 的可执行文件就超过 4MB,实在有点离谱。我知道编译器优化还在进步,只是觉得这部分很有意思。
soviettoly查看英文原文
"This boot-loader, unfortunately, did not support loading any kernel images larger than 4 megabytes. This turned into a problem very quickly as it turns out that rustc is far less adept than gcc at creating succinct output. In fact, I was hitting this problem so early I was barely able to make a “Hello World” before having to stop working on rust code." This really caught me. I have not played around with rust that much but having the executable be over 4MB, with such a small program such as just a Hello World is kind of nuts. I know that they still have lot of compiler optimization, but I just thought that was a very interesting portion of the read.
支持称赞论文的技术排版与代码呈现质量。
讨论这类主题的 PDF 以前看起来要惨淡得多。这里的代码清单比我以前见过的大多数都漂亮,连反汇编都有语法高亮。这样的内容配得上这么好的排版,我很喜欢。
tempodox查看英文原文
PDFs discussing topics like that used to look much more bleak. The code listings here look better than most of what I've seen before. Even the (dis)assembly has some syntax highlighting. This content deserves to be that nicely presented, I love it.
历次讨论
- 2015Hacker News 讨论帖187 分 · 21 评
同领域还值得读
I/O 比 CPU 更快——让我们划分资源并消除操作系统抽象
I/O Is Faster Than CPU – Let’s Partition Resources and Eliminate OS Abstractions
指出在现代服务器硬件上 I/O 速度已接近甚至超过 CPU,传统操作系统抽象反而成为瓶颈。
系统与数据库2019 · 817 分 · 277 评进阶 · 约 30 分钟编辑精选使用 io_uring 的高效 I/O
Efficient IO with io_uring
由 Linux 内核开发者 Jens Axboe 撰写,介绍 Linux 新的异步 I/O 接口 io_uring。
系统与数据库2019 · 426 分 · 96 评进阶 · 约 45 分钟编辑精选线程对大多数用途而言是个坏主意(1995)
Threads Are a Bad Idea for Most Purposes (1995)
这篇 1995 年的文章由 John Ousterhout 撰写,讨论为什么线程对大多数用途而言是坏主意,并主张事件驱动编程通常更简单、更高效。
系统与数据库2017 · 423 分 · 382 评进阶 · 约 25 分钟编辑精选学习型索引结构之论证
The Case for Learned Index Structures
提出把索引看作一种"模型":既然 B-tree 等结构本质上是在学习数据的分布,就可以用机器学习模型(如回归模型、神经网络)来近似键到位置的映射,从而替代 B-tree、哈希索引…
系统与数据库2017 · 398 分 · 66 评 · 引用 25进阶 · 约 60 分钟编辑精选FoundationDB:一个分布式、解耦的事务型键值存储
FoundationDB: A distributed, unbundled, transactional key value store
介绍 FoundationDB:一个分布式、解耦设计的事务性键值存储。
系统与数据库2021 · 283 分 · 99 评进阶 · 约 90 分钟编辑精选