最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

xv6文件系統(tǒng)(1),buffer-inode

2023-03-18 19:50 作者:米諾斯人  | 我要投稿

補(bǔ)一下之前的坑

// Disk layout:磁盤(pán)內(nèi)容分部

// [ boot block | super block | log | inode blocks |

// ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?free bit map | data blocks]

//

// mkfs computes the super block and builds an initial file system. The

// super block describes the disk layout:

// struct superblock {

// ? uint magic; ? ? ? ?// Must be FSMAGIC

// ? uint size; ? ? ? ? // Size of file system image (block number)

// ? uint nblocks; ? ? ?// Number of data blocks

// ? uint ninodes; ? ? ?// Number of inodes.

// ? uint nlog; ? ? ? ? // Number of log blocks

// ? uint logstart; ? ? // Block number of first log block

// ? uint inodestart; ? // Block number of first inode block

// ? uint bmapstart; ? ?// Block number of first free map block

// };


【superblock 存儲(chǔ)了磁盤(pán)的布局layout,一般在boot時(shí),就把superblock裝入內(nèi)存】

————————

buffer層:

所有buffer node(循環(huán)鏈表)的信息被鏈表的spinlock保護(hù);而每一個(gè)buffer的data被buffer自己的sleeplock保護(hù)。

bget spinlock.lock后順序查找一個(gè)符合要求的buf,改變buf的信息(如ref-count)鎖住其sleeplock,返回。

bread方法讀取磁盤(pán)特定的塊區(qū):bget通過(guò)遍歷,獲取一個(gè)buffer,如果該block已經(jīng)在buffer則直接返回,否則找到一個(gè)空閑buf把磁盤(pán)數(shù)據(jù)裝入其中,再返回。返回的buf的sleeplock是鎖住的。

bwrite在buf的sleeplock鎖住的情況下把buf數(shù)據(jù)寫(xiě)入磁盤(pán)

brelse 釋放資源改變信息,如ref-count--;解開(kāi)buf的sleeplock

bpin增加buf的引用計(jì)數(shù)

punpin減少buf的引用計(jì)數(shù)

這兩個(gè)引用計(jì)數(shù)ref count的api用于buf所有權(quán)轉(zhuǎn)移(比如從函數(shù)的stack轉(zhuǎn)移到log緩存中)

————————————

log層:

先提一下log_write;這個(gè)方法被較為底層的各種方法調(diào)用,用緩存buf的方式(引用計(jì)數(shù)、更改log頭)代替把buf直接寫(xiě)到disk上。

之后begin_op write_log write_head commit end_op等方法沒(méi)什么可說(shuō)的;就是把data全部寫(xiě)入log區(qū)后才開(kāi)始從log區(qū)向真正的datablock區(qū)轉(zhuǎn)移。

【值得注意的是】,log層并不與inode層分離,可以看作同一層;inode層的讀寫(xiě)api嵌入了很多l(xiāng)og層api用以減少寫(xiě)磁盤(pán)次數(shù)(log_write),因此很多操作為:begin_op(); iput(buf); end_op();

————————————————

balloc、bfree:根據(jù)bitmap分配、釋放一塊空閑的磁盤(pán)區(qū)域(引用計(jì)數(shù))

——————————————

inode層

由于這是第一次提起inode,下面記錄一些關(guān)鍵信息。

The on-disk inode is defined by a struct dinode (kernel/fs.h:32). The type field distinguishes between files, directories, and special files (devices). A type of zero indicates that an ondisk inode is free. The nlink field counts the number of directory entries that refer to this inode, in order to recognize when the on-disk inode and its data blocks should be freed. The size field records the number of bytes of content in the file. The addrs array records the block numbers of the disk blocks holding the file’s content.

以上為dinode結(jié)構(gòu)體的概述。

n->ref為文件的引用計(jì)數(shù)(內(nèi)存)

n->type為文件類(lèi)型:file、dir、dev、free等

n->nlink為本文件被其他文件引用的引用計(jì)數(shù)(磁盤(pán))

n->size為文件大小

n->addr[]為文件分布的塊區(qū)地址,文件按addr[0]、addr[1]、...順序排列

inode in proc和dinode的關(guān)系有點(diǎn)類(lèi)似buffer緩存層和disk磁盤(pán)的關(guān)系。

ialloc+iget取得inode,ilock上鎖并且從dinode加載inode,iupdate調(diào)用log_write把inode寫(xiě)回磁盤(pán),iput釋放inode(如果inode->nlink和inode->ref減為0,再調(diào)用itruncate徹底從磁盤(pán)釋放inode)

著重說(shuō)一下itruncate中inode文件徹底釋放:釋放inode->addr[]數(shù)組中的每個(gè)塊區(qū),即把對(duì)應(yīng)的bitmap標(biāo)記為0(即bfree,和balloc相反)【inode會(huì)釋放ref cnt不為0的buffer對(duì)應(yīng)的block嗎?】不會(huì),bread獲取buffer只能通過(guò)balloc,釋放只能通過(guò)bfree。balloc和bfree一一對(duì)應(yīng)。

上面基本是inode的內(nèi)部接口,下面介紹inode的外部接口

readi根據(jù)偏移量計(jì)算出需要讀取的塊區(qū),比如讀取文件的第n塊,那就是inode->addr[n];然后判斷是把文件向虛擬地址拷貝還是實(shí)地址,虛擬地址需要手動(dòng)查頁(yè)表。

writei類(lèi)似,除了用log_write緩存代替write_disk直寫(xiě)外(因此需要調(diào)用begin_op和end_op來(lái)通知log模塊),不多贅述。









xv6文件系統(tǒng)(1),buffer-inode的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
沁阳市| 周口市| 怀安县| 济宁市| 丹阳市| 菏泽市| 潜江市| 衡东县| 台南县| 姜堰市| 磐石市| 新田县| 枣阳市| 桂平市| 张家界市| 沅江市| 连州市| 兴安县| 巫溪县| 葫芦岛市| 大城县| 新闻| 仲巴县| 通江县| 红河县| 双流县| 建瓯市| 阿勒泰市| 贞丰县| 广昌县| 二连浩特市| 汕头市| 宁德市| 鹤岗市| 电白县| 甘肃省| 赤壁市| 鄂托克前旗| 庆阳市| 商河县| 抚州市|