Monday, November 8, 1993 Secondary storage allocation, continued (chapter 9) ------------------------------------------------------------------------------- Free space management Objective: implement a free space list (list of free blocks) - issue: keep list in main memory or on the disk (speed; efficiency; persistance) --- Bit vector implementation (bit map) - Each block on disk represented by one bit in bit vector - bit is "1" if block is allocated, "0" if block is free - advantage: very compact representation - advantage: very easy and efficient to find n consecutive free blocks on disk - disadvantage: requires hardware support for efficient bit manipulation - disadvantage: inefficient unless kept in main memory; limits effective size of disk --- Linked list - link together free disk blocks with each keeping pointer to next - space for pointers can be found in the free block itself - hence list has to live on the disk - advantage: no net increase in space required either in main memory or on disk - disadvantage: must read each block, requiring unacceptable i/o time --- Grouping (modification of linked list) - if block has room for *n* pointers, store addresses of *n-1* free blocks in the first free one. Nth entry is link to another block containing the next n-1 addresses --- Counting - keep address of first free block in sequence and the number, n, of free contiguous blocks that follow. - assume that blocks are deallocated in bunches (why?) - so each entry requires more space than other schemes but there are fewer entries overall if assumption is correct ------------------------------------------------------------------------------- Allocation methods Three major schemes contiguous - file occupies contiguous addresses on disk linked - file is linked list of disk blocks indexed - pointers brought together in an index block --- Contiguous allocation---each file occupies set of contiguous addresses on disk Question: how do you *find* that contiguous set of addresses? - first fit, best fit, worst fit ... simulations: first fit and best fit > worst fit (time and storage use) neither first fit nor best fit clear better in storage use first fit generally faster - advantage of contiguous allocation reference to successive blocks requires no or little head movement - disadvantages - external fragmentation - file size fixed at creation time may limit ability to extend if too little space internal fragmentation if too much space even if accurate allocation, may not need space for quite some time - modifications, of course, may change space requirements for file - extending file if not enough space: option 1: terminate user's program (inconvenient to user; leads to over allocation) option 2: find larger hole and copy contents (time consuming) --- Linked allocation---file's blocks can be anywhere on disk; linked together - easy to create a file (just have to create new entry in device directory pointing to first block of file---nil at present) - no external fragmentation - easy to modify file (e.g., increase/decrease number of blocks in middle), especially if doubly linked - disadvantage: sequential acccess files only (have to follow pointers to find a particular byte in the middle of file) - space required for pointers is significant - not resilant to failure---blocks scattered over disk, what can you recover if you lose some pointers? (can store more info with block with greater overhead) - Variation: File Allocation Table (FAT) disk area with one entry per block, indexed by block number directory points to first entry each entry contains pointer to next block in file (last one has special EOF marker) --- Indexed allocation - index block for each file - index block contains disk addresses for blocks allocated to the file - directory points to index block - index block is fixed size; all entries are nil initially - advantage: can support direct access by indirecting through index entries - disadvantage: wasted pointer space in index block. Hence want index block to be as small as possible - unless figure out way to extend size, this will limit size of file also! - variants that permit larger size - linked scheme (from end of block to next block) - multilevel index (can increase levels to further increase number of entries - combined scheme (as in BSD Unix) given 15 pointers, let first 12 point directly to blocks 13 points to new block (one level of indirection) 14 points to block that points to block (2 levels of indirection) 15 is triple indirection ------------------------------------------------------------------------------- Disk storage management design issues - block size - free space management: free list presentation - allocation methods - fragmentation problme - access method - reliability - space efficiency - run-time overhead - limits on file size - file modification ------------------------------------------------------------------------------- Next: Disk scheduling