【正文】
b u f c t lk m e m b u f c t lk m e m b u f c t lb u f b u fb u fu n u s e do n e o r m o r e p a g e sS l a b : k e y s t r u c t u r e i n t h e c a c h eObject Descriptor ? Each object has a descriptor of type kmem_bufctl_t. ? Object descriptors are stored in an array placed after the corresponding slab descriptor. Relationships between slab and object descriptors Aligning Objects in Memory ? 對象在 slab中分配的物理地址是以對齊常量的整數(shù)倍的。 ? slab最大的分配空間是一個頁面的大小 4096 ? 在 CPU的 cache中,為了提高傳輸效率,地址都是以 word大小進(jìn)行傳遞的。 ? 同樣大小的 object,希望以同樣的偏移量來進(jìn)行存儲,這樣可以提高cache的使用效率。 Slab with color col and alignment aln pagelevel allocatorinodecachefilecachesk_buffcachetask_structcacheactiveinodesactivesk_buffactivefilesactiveprocesseskmem_cache_create() kmem_cache_destroy()kmem_cache_free()kmem_cache_alloc()Linux kernel memory allocator architectureback endfront endLinux文件管理 Linux支持的常見的文件系統(tǒng)類型 ? Linux自身提供的缺省文件系統(tǒng): ext2fs(一般根文件系統(tǒng) /使用此文件系統(tǒng));新增的自身提供的文件系統(tǒng): ext3fs、 ReiserFS、 IBM JFS等 ? 其它 UNIX使用的文件系統(tǒng): minix,ext,xiafs等 ? DOS/Windows使用的文件系統(tǒng): FAT12,FAT16,FAT32,VFAT,NTFS(只讀) ? HPFS( OS/2使用、只讀)、 HFS( Macintosh使用、只讀);AFFS(Amiga); System V,Coherent,Xenix; CDROM( ISO 9660) ? UMSDOS( UNIXlike FS on MSDOS); NFS(網(wǎng)絡(luò)文件系統(tǒng));SMBFS( Windows共享文件系統(tǒng))、 NCPFS( Novell Netware共享文件系統(tǒng)) ? /proc(用于內(nèi)核和進(jìn)程信息) Linux 專用文件系統(tǒng) ? Minix 是 Linux 的第一個文件系統(tǒng),有局限,性能比較差。文件名不能長于 14 個字符,最大的文件大小是 64M 字節(jié) ? 在 1992 年 4 月引入第一個專為 Linux 設(shè)計的文件系統(tǒng) 擴(kuò)展文件系統(tǒng)或 EXT ( Extend File System ) ? 1993 年,增加了擴(kuò)展文件系統(tǒng)第二版,或 EXT2 傳統(tǒng) Unix文件系統(tǒng) ? 只支持特定的文件系統(tǒng) ? 無法存取其他的文件系統(tǒng) ? 如何支持更多的文件系統(tǒng) 傳統(tǒng) Unix系統(tǒng)的缺點 解決方案一 方案一的問題 ? Kernel與文件系統(tǒng)的依賴程度太高 ? 增加編程的負(fù)擔(dān) ? 系統(tǒng)的擴(kuò)展性不好 ? 方案二:為 kernel和文件系統(tǒng)提供了一個統(tǒng)一的界面 方案二 虛擬文件系統(tǒng) VFS 虛擬文件系統(tǒng) ? 現(xiàn)在的系統(tǒng)大多都在系統(tǒng)內(nèi)核和文件系統(tǒng)之間提供一個標(biāo)準(zhǔn)的接口,真實的文件系統(tǒng)通過一個接口層從操作系統(tǒng)和系統(tǒng)服務(wù)中分離出來,這樣不同文件結(jié)構(gòu)之間的數(shù)據(jù)可以十分方便地交換。 ? Linux也在系統(tǒng)內(nèi)核和文件系統(tǒng)之間提供了一種叫做虛擬文件系統(tǒng) VFS( virtual file system)的標(biāo)準(zhǔn)接口。 ? VFS 允許 Linux 支持許多(通常是不同的)文件系統(tǒng),每一個都向 VFS 表現(xiàn)一個通用的軟件接口。 Linux 文件系統(tǒng)的所有細(xì)節(jié)都通過軟件進(jìn)行轉(zhuǎn)換,所以所有的文件系統(tǒng)對于 Linux 核心的其余部分和系統(tǒng)中運行的程序顯得一樣。 虛擬文件系統(tǒng)轉(zhuǎn)換 Linux 文件管理程序系統(tǒng)調(diào)用接口 VFS 轉(zhuǎn)換 FAT文件系統(tǒng) Ext2文件系統(tǒng) /proc文件系統(tǒng) VFS的基本概念 (1/3) ? Linux成功的關(guān)鍵就是支持多文件系統(tǒng) ? VFS的歷史 ?SUNOS: vitualnode layer ?: VirtualFilesystem Interface ?Linux: originally named by Virtual Filesystem Switch ? VFS的設(shè)計 ?In fact VFS is a kernel software layer posed of a superset of functions of various file systems and it provides a uniform interface to applications like the objectoriented approach VFS的基本概念( 2/3) ? VFS所支持的文件系統(tǒng),可以查看 fs目錄 ? Network ?nfs ?Coda ?AFS Andrew FS ?smbfs LanManager ?ncpfs Novell ? Special ones ?procfs /proc ?umsdos Unix in DOS ?userfs redirector to user ? Media based ?ext2 Linux native ?ufs BSD ?fat DOS FS ?vfat win 95 ?hpfs OS/2 ?minix well…. ?Isofs CDROM ?sysv Sysv Unix ?hfs Macintosh ?affs Amiga Fast FS ?NTFS NT’s FS ?adfs Acornstrongarm VFS的基本概念( 3/3) ? 通用文件模型 ? 可以表示所有支持的文件系統(tǒng) ? 提供了對傳統(tǒng) Unix文件系統(tǒng)的映象 ? 在通用文件模型中包含的對象類型 ? Superblock ? inode ? file ? dentry VFS和實際文件系統(tǒng)的關(guān)系 實際文件系統(tǒng)和 VFS的轉(zhuǎn)換 ? 當(dāng)每一個文件系統(tǒng)初始化的時候,自身向 VFS 登記。 (在系統(tǒng)啟動操作系統(tǒng)初始化自身時 ) ? 真實的文件系統(tǒng)自身建立在內(nèi)核中或者是作為可加載的模塊。文件系統(tǒng)模塊在系統(tǒng)需要的時候加載。 ? 當(dāng)一個塊設(shè)備文件系統(tǒng)安裝的時候,(包括 root 文件系統(tǒng)), VFS 必須讀取它的超級塊。每一個文件系統(tǒng)類型的超級塊的讀取例程必須找出這個文件系統(tǒng)的拓?fù)浣Y(jié)構(gòu),并把這些信息映射到一個 VFS 超級塊的數(shù)據(jù)結(jié)構(gòu)上。 ? VFS 保存系統(tǒng)中安裝的文件系統(tǒng)的列表和它們的 VFS 超級塊列表。 Interaction between processes and VFS objects VFS相關(guān)的系統(tǒng)調(diào)用( 1/2) System call name Description mount( ) umount( ) Mount/unmount filesystems sysfs( ) Get filesystem information statfs( ) fstatfs( ) ustat( ) Get filesystem statistics chroot( ) pivot_root( ) Change root directory chdir( ) fchdir( ) getcwd( ) Manipulate current directory mkdir( ) rmdir( ) Create and destroy directories getdents( ) readdir( ) Manipulate directory entries link( ) unlink( ) rename( ) Manipulate directory entries readlink( ) symlink( ) Manipulate soft links chown( ) fchown( ) lchown( ) Modify file owner chmod( ) fchmod( ) utime( ) Modify file attributes stat( ) fstat( ) lstat( ) access( ) Read file status open( ) close( ) creat( ) umask( ) Open and close files VFS相關(guān)的系統(tǒng)調(diào)用( 2/2) System call name Description dup( ) dup2( ) ftl( ) Manipulate file descriptors select( ) poll( ) Asynchronous I/O notification truncate( ) ftruncate( ) Change file size lseek( ) _llseek( ) Change file pointer read( ) write( ) readv( ) Carry out file I/O operations writev( ) sendfile( ) readahead( ) Carry out file I/O operations pread( ) pwrite( ) Seek file and access it mmap( ) munmap( ) Handle file memory mapping madvise( ) mincore( ) Handle file memory mapping fdatasync( ) fsync( ) sync( ) msync( ) Synchronize file data flock( ) Manipulate file lock VFS 相關(guān)數(shù)據(jù)結(jié)構(gòu) ? Superblock ( struct super_block @ include/linux/ ) ? Inode ( struct inode @ include/linux/ ) ? File ( struct file @ include/linux/ ) ? Dentry ( struct dentry @ include/linux/ ) ? Dentry cache ? Files associated with a process ? struct fs_struct @ include/linux/, a field of struct task_struct ? struct files_struct @ include/linux/, also a field of struct task_struct 各數(shù)據(jù)結(jié)構(gòu)間的關(guān)系 task_struct open file object inode superblock disk fds open file object open file object inode inode dentry dentry dentry dentry dentry inode cache dentry cache 共享的數(shù)據(jù)結(jié)構(gòu) ? calling dup() – ? shares open file objects ? example: 2amp。1 ? opening the same file twice – ? shares dentries ? opening same file via different hard links – ? shares inodes ? mounting same filesystem on different dirs – ? shares superblocks VFS 超級塊 ? 每一個安裝的文件系統(tǒng)都用 VFS 超級塊 ? mounted filesystem descriptor ? usually first block on disk (after boot block) ? copied into (similar) memory struc