MIT6.1810: Lab6 Lock

一、Memory allocator (easy) 1. 物理内存分配器现状 当前 xv6 的物理内存管理策略比较简单: 将可用的物理内存划分为 4KB 大小的页面。 使用一个 freelist(空闲链表)将这些页面串联起来。 使用一个自旋锁保护 freelist,保证多核环境下链表操作的互斥性。 调用 kalloc() 和 kfree() 操作 freelist 之前先获取自旋锁,操作完成后释放锁。 更多细节可以参考我的这篇博客。 按照实验要求,在 xv6 中运行 kalloctest: $ kalloctest start test1 test1 results: --- lock kmem stats lock: kmem: #test-and-set 67377 #acquire() 433136 --- top 5 contended locks: lock: virtio_disk: #test-and-set 144638 #acquire() 183 lock: proc: #test-and-set 86684 #acquire() 667829 lock: proc: #test-and-set 78406 #acquire() 667827 lock: proc: #test-and-set 72893 #acquire() 270341 lock: kmem: #test-and-set 67377 #acquire() 433136 tot= 67377 test1 FAIL start test2 total free number of pages: 32465 (out of 32768) .......... test2 OK start test3 ..........child done 10000 test3 OK start test4 ............................child done 100000 .child done 100000 .child done 100000 --- lock kmem stats lock: kmem: #test-and-set 989593 #acquire() 3377039 --- top 5 contended locks: lock: wait_lock: #test-and-set 18470332 #acquire() 40032 lock: proc: #test-and-set 1525506 #acquire() 2552018 lock: kmem: #test-and-set 989593 #acquire() 3377039 lock: proc: #test-and-set 248206 #acquire() 1613804 lock: proc: #test-and-set 211798 #acquire() 1956210 tot= 989593 test4 FAIL m 190242 n 989593 1.1 理解锁竞争统计 在 lab lock 版本中,acquire() 函数会记录两个指标: ...

November 5, 2026 · 8 min · 1651 words