Presentation on theme: "Free Space and Allocation Issues"— Presentation transcript:
1 Free Space and Allocation Issues How do I keep track of a file system’s free space?How do I allocate new disk blocks when needed?And how do I handle deallocation?
2 The Allocation/Deallocation Problem File systems usually aren’t staticYou create and destroy filesYou change the contents of filesSometimes extending their length in the processSuch changes convert unused disk blocks to used blocks (or visa versa)Need correct, efficient ways to do thatTypically implies a need to maintain a free list of unused disk blocks
3 Creating a New File Allocate a free file control block For UNIXSearch the super-block free I-node list,Take the first free I-nodeFor DOSSearch the parent directory for an unused directory entryInitialize the new file control blockWith file type, protection, ownership, ...Give new file a nameNaming issues will be discussed in the next lecture
4 Extending a File Application requests new data be assigned to a file May be an explicit allocation/extension requestMay be implicit (e.g., write to a currently non-existent block – remember sparse files?)Find a free chunk of spaceTraverse the free list to find an appropriate chunkRemove the chosen chunk from the free listAssociate it with the appropriate address in the fileGo to appropriate place in the file or extent descriptorUpdate it to point to the newly allocated chunk
5 Deleting a File Release all the space that is allocated to the file For UNIX, return each block to the free block listDOS does not free spaceIt uses garbage collectionSo it will search out deallocated blocks and add them to the free list at some future timeDeallocate the file control lockFor UNIX, zero inode and return it to free listFor DOS, zero the first byte of the name in the parent directoryIndicating that the directory entry is no longer in useDoes this approach have beneficial aspects for recovery purposes? Bad aspects for security purposes?
6 Free Space Maintenance File system manager manages the free spaceGetting/releasing blocks should be fast operationsThey are extremely frequentWe'd like to avoid doing I/O as much as possibleUnlike memory, it matters what block we chooseBest to allocate new space in same cylinder as file’s existing spaceUser may ask for contiguous storageFree-list organization must address both concernsSpeed of allocation and deallocationAbility to allocate contiguous or near-by space
7 DOS File System Free Space Management Search for free clusters in desired cylinderWe can map clusters to cylindersThe BIOS Parameter Block describes the device geometryLook at first cluster of file to choose the desired cylinderStart search at first cluster of desired cylinderExamine each FAT entry until we find a free oneIf no free clusters, we must garbage collectRecursively search all directories for existing filesEnumerate all of the clusters in each fileAny clusters not found in search can be marked as freeThis won’t be fast . . .
8 Extending a DOS FileNote cluster number of current last cluster in fileSearch the FAT to find a free clusterFree clusters are indicated by a FAT entry of zeroLook for a cluster in the same cylinder as previous clusterPut -1 in its FAT entry to indicate that this is the new EOFThis has side effect of marking the new cluster as “not free”Chain new cluster on to end of the filePut the number of new cluster into FAT entry for last cluster
9 DOS Free SpacebootblockBIOSparmsFile AllocationTabledata clusters…########-1####Each FAT entry corresponds to a cluster, and contains the number of the next cluster.A value of zero indicates a cluster that is not allocated to any file, and is therefore free.
10 The BSD File System Free Space Management BSD is another version of UnixThe details of its inodes are similar to those of Unix System VAs previously discussedOther aspects are somewhat differentIncluding free space managementTypically more advancedUses bit map approach to managing free spaceKeeping cylinder issues in mind
11 The BSD Approach Instead of all control information at start of disk, Divide file system into cylinder groupsEach cylinder group has its own control informationThe cylinder group summaryActive cylinder group summaries are kept in memoryEach cylinder group has its own inodes and blocksFree block list is a bit-map in cylinder group summaryEnables significant reductions in head motionData blocks in file can be allocated in same cylinderInode and its data blocks in same cylinder groupDirectories and their files in same cylinder group
12 BSD Cylinder Groups and Free Space cylinderscylinder groupsI-nodesdata blocksfile system & cylinder group parametersfree block bit-mapfree I-node bit-map
13 Bit Map Free Lists … Actual data blocks 111block #1(in use)block #2(in use)block #3(free)block #4(in use)block #5(free)block #6(free)Actual data blocksBSD Unix file systems use bit-maps to keep track of both free blocks and free I-nodes in each cylinder group
14 Extending a BSD/Unix File Determine the cylinder group for the file’s inodeCalculated from the inode’s identifying numberFind the cylinder for the previous block in the fileFind a free block in the desired cylinderSearch the free-block bit-map for a free block in the right cylinderUpdate the bit-map to show the block has been allocatedUpdate the inode to point to the new blockGo to appropriate block pointer in inode/indirect blockIf new indirect block is needed, allocate/assign it firstUpdate inode/indirect to point to new block
15 Unix File Extension C.G. summary Free I-node 3d bit map block pointers(in I-node)1st1stC.G.summary2nd2nd3rdFreeI-nodebit map4th3d5th6th7th1. Determine cylinder group and get its informationFreeblockbit map8th9th✔10th2. Consult the cylinder group free block bit map to find a good block11th12th3. Allocate the block to the file13th3.1 Set appropriate block pointer to it3.2 Update the free block bit map
16 Compaction and Defragmentation File I/O can be efficient if file extents are contiguousEasy if free space is well distributed in large chunksWith use, the free space becomes fragmentedAnd file I/O involves more head motionPeriodic in-place compaction and defragmentationMove the most popular files to the inner-most cylindersCopy all files into contiguous extentsLeave the free-list with large contiguous extentsHas the potential to significantly speed up file I/O
17 Compaction/Defragmentation in Real Systems Often done using a special utilityDOS file systemUnix XFS file systemGood allocation strategies can limit the needMost Linux systems don’t do it at allIf your disk is big enough not to ever fill up, not a problemOften the case in modern consumer computersBut not for many types of servers