Download presentation
Presentation is loading. Please wait.
1
Chöông 10: Heä Thoáng File
10.B Hieän thöïc heä thoáng file vaø thö muïc Caùc phöông phaùp quaûn lyù khoâng gian troáng
2
Sô ñoà boá trí (layout) heä thoáng file (1/4)
Toå chöùc khoâng gian ñóa (maùy tính caù nhaân – PC) MBR From Several major kinds of boot sectors could be encountered on IBM PC compatible hard disks, floppy disks and similar storage devices: A master boot record (MBR) is the first sector of a data storage device that has been partitioned. The MBR sector may contain code to locate the active partition and invoke its Volume Boot Record. A volume boot record is the first sector of a data storage device that has not been partitioned, or the first sector of an individual partition on a data storage device that has been partitioned. It may contain code to load and invoke an operating system (or other standalone program) installed on that device or within that partition. Partition control block FCB’s i-nodes
3
Sô ñoà boá trí heä thoáng file (2/4)
Partition control block löu soá löôïng block trong partition, kích thöôùc block, soá löôïng free block hieän thôøi vaø caùc con troû chæ ñeán chuùng,… löu soá löôïng free FCB hieän thôøi vaø caùc con troû chæ ñeán chuùng,… Ví duï “superblock” trong UNIX File System File control block (FCB): moãi file ñöôïc quaûn lyù thoâng qua FCB cuûa noù löu caùc thoâng tin veà file, keå caû caùc con troû chæ ñeán caùc data block cuûa noù Ví duï “i-node” trong UNIX File System:
4
Sô ñoà boá trí heä thoáng file (3/4)
Layout cuûa moät partition chöùa heä thoáng file UNIX
5
Sô ñoà boá trí heä thoáng file (4/4)
FAT duøng ñeå chæ baûng FAT vaø cuõng duøng ñeå chæ heä thoáng file Layout cuûa moät partition chöùa heä thoáng file FAT Boot sector FAT Root directory Data blocks
6
VFS (Virtual File System)
Cung caáp giao dieän ñoàng nhaát cho öùng duïng ñoäc laäp vôùi file system cuï theå nhieàu file system khaùc nhau trong cuøng heä thoáng open, read, write, opendir,… disk partition ext2 file system FAT file system NFS file system ÖÙng duïng VFS : goïi haøm/thuû tuïc switch
7
VFS (Virtual File System)
Vò trí cuûa VFS vaø file system software trong I/O call path (Linux) ÖÙng duïng trong user space VFS ext2_file_write() File system cuï theå, ôû ñaây ext2 Ñònh thôøi cho thieát bò block Device driver from Lunde
8
Hieän thöïc file Caáp phaùt khoâng gian löu tröõ cho file/directory, muïc tieâu: söû duïng khoâng gian ñóa höõu hieäu truy caäp file nhanh Neáu soá löôïng vaø kích thöôùc file khoâng thay ñoåi ñoäng thì hieän thöïc file nhö theá naøo? Caùc phöông phaùp caáp phaùt phoå bieán Caáp phaùt lieân tuïc (contiguous allocation) Caáp phaùt theo danh saùch lieân keát (linked list allocation) Caáp phaùt duøng chæ muïc (indexed allocation)
9
Caáp phaùt lieân tuïc Thôøi gian di chuyeån ñaàu ñoïc?
Coù theå truy xuaát ngaãu nhieân moät block cuûa file: block nr = start + block offset Phaân maûnh ngoaïi Coù theå gaëp khoù khaên khi taïo file môùi vaø khi caàn theâm block cho file ÖÙng duïng: ISO-9660 (CDROM)
10
Caáp phaùt theo danh saùch lieân keát (1/2)
pointer -1 data layout cuûa block -1
11
Caáp phaùt theo danh saùch lieân keát (2/2)
Öu ñieåm Deã daøng theâm block cho file khi caàn Quaûn lyù khoâng gian troáng baèng danh saùch lieân keát Khoâng coù phaân maûnh ngoaïi Nhöôïc ñieåm Chæ truy xuaát hieäu quaû ñoái vôùi sequential-access file Toán khoâng gian löu tröõ caùc con troû Ñoä tin caäy: pointer trong block coù theå bò hoûng
12
FAT – moät hieän thöïc cuûa caáp phaùt theo danh saùch lieân keát:
Nhöng khoâng löu con troû ñeán file block tieáp theo trong block chöùa döõ lieäu file FAT (File Allocation Table) Moãi block ñóa ñöôïc töôïng tröng bôûi moät entry trong FAT FAT entry vôùi index i töôïng tröng block coù block nr i FAT entry chöùa block nr keá tieáp trong file, neáu file goàm nhieàu block no. of disk blocks - 1
13
Caáp phaùt duøng chæ muïc (1/2)
Baûng index (index block) chöùa ñòa chæ caùc block cuûa file thöù töï caùc ñòa chæ cuõng laø thöù töï caùc block cuûa file
14
Caáp phaùt duøng chæ muïc (2/2)
Öu ñieåm Random vaø sequential access Khoâng xaûy ra phaân maûnh ngoaïi Khuyeát ñieåm Toán khoâng gian löu tröõ baûng index duø file coù kích thöôùc chæ vaøi block Vaán ñeà: Kích thöôùc moät file coù theå nhoû nhöng cuõng coù theå raát lôùn. Kích thöôùc index block bao nhieâu laø phuø hôïp? Giaûi quyeát: multilevel index i-node
15
i-node – moät hieän thöïc cuûa index block
UNIX v7 i-node: 13 pointer Linux ext2 i-node: 15 pointer
16
Hieän thöïc file duøng i-node
File (user view) Ví duï
17
Hieän thöïc thö muïc Thö muïc ñöôïc duøng ñeå chöùa baûng aùnh xaï töø teân file (chuoãi kyù töï ASCII) ñeán thoâng tin caàn thieát ñeå ñònh vò caùc block döõ lieäu cuûa file Toå chöùc thö muïc Danh saùch tuyeán tính (array hay linear list), baûng baêm,… FAT file system UNIX file system first block nr i-node
18
Duyeät path name ñeå laáy block nr cuûa file
Ví duï: Xaùc ñònh caùc block döõ lieäu cuûa file /a/b/c i-node of / (the 1st one of i-list, by convention)
19
i-node: chia seû file (1/2)
Thö muïc i-node 27 i-node 51
20
i-node: chia seû file (2/2)
Thö muïc i-node 27 i-node 51 i-node 27
21
Quaûn lyù khoâng gian troáng
Caùc phöông phaùp Bit vector (bit map) Linked list Grouping Counting
22
Phöông phaùp bit vector (bit map)
Ví duï: bit vector … block 0, 1 troáng block 2, 3, 4, 5 ñaõ ñöôïc caáp block 6, 7 troáng … 1 2 n - 1 bit[ i ] = 0 block i coøn troáng 1 block i ñaõ ñöôïc caáp Öu ñieåm: Ñôn giaûn vaø hieäu quaû khi caàn tìm khoái troáng ñaàu tieân hoaëc chuoãi khoái troáng lieân tuïc Thao taùc treân bit Khuyeát ñieåm: Caàn khoâng gian löu tröõ. Ví duï Kích thöôùc block = 212 byte Kích thöôùc ñóa = 230 byte n = 230/212 = 218 bit (32 KB)
23
Phöông phaùp duøng linked list
Lieân keát caùc khoái troáng vôùi nhau Chæ caàn giöõ con troû ñeán khoái nhôù troáng ñaàu tieân treân ñóa, coù theå cache trong boä nhôù chính ñeå taêng toác Öu ñieåm: Ít laõng phí khoâng gian ñóa Khuyeát ñieåm: Khoâng hieäu quaû; trong tröôøng hôïp xaáu nhaát phaûi duyeät toaøn boä ñóa ñeå tìm khoâng gian troáng lieân tuïc (tröôøng hôïp caáp phaùt lieân tuïc)
24
Grouping vaø counting (1/2)
Phöông phaùp grouping Caùc ñòa chæ cuûa n khoái troáng ñöôïc löu trong moät khoái troáng ban ñaàu. Khoái nhôù thöù n chöùa caùc ñòa chæ cuûa n khoái nhôù troáng keá tieáp. Nhaän xeùt: grouping laø môû roäng cuûa phöông phaùp duøng linked list (laáy n = 1) Phöông phaùp counting Toå chöùc baûng chæ muïc moãi entry: ñòa chæ cuûa khoái troáng ñaàu tieân trong nhoùm khoái troáng lieân tuïc vaø moät soá ñeám soá löôïng khoái troáng. Coù theå caáp phaùt hoaëc thu hoài ñoàng thôøi nhieàu khoái nhôù lieân tuïc.
25
Grouping vaø counting (2/2)
Ví duï: Phương phaùp linked list Phương phaùp grouping: n = Block 2 löu 3, 4, Block 5 löu 8, 9, Block 10 löu 11, 12, Block 13 löu 17, 28, Block 25 löu 26, 27 Phöông phaùp counting: noäi dung index block
26
Journaling file system
Ghi nhaän caùc laàn caäp nhaät treân file system thaønh caùc giao taùc (transaction) Moïi transaction ñeàu phaûi ñöôïc ghi nhaän trong log file Moät transaction ñöôïc xem laø hoaøn taát (commit) ñaõ ñöôïc ghi nhaän ñaày ñuû trong log file (luùc naøy, file system coù theå chöa ñöôïc caäp nhaät) Khi file system ñöôïc caäp nhaät vôùi ñaày ñuû moïi taùc vuï trong transaction thì transaction seõ ñöôïc xoùa ñi trong log file Neáu file system bò hoûng heä ñieàu haønh döïa vaøo caùc transaction trong log file ñeå söûa chöõa Tham khaûo theâm Linux-ext3, JFS, NTFS The concept of journaling in file systems, or Write Ahead Logging (WAL) as it is called in database systems, was introduced to improve speed and reliability during crash recovery. The journal feature of ext4 (introduced in ext3, see [23]) is a circular buffer in which disk writes are logged before they are written to the main file system. This allows recovery because at all times the set of blocks which might be inconsistent is known, and the blocks are stored in a consistent state; either the new version in the journal, or the old version on the main file system. The journaling feature has a large impact on the patterns of disk writes as seen from the I/O scheduler. While full data journaling increases the amount of writes by a factor of two, because data is written to both the journal and the main file system, the write patterns become much nicer. The writes to the data journal, which may be either a pre-allocated file (represented using an inode number stored in the superblock–normally and extents based file with inode number 8), or a separate block device, are very sequential due to the nature of the log (append-only circular buffer). Unless the file system is very small or a custom block or journal size is used, the journal will be 128 MiB large and stored in the middle of the file system, in a non-sparse block group without any inode tables and bitmaps. After data is written to the journal, the file system may delay writing the data to the main file system longer than it could have done without journaling, especially when system calls such as fsync are used. As shown in [24], the impact of journaling depends on the workload. For sequential writes, full data journaling may halve the bandwidth, while metadata journaling has low cost. On the other hand, with highly random workloads data journaling may give a factor of 10 in performance gain, while plain metadata journaling again has little to no overhead. [23] Stephen C. Tweedie. Journaling the linux ext2fs filesystem. In The Fourth Annual Linux Expo, Durham, North Carolina, May Available from: [cited May 2009]. [24] Vijayan Prabhakaran, Andrea C. Arpaci-Dusseau, and Remzi H. Arpaci-Dusseau. Analysis and evolution of journaling file systems. In ATEC ’05: Proceedings of the annual conference on USENIX Annual Technical Conference, pages 8–8, Berkeley, CA, USA, USENIX Association.
27
Phuï luïc
28
MS-DOS File System MS-DOS directory entry
29
Windows 98 File System (1/3)
Môû roäng MS-DOS directory entry ñeå duøng trong Windows 98 Bytes
30
UNIX V7 File System (1/2) Moät UNIX V7 directory entry i-node number
31
UNIX V7 File System (2/2) Caùc böôùc ñeå doø tìm /usr/ast/mbox
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.