= xv6 buffer cache
{c}
The teaching implementation's `bget` checks device and block number under a shared <spinlock>, increments `refcnt` before releasing that lock, and then takes the buffer's content <mutex>. On a <cache miss> it reserves an unused structure and clears `valid`; `bread` fills it only if necessary. This makes lookup and reservation share one <synchronization (computing)> boundary. `brelse` releases the content <mutex> and decrements the reference count. Unlike the stipulated trace policy, it moves the structure to the recent end only when that decrement reaches zero. <xv6 RISC-V source code/bio.c>{ref}
This implementation has `valid` and `refcnt` but no generic dirty flag. Its <file-system journaling> code records modified blocks with `log_write`, pins each newly recorded block, copies cached contents to the journal during commit, and unpins after installing the committed contents at their final locations. Thus journal pins keep modifications resident after callers release them. Its eviction loop does not perform the generic dirty-victim <buffer cache writeback> of our model. <xv6 RISC-V source code/buf.h>{ref}<xv6 RISC-V source code/log.c>{ref}
Back to article page