tianole/docs/agents/tasks/03-memory.md
2026-05-08 21:26:30 +08:00

45 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 03 内存管理
## 目标
从 boot memory map 建立 kernel 自己的内存模型,提供物理页、虚拟地址和内核堆能力。
## 前置条件
- 异常处理可用,尤其是 page fault 路径。
- early log 和 panic 可用。
## 建议边界
- `kernel/mm/`:架构无关内存管理。
- `arch/x86/mm/`页表格式、地址空间切换、TLB 操作。
- `include/tianole/`:通用内存接口。
## 实现内容
- 解析 boot memory map。
- 归一化可用/保留/固件/内核占用区域。
- 建立物理页分配器。
- 建立内核虚拟地址布局。
- 建立页表 map/unmap 接口。
- 建立最小内核堆。
- 为后续匿名页、缺页加载、COW、`mmap`、page cache、换页预留接口。
## 非玩具化约束
- 不写死物理内存大小。
- 不把 UEFI memory type 作为长期内核内存类型。
- allocator 接口要允许后续替换为 buddy/slab。
- 小对象分配要允许后续演进到 slab/slub 或等价缓存分配器。
- 地址空间布局要文档化。
- 用户地址空间和内核地址空间的边界不能依赖调用方自觉遵守。
- 不能把 page cache 和匿名页排除在长期模型之外。
## 验收方式
- 能分配和释放多个物理页。
- 能建立和删除虚拟映射。
- page fault 能输出有效诊断。
- 内核堆能分配小对象。
- 后续能在此基础上加入 COW、`mmap`、换页和内存回收。