1 / 40

Operating Systems

Operating Systems. Certificate Program in Software Development CSE-TC and CSIM, AIT September--November, 2003. Objectives discuss file storage and access on secondary storage (a hard disk). 11. File System Implementation (S&G, Ch. 11). Contents. 1. A Hard Disk 2. File System Organization

Download Presentation

Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems Certificate Program in Software DevelopmentCSE-TC and CSIM, AITSeptember--November, 2003 • Objectives • discuss file storage and access on secondary storage (a hard disk) 11. File System Implementation(S&G, Ch. 11)

  2. Contents 1. A Hard Disk 2. File System Organization 3. Allocation Methods 4. File System Management 5. Directory Implementation 6. Improving Performance

  3. 1. A Hard Disk Fig. 2.5, p.33 spindle track t actuator sector s read-writehead : cylinder c arm platter rotation

  4. Notes • To read/write disk sector • move head to cylinder (seek) • wait for sector to rotate to head (latency) • read or write (transfer) • Controller • one controller for several disks • intelligent controllers • caching continued

  5. I/O transfer is carried out in blocks • one or more sectors • Sector size: 32 - 4096 bytes • usually 512 bytes

  6. 2. File System Organization Fig. 11.1, p.370 application program logical file system file-organization module basic file system I/O control hardware devices

  7. Features • Basic File System • identifies a hardware block using drive/cylinder/track/sector numbers • I/O Control • consists of device drivers and interrupt handlers • translates hardware block commands (e.g. “retrieve block 123”) into hardware specific instructions continued

  8. File Organization Module • translates logical block addresses into physical blocks and then to drive / cylinder / track / sector numbers

  9. 2.1. Open File Table • An open() searches for a file and then records its details in an open file table • returns an index to the table entry • called a file descriptor in UNIX • the index is used by subsequent file operations

  10. Open File Table Diagram Fig. 11.2, p.372 pointer todisk block index file name permissions access dates 0 test.c rw- rw- rw- . . . . . . 1 mail.txt rw- --- --- : : : : n

  11. 3. Allocation Methods • How is space allocated to files on a disk? • Aims: • utilize disk space effectively • allow fast file access • Three main methods: • contiguous allocation • linked allocation • indexed allocation

  12. 3.1. Contiguous Allocation • Each file occupies a set of contiguous (continuous) blocks on the disk. • Supports fast sequential and direct (random) access • e.g. the 5th block of a file starting at block 19 is at block 24 (19+5)

  13. 6 0 1 2 3 4 5 7 26 11 31 30 25 28 12 14 29 13 15 24 17 23 22 19 16 18 27 21 20 Diagram Fig. 11.3, p.374 'physical block' view directory file start lengthcount 0 2tr 14 3mail 19 6list 28 4f 6 2 8 9 10

  14. Problems • Finding space for a new file or a resized file. • Determining size requirements. • External fragmentation of the hard disk.

  15. 3.2. Linked Allocation • Each file is stored as a linked list of disk blocks • the disk blocks may be anywhere on the disk

  16. 0 2 3 4 5 6 7 21 15 28 29 31 22 26 11 24 30 13 12 19 18 14 27 20 23 17 Diagram Fig. 11.4, p.377 directory file start endjeep 1 10 9 25 8 9 10 16 25 16 1 25 -1

  17. Advantages • Solves the problems with contiguous allocation • the space allocation problem • no external fragmentation • Fast for sequential access.

  18. Disadvantages • Direct access is not supported (efficiently). • Space overhead of pointers • solution: cluster disk blocks • Reliability if a pointer ‘fails’ • solution: use richer (bigger) links

  19. 3.2.1. File-allocation Table (FAT) Fig. 11.5, p.378 0 directory entry test . . . 217 217 name startblock 618 339 eof 618 339 no. of disk blocks FAT

  20. Notes • The table has one entry for each disk block on the disk, and is indexed by block number. • Records the sequence of blocks used by each file. • No need for pointers in the actual disk blocks. continued

  21. Used by MS-DOS and OS/2 • Drawback: the disk head needs to do many seeks: • move to the start of the FAT • then move to the required FAT entry • then move to the actual disk block

  22. 3.3. Indexed Allocation • A modification of linked allocation where the disk block pointers for a file are all placed in an index block.

  23. 0 2 3 4 5 6 7 20 14 28 29 30 31 11 15 24 21 12 19 13 26 17 27 23 22 18 Diagram Fig. 11.6, p.379 directory file index blockjeep 19 1 8 9 10 91611025-1-1-1 16 19 25

  24. Notes • Supports direct access. • Wasteful if only a few pointers are stored in the index block.

  25. 3.3.1. Variations • Linked Scheme • link together the (smaller) index blocks used for a file • Multilevel Index • use a first-level index block to point to second-level index blocks which point to the actual disk blocks • supports much bigger files continued

  26. . . . data mode data owners (2) data timestamps (3) data size data 12 block count . . . data direct blocks . . . data data single indirect . . . data double indirect triple indirect data • Combined Schemes • e.g. the UNIX file index block (inode) : ::: : : Fig. 11.7, p.381

  27. 3.4. Performance • Allocation methods vary in their: • storage efficiency • disk block access times • Measurements depend on the file mix in the OS • e.g. no. of sequential access files vs. no. of direct/random access files continued

  28. Contigous allocation • constant time access for sequental or direct access files • Linked allocation • should not be used for direct access files continued

  29. Indexed allocation • faster if the index block for the file is already in memory • large files require more index block searching, so are slower to access

  30. Performance Optimisations • Since CPU speeds are often 10,000 times faster than hard disk speeds, then very complex disk accessing optimisations, coded in software/hardware are worthwhile.

  31. 4. File Space Management • Use a free-space list to record which blocks are free (i.e. not allocated to a file or directory). • Implementation approaches: • bit vector • linked list • grouping • counting

  32. 4.1. Bit Vector • Represent each free block by a ‘1’ bit, each allocated block as a ‘0’ bit in a bit vector. • Example: free blocks are 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18, 25, 26, 27,… • Bit vector: 001111001111110001100000011100000... continued

  33. OSes contain fast bit manipulation instructions to find a free block or blocks quickly. • Problem: size of the bit vector • 1 bit required for each disk block

  34. 4.2. Linked List Fig. 11.8, p.384 • Link together all the free disk blocks. • Problems: • traversal speed • pointer failure 0 1 2 3 4 5 6 7 8 9 10 11 free-spacelist head 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

  35. 4.3. Grouping • Store the addresses of the n free blocks in the first free disk block. • Use pointers to link together multiple disk blocks of this information.

  36. 4.4. Counting • In contiguous allocation schemes, free blocks are usually contiguous. • Instead of making a list of n free disk blocks, store the address of the first free block and a counter (containing n).

  37. 5. Directory Implementations • Linear list of files • simple to code • time-consuming to search • solution: cache recently used directory info. • Hash table • compute the index into a list of files based on a hash function (applied to the file name) • collisions • cost of directory reorganization

  38. 6. Improving Performance • Most disk controllers include local memory to store previously accessed tracks • repeated accesses are faster • called a track cache (or track buffer) • Some systems store recently accessed disk blocks in memory • called a disk cache (or block buffer) continued

  39. Some systems support RAM disks (virtual disks) in memory • users can carry out standard disk operations, but they are much faster since the data never leaves memory

  40. Diagram Fig. 11.9, p.389 ram disk harddisk trackcache CPU disk cache disk controller main memory

More Related