xv6 risc-v bio.c code walk through

本文详细介绍了 xv6 操作系统中文件系统缓冲区缓存的工作原理,包括其接口、数据结构和操作。重点讨论了 bread、bwrite 和 brelse 函数的作用,以及如何利用 LRU 策略进行缓存管理。
摘要由CSDN通过智能技术生成

(感觉文件系统的代码还是挺多的 做个笔记

首先上xv6 文件系统的结构图:

disk在virtio硬盘上读写

buffer cache 如下

logging 将来自高层对几个块的更新包装成一个事务(transaction),保证发生崩溃时,块的更新具有原子性(要么都不执行,要么全部执行

inode 提供单个的文件,表现为inode,有一个独一无二的inum,一些块保存该文件的数据

directory 将目录实现为一种特殊的inode,他的内容是一系列dirent(directory entry),每个dirent包含一个文件名和一个inum

pathname 提供有层次地路径名,并使用递归地查找来解析他们

file descriptor将unix的各种资源抽象化,使其都可以通过文件描述符访问

 

bio.c负责的是buffer cache这一层

bio.c有最详细的注释:

 Buffer cache.

 The buffer cache is a linked list of buf structures holding
 cached copies of disk block contents.  Caching disk blocks
 in memory reduces the number of disk reads and also provides  a synchronization point for disk blocks used by multiple processes.

可以知道:这里采用链表的形式,管理对磁盘块内容的缓存。缓存磁盘块可以让我们减少对磁盘的读,并且在多个进程读写磁盘块时提供了一个同步的点

 Interface:
 * To get a buffer for a particular disk block, call bread. bread用于获取一个缓存块
 * After changing buffer data, call bwrite to write it to disk. bwrite将更改过的缓存块写回到磁盘
 * When done with the buffer, call brelse. brelse(release)释放一个缓存块(?
 * Do not use the buffer after calling brelse.
 * Only one process at a time can use a buffer,
     so do not keep them longer than necessary. 一个缓存块一次只能被一个进程使用,所以使用完尽早释放(?
 

首先看数据结

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值