天天看點

[深入了解檔案系統之五] 從SVR3 到SVR4

為何有必要從SVR3到SRV4?為了吸收AT&T當時開發的作業系統的一些特性,內建VM的更新。

從SVR3到SVR4主要改動的地方包括:

1.用讀寫鎖替代了之前的鎖政策;

2.在IO路徑上,用pages cache替換了之前的buffer caches, 用來提供meta data傳輸的吞吐率和效率

<a href="https://s5.51cto.com/wyfs02/M01/8E/42/wKioL1i6w7rCWFG4AAFEl5masXg954.png" target="_blank"></a>

具體的變化如下:

檔案描述符方面:

SVR3:檔案描述符就是u_ofile[]數組的Index;

SVR4: 檔案描述符是動态配置設定且可調節的, u_ofile[]被去掉,用u_nofiles[]和u_flist, a structure of type ufchunkthat contains an array of NFPCHUNK(which is 24) pointers to file table entries

替代了。每個程序最大檔案描述符的個數是由rlimit資料結構來限制的。

There are a number of per-process limits within the u_rlimit[]array. The u_rlimit[RLIMIT_NOFILE]entry defines both a soft and hard file descriptor limit. Allocation of file descriptors will fail once the soft limit is reached. Thesetrlimit()system call can be invoked to increase the soft limit up to that of the hard limit, but not beyond. The hard limit can be raised, but only by root

SVR4中檔案描述符的配置設定圖如下:

<a href="https://s5.51cto.com/wyfs02/M01/8E/45/wKiom1i6w33DjLobAABTWC4-AU4267.png" target="_blank"></a>

Virtual Filesystem Switch Table方面的改變

核心編譯的時候動态構造,由vfssw[]數組指定的file system switch table , 每一個成員的構造如下:

struct vfssw {

char *vsw_name;

int (*vsw_init)();

struct vfsops *vsw_vfsops;

}

Thevfsstructure with SVR4 contained all of the original Sun vfsfields and introduced a few others including vfs_dev, which allowed a quick and easy scan to see if a filesystem

was already mounted, and the vfs_fstypefield, which is used to index the

vfssw[]array to specify the filesystem type

vnode和VOP層的改變

vnode資料結構中去掉了v_shlockc, v_exlockc;

加入了:

v_stream指向vstream裝置;

v_filocks指向目前檔案所指向的所有檔案和鎖

v_pages基于SVR4之後,所有的讀寫操作都是基于page cache,而非之前的buffer cache (buffer cache現在隻是在像inodes/directories等meta-data中用到)

對應的vnode operations vector 數組中經曆了更多的改動:

從中去掉的函數包括:vop_bmap()/vop_bread()/vop_brelse()/vop_strategy()/vop_rdwr()/vop_select()

新引入的函數包括:

vop_read()/vop_write()/

vop_setfl() : in response to an fcntl() system call

where the F_SETFL (set file status flags) flag is specified. This allows the

filesystem to validate any flags passed.

vop_fid():用來生成唯一的檔案句柄

vop_rwlock(): 通過引入了LOCK_SHARED or LOCK_EXCL 标示符,支援了單寫者多讀者模型

vop_rwunlock():釋放上面申請使用的鎖

vop_seek(): When specifying an offset to lseek(), this function is called to determine whether the filesystem deems the offset to be appropriate.

vop_cmp():比較兩個指定的vnode

vop_frlock(): implement file and record locking

vop_space(): fcntl() system call has an option, F_FREESP, which  allows the caller to free space within a file

vop_realvp():A call  toVOP_REALVP()is made by filesystems when performing a link()system call to ensure that the link goes to the underlying file and not the specfs file, that has no physical representation on disk.

vop_getpage():read pages of data from the file in response to a page fault.

vop_putpage():flush a modified page of file data to disk

vop_map():implementing memory mapped files

vop_addmap():adds a mapping

vop_delmap(): deletes a mapping

vop_poll():implementing the poll()system call.

vop_pathconf():implement the pathconf()and

fpathconf()system calls. Filesystem-specific information can be returned, such as the maximum number of links to a file and the maximum file size

vnode的操作最後都是用宏實作的:

#define VOP_LOOKUP(vp,cp,vpp,pnp,f,rdir,cr) \ (*(vp)-&gt;v_op-&gt;vop_lookup)(vp,cp,vpp,pnp,f,rdir,cr)

這樣一來:The filesystem-independent layer of the kernel will only access the filesystem

through macros. Obtaining a vnode is performed as part of an open()or

creat()system call or by the kernel invoking one of the veneer layer functions

when kernel subsystems wish to access files directly.

基于上述第二步,很多之前的操作,比如bread/bwrite/都被去掉,用沒使用buffer的函數替代。

本文轉自存儲之廚51CTO部落格,原文連結:http://blog.51cto.com/xiamachao/1903259 ,如需轉載請自行聯系原作者

繼續閱讀