爲什麼有必要從SVR3到SRV4?爲了吸取AT&T當時開發的操做系統的一些特性,集成VM的更新。node
從SVR3到SVR4主要改動的地方包括:數組
1.用讀寫鎖替代了以前的鎖策略;數據結構
2.在IO路徑上,用pages cache替換了以前的buffer caches, 用來提供meta data傳輸的吞吐率和效率app
具體的變化以下:ide
文件描述符方面:函數
SVR3:文件描述符就是u_ofile[]數組的Index;ui
SVR4: 文件描述符是動態分配且可調節的, u_ofile[]被去掉,用u_nofiles[]和u_flist, a structure of type ufchunkthat contains an array of NFPCHUNK(which is 24) pointers to file table entriesthis
替代了。每一個進程最大文件描述符的個數是由rlimit數據結構來限制的。spa
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中文件描述符的分配圖以下:
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)->v_op->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的函數替代。