欢迎来到天天文库
浏览记录
ID:43515653
大小:1.16 MB
页数:71页
时间:2019-10-09
《lecture_15_file_system Implementation》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
File-systemImplementationZhaoFangOperatingSystems-forthecollagestudents GoalforTodayFile-SystemStructureFile-SystemImplementationDirectoryImplementationFree-SpaceManagementUnixFileManagementLinuxVirtualFileSystemWindowsFileSystem ObjectivesTodescribethedetailsofimplementinglocalfilesystemsanddirectorystructuresTodescribetheimplementationofremotefilesystemsTodiscussblockallocationandfree-blockalgorithmsandtrade-offs File-SystemStructureFilestructureLogicalstorageunitCollectionofrelatedinformationFilesystemresidesonsecondarystorage(disks)Provideduserinterfacetostorage,mappinglogicaltophysicalProvidesefficientandconvenientaccesstodiskbyallowingdatatobestored,locatedretrievedeasily File-SystemStructureDiskprovidesin-placerewriteandrandomaccessI/Otransfersperformedinblocksofsectors(usually512bytes)Filecontrolblock–storagestructureconsistingofinformationaboutafileDevicedrivercontrolsthephysicaldeviceFilesystemorganizedintolayers Typicalsoftwareorganization DeviceDriversLowestlevelCommunicatesdirectlywithperipheraldevicesResponsibleforstartingI/OoperationsonadeviceProcessesthecompletionofanI/Orequest BasicFileSystemPhysicalI/OPrimaryinterfacewiththeenvironmentoutsidethecomputersystemDealswithexchangingblocksofdataConcernedwiththeplacementofblocksConcernedwithbufferingblocksinmainmemory BasicI/OSupervisorResponsibleforallfileI/Oinitiationandtermination.Controlstructuresdealwith•DeviceI/O,•Scheduling,•Filestatus.•SelectsandschedulesI/Owiththedevice LogicalI/OEnablesusersandapplicationstoaccessrecordsProvidesgeneral-purposerecordI/OcapabilityMaintainsbasicdataaboutfile ElementsofFileManagement File-SystemImplementationBootcontrolblockcontainsinfoneededbysystemtobootOSfromthatvolumeNeededifvolumecontainsOS,usuallyfirstblockofvolumeVolumecontrolblock(superblock,masterfiletable)containsvolumedetailsTotal#ofblocks,#offreeblocks,blocksize,freeblockpointersorarrayDirectorystructureorganizesthefilesNamesandinodenumbers,masterfiletable File-SystemImplementation(Cont.)Per-fileFileControlBlock(FCB)containsmanydetailsaboutthefileinodenumber,permissions,size,datesNFTSstoresintoinmasterfiletableusingrelationalDBstructures In-MemoryFileSystemStructuresMounttablestoringfilesystemmounts,mountpoints,filesystemtypesThefollowingfigureillustratesthenecessaryfilesystemstructuresprovidedbytheoperatingsystemsPlusbuffersholddatablocksfromsecondarystorageOpenreturnsafilehandleforsubsequentuseDatafromreadeventuallycopiedtospecifieduserprocessmemoryaddress In-MemoryFileSystemStructures PartitionsandMountingPartitioncanbeavolumecontainingafilesystem(“cooked”)orraw–justasequenceofblockswithnofilesystemRootpartitioncontainstheOS,otherpartitionscanholdotherOses,otherfilesystems,orberawMountedatboottimeOtherpartitionscanmountautomaticallyormanually VirtualFileSystemsVirtualFileSystems(VFS)onUnixprovideanobject-orientedwayofimplementingfilesystemsVFSallowsthesamesystemcallinterface(theAPI)tobeusedfordifferenttypesoffilesystemsSeparatesfile-systemgenericoperationsfromimplementationdetailsImplementsvnodeswhichholdinodesornetworkfiledetails VirtualFileSystems(Cont.)TheAPIistotheVFSinterface,ratherthananyspecifictypeoffilesystem VirtualFileSystemImplementationForexample,Linuxhasfourobjecttypes:inode,file,superblock,dentryVFSdefinessetofoperationsontheobjectsthatmustbeimplementedEveryobjecthasapointertoafunctiontableFunctiontablehasaddressesofroutinestoimplementthatfunctiononthatobject BlocksandrecordsRecordsarethelogicalunitofaccessofastructuredfileButblocksaretheunitforI/OwithsecondarystorageThreeapproachesarecommonFixedlengthblockingVariablelengthspannedblockingVariable-lengthunspannedblocking FixedBlockingFixed-lengthrecordsareused,andanintegralnumberofrecordsarestoredinablock.Unusedspaceattheendofablockisinternalfragmentation FixedBlocking VariableLengthSpannedBlockingVariable-lengthrecordsareusedandarepackedintoblockswithnounusedspace.SomerecordsmayspanmultipleblocksContinuationisindicatedbyapointertothesuccessorblock VariableBlocking:Spanned Variable-lengthunspannedblockingUsesvariablelengthrecordswithoutspanningWastedspaceinmostblocksbecauseoftheinabilitytousetheremainderofablockifthenextrecordislargerthantheremainingunusedspace. VariableBlocking:Unspanned SecondaryStorageManagementTheOperatingSystemisresponsibleforallocatingblockstofilesTworelatedissuesSpacemustbeallocatedtofilesMustkeeptrackofthespaceavailableforallocation Fileallocationissues1.Whenafileiscreated–isthemaximumspaceallocatedatonce?2.Spaceisaddedtoafileincontiguous‘portions’Whatsizeshouldbethe‘portion’?3.Whatdatastructureshouldbeusedtokeeptrackofthefileportions? PreallocationvsDynamicAllocationNeedthemaximumsizeforthefileatthetimeofcreationDifficulttoreliablyestimatethemaximumpotentialsizeofthefileTendtooverestimatedfilesizesoasnottorunoutofspace PortionsizeTwoextremes:PortionlargeenoughtoholdentirefileisallocatedAllocatespaceoneblockatatimeTrade-offbetweenefficiencyfromthepointofviewofasinglefile,ortheoverallsystemefficiency ContiguousAllocationFileblocksarestoredcontiguouslyondiskToallocateafile,SpecifythefilesizeSearchthediskallocationbitmapforconsecutivefreeblocksdatablocklocationnumberofblocksFileheader ContiguousAllocationMappingfromlogicaltophysicalQLA/512RBlocktobeaccessed=Q+startingaddressDisplacementintoblock=R ProsandConsofContiguousAllocation+Fastsequentialaccess+EaseofcomputingrandomfilelocationsAddinganoffsettothefirstdiskblocklocation-Externalfragmentation-Difficultyingrowingfiles Segment-BasedAllocationNeedsasegmenttabletoallocatemultiple,contiguousregionsofblocksbegin,endblocksbegin,endblocksFileheader ProsandConsofSegment-BasedAllocation+Relaxtherequirementsforlargecontiguousdiskregions-Fragmentation100%Segment-basedallocationIndexedallocation-Randomaccessesnotasfastaspurecontiguousallocation Linked-ListAllocationEachfileblockonadiskisassociatedwithapointertothenextblockAspecialmarkertoindicatetheendofthefilee.g.,MS-DOSfilesystemFileattributetable(FAT)datablocklocationnextblockentryFileheader ProsandConsofLinked-ListAllocation+Filescangrowdynamicallywithincrementalallocationofblocks-SequentialaccessmaysufferBlocksmaynotbecontiguous-HorriblerandomaccessesMayinvolvemultiplesequentialsearches-UnreliableAcorruptedpointercanleadtolossoftheremainingfile LinkedAllocation File-AllocationTable IndexedAllocationUsesapreallocatedindextodirectlytrackthefileblocklocationsdatablocklocationdatablocklocationFileheader ExampleofIndexedAllocation ProsandConsofIndexedAllocation+Fastlookupsandrandomaccesses-FileblocksmaybescatteredalloverthediskPoorsequentialaccessNeedsdefragmenter-Needstoreallocateindexasthefilesizeincreases MultilevelIndexedAllocationCertainindexentriespointtoindexblocks,asopposedtodatablocks(e.g.,Linuxext2)datablocklocationdatablocklocation12datablocklocationdatablocklocationindexblocklocationindexblocklocationindexblocklocationFileheader MultilevelIndexedAllocationAsingleindirectblockcontainspointerstodatablocksAdoubleindirectblockcontainspointerstosingleindirectblocksAtripleindirectblockcontainspointerstodoubleindirectblocks ProsandConsofMultilevelIndexedAllocation+OptimizedforsmallandlargefilesSmallfilesaccessedthroughthefirst12pointersLargefilescangrowincrementally-Multiplediskaccessestofetchadatablockundertripleindirectblock-Largestfilesizecappedbythenumberofpointers-Arbitraryfilesizeboundariesamonglevels HashedAllocationAllocatesadiskblockbyhashingtheblockcontenttoadisklocationdatablocklocationdatablocklocationdatablocklocationdatablocklocationOldfileheaderNewfileheader ProsandConsofHashedAllocation+Fileblocksofthesamecontentcansharethesamediskblocktosavestoragee.g.,emptyblocks+GoodforbackupsandarchivalSmallmodificationstoalargefileresultinonlyadditionalstorageofthechanges-Poordiskperformance FreeSpaceManagementJustasallocatedspacemustbemanaged,somusttheunallocatedspaceToperformfileallocation,weneedtoknowwhichblocksareavailable.Weneedadiskallocationtableinadditiontoafileallocationtable BitTablesThismethodusesavectorcontainingonebitforeachblockonthedisk.Eachentryofa0correspondstoafreeblock,andeach1correspondstoablockinuse.Advantages:WorkswellwithanyfileallocationmethodSmallaspossible ChainedFreePortionsThefreeportionsmaybechainedtogetherbyusingapointerandlengthvalueineachfreeportion.NegligiblespaceoverheadSuitedtoallfileallocationmethodsLeadstofragmentation IndexingtreatsfreespaceasafileandusesanindextableasitwouldforfileallocationForefficiency,theindexshouldbeonthebasisofvariable-sizeportionsratherthanblocks.Thus,thereisoneentryinthetableforeveryfreeportiononthedisk.Thisapproachprovidesefficientsupportforallofthefileallocationmethods. FreeBlockListEachblockisassignedanumbersequentiallythelistofthenumbersofallfreeblocksismaintainedinareservedportionofthedisk. VolumesAcollectionofaddressablesectorsinsecondarymemorythatanOSorapplicationcanusefordatastorage.Thesectorsinavolumeneednotbeconsecutiveonaphysicalstoragedevice;insteadtheyneedonlyappearthatwaytotheOSorapplication.Avolumemaybetheresultofassemblingandmergingsmallervolumes. UNIXFileManagementSixtypesoffilesRegular,orordinaryDirectorySpecialNamedpipesLinksSymboliclinks InodesIndexnodeControlstructurethatcontainskeyinformationforaparticularfile.SeveralfilenamesmaybeassociatedwithasingleinodeButanactiveinodeisassociatedwithonlyonefile,andEachfileiscontrolledbyonlyoneinode FreeBSDInodesinclude:ThetypeandaccessmodeofthefileThefile’sownerandgroup-accessidentifiersCreationtime,lastread/writetimeFilesizeSequenceofblockpointersNumberofblocksandNumberofdirectoryentriesBlocksizeofthedatablocksKernelandusersetableflagsGenerationnumberforthefileSizeofExtendedattributeinformationZeroormoreextendedattributeentries FreeBSDInodeandFileStructure FileAllocationFileallocationisdoneonablockbasis.AllocationisdynamicBlocksmaynotbecontiguousIndexmethodkeepstrackoffilesPartofindexstoredinthefileinode.InodeincludesanumberofdirectpointersAndthreeindirectpointers UNIXDirectoriesandInodesDirectoriesarefilescontaining:alistoffilenamesPointerstoinodes UNIXFileAccessControlFilesareassociatedwithpermissionsfor:UserIDGroupIDEveryoneelse UNIXFileAccessControl LinuxVirtualFileSystemUniformfilesysteminterfacetouserprocessesRepresentsanyconceivablefilesystem’sgeneralfeatureandbehaviorAssumesfilesareobjectsthatsharebasicpropertiesregardlessofthetargetfilesystem KeyingredientsofVFSStrategyAuserprocessissuesafilesystemcall(e.g.,read)usingtheVFSfilescheme.TheVFSconvertsthisintoaninternalfilesystemcallThenewcallispassedtoamappingfunctionforaspecificfilesystem TheroleofVFSwithintheKernel PrimaryObjectsinVFSSuperblockobjectaspecificmountedfilesystemInodeobjectaspecificfileDentryobjectaspecificdirectoryentryFileobjectanopenfileassociatedwithaprocess WindowsFileSystemKeyfeaturesofNTFSRecoverabilitySecurityLargedisksandlargefilesMultipledatastreamsJournalingCompressionandEncryption NTFSVolumeandFileStructureSectorThesmallestphysicalstorageunitonthediskAlmostalways512bytesClusterOneormorecontiguoussectorsVolumeLogicalpartitiononadisk EfficientwithLargeFilesVolumeSizeSectorsperClusterClusterSize512Mbyte1512bytes512Mbyte–1Gbyte21K1–2Gbyte42K2–4Gbyte84K4–8Gbyte168K8–16Gbyte3216K16–32Gbyte6432K>32Gbyte12864K NTFSVolumeLayoutEveryelementonavolumeisafile,andeveryfileconsistsofacollectionofattributes.Eventhedatacontentsofafileistreatedasanattribute. WindowsNTFSComponents Assignments1.Considerasystemthatsupportsthestrategiesofcontiguous,linked,andindexedallocation.Whatcriteriashouldbeusedindecidingwhichstrategyisbestutilizedforaparticularfile?2.ExplainhowtheVFSlayerallowsanoperatingsystemtosupportmultipletypesoffilesystemseasily.
此文档下载收益归作者所有
举报原因
联系方式
详细说明
内容无法转码请点击此处