We were talking about the different ways to optimize IO devices. Last thing we mentioned was track head offset between tracks. File placement: Different files have different frequencies of access. - If you put the most frequently used together, seek time is reduced. - Cluster files that are used at the same time also reduce seek time. - Put files on parallel disks so we can access them in parallel. Disk caching: - If you have locality reference, caching is a good idea. - Caching can be done in two places, main memory and disk controller. Most caches are stored in DRAM, and DRAM is volatile. Read ahead is prefetching to cache Write behind is write to disk after writing to cache Cache is not as good as TLB, but is still quite effective Sequential access: - A lot of IOs are sequential, so prefetching is going to reduce access time. Data replication: - Having multiple copies of data also reduce access time. However, writing to multiple locations slows the system down. RAID: Redundant Array of Independent Disk - Small disk are cheaper D1 D2 D3 D4 Parity Disk 1,5 2,6 3,7 4,8 -- D D D D P D D D D P D D D D P D D D D P P P P P - Bottleneck on the parity disk because it has 4 times the IO compare to other disks (in this particular example) - Rotate the parity block by distributing them evenly among other disks to reduce the bottleneck RAID0 - interleave, no parity disk RAID1 - mirroring RAID4 - fixed parity disk location RAID5 - varied parity disk location ------------------------------------------------------------------------------- Directories and Other File System Topics File descriptor: - Normally live on disk; want to keep file descriptor even after the machine is turned off - inode, index node, entry is the file descriptor - inode number is the name of the file; the unique identifier for the file - IBM uses VTOC; equivalent to inode Inode fields: - Reference count - Number of links to file - Owner's user id, owner's group id - Number of bytes in file - Time last accessed, time last modified, last time inode changed - Disk block addresses, indirect blocks - Flags: inode is locked, file has been modified, some process waiting on lock - File mode: type of file: character special, directory, block special, regular, symbolic link, socket - Protection info: set user id on execution, set group id on execution, read, write, execute permissions, sticky bit - Count of shared locks on inode - Count on exclusive locks on inode - Unique identifier - File system associated with this inode - Quota structure controlling this file This is a computer system, not data processing system. When a file is open, its descriptor is kept in main memory. When the file is closed, the descriptor is stored back to disk. - There is a process open file table - There is also a system open file table; this maps names to files - System open file table allows faster access; an optimization. Files that have been opened recently are opened again in the near future. - You want only one copy of inode, so everyone sees the same one. Otherwise, locking is required. Users need a way to reference files. 1. Have a single directory for the whole disk. Use a special area of disk to hold the directory. - Contains pairs 2. Have a separate directory for each user. This is still clumsy; names from a user's different projects get confused. Still can't remember names of files. - Files have 3 part name: - File names are limited to 8 characters 3. Generalize the directory structure to a tree. - Directories are stored on disk just like regular files. - User programs can manipulate directories almost like any other file. Only special system programs may write directories. - Each directory contains pairs - There is one special directory, called the root. This directory has no name, and is the file pointed to by descriptor 2 (descriptors 0 and 1 have other speical purposes). - Full file name is the path name, i.e. full name from root. - A directory consists of some number of block as of DIRBLKSIZ bytes - Each directory block contains some number of directory entry structures, which are of variable length. - Note that in Unix, a file name is not the name of a file. It is only a name by which the kernel can search for the file. The real name is inode number. - Each pointer from a directory to a file is called a hard link - In some systems, there is a distinction between a "branch" and a "link", where the link is a secondary access path, and the branch is the primary access path. - "Erase" a file by removing a link to it. In reality, a count is kept of the number of links to a file. It is only really erased when the last link is removed. Symbolic links: - There are two ways to "link" to another directory or file. One is a direct pointer. - We can use symbolic links, by which instead of pointing to the file or directory, we have a symbolic name for that file or directory. Pros and Cons of tree structured directory scheme: - Can organize files in logical manner. Easy to find the file you're looking for. - "Name" of the file is in fact a concatenation of the path from the root. - Can have duplicate names - Can give away access to a subdirectory and the files under it, without giving access to all files. - Access to a file requires only reading the relevant directories, not the entire list of files. - Structure is more complex to move around and maintain. - A file access may require that many directories be read. Operations on files: - Open: put a file descriptor into your table of open files. There are the files that you can use. May require that locks be set, and a user count be incremented. - Close: inverse of open - Create a file: sometimes done automatically by open - Remove or erase: drop the link to the file. Put the blocks back on the free list if this is the last link. - Read: read a record from the file. - Write: like read, but may also require disk space allocation. - Rename: rename the file - Seek: move to a given location in the file - Synch: write blocks of file from disk cache back to disk - Change properties - Link: add a link to a file - Lock & Unlock: lock/unlock the file - Partial Erase (truncate)