You are on page 1of 4

Fileallocationmethod

Easeofaccessingadiskdirectlyprovideflexibilityinimplementingafile.Themainproblemin
implementationishowtoallocatethefilestoadisk,sothediskcanterutilisasieffectivelyand
filescanbeaccessedquickly.Therearethreemainmethods,accordingtothebook"Applied
OperatingSystemConcepts:FirstEdition"byAviSilberschatz,PeterGalvinandGregGagneto
allocatediskspacewhichiswidelyused,contiguous,linked,andindexed.

contiguousallocation
Thismethodputseachfileinasequentialsetofblocksonthedisk.Addressdiscstatinga
linearsequence.Withthislinearsequencethenthediskheadmovesonlyiftheaccessofthe
lastsectorofacylinderintothefirstsectorofthenextcylinder.Searchtime(seektime)and
lotsofdiskseekneededtoaccessfilesontheallocationsidebysideisveryminimal.Examples
ofoperatingsystemsthatusecontiguousallocationistheIBMVM/CMSbecausethis
approachproducesagoodperformance.
Contiguousallocationofafileisidentifiedbyaddressandlengthofthedisk(inunitsof
blocks)fromthefirstblock.So,supposethereisafilewithnblockslongandstartsfromthe
locationofbthenthefileoccupiesblocksb,b+1,b+2,...,b+n1.Directoryforeachfile
indicatesthebeginningandthelengthoftheblockaddressareaallocatedtothefile.Thereare
twokindsofwaystoaccessfilesthatareallocatedbythismethod,namely:
Sequentialaccess,filesystemsknowtheaddressofthelastblockofthediskandreadthenext
blockifnecessary.
Directaccess,fordirectaccesstoblockifromafilethatstartsatblockb,itcandirectlyaccess
theblockb+i.
Thedifficultyofthecontiguousallocationmethodistofindspacefornewfiles.Diskspace
allocationproblemwiththismethodisanapplicationproblemofdynamicstorageallocation
(adynamicstorageallocation),thatishowtomeetthedemandofsizenfromalistofempty
space.Commonstrategiesarefirstfitandbestfit.Bothstrategiesarehavingproblemsof
externalfragmentation,whereifthefileisallocatedanddeletedthediskfreespace
fragmentedintosmallpieces.Thiswillbeaproblemwhenmanysmallpiecescannotmeet
demandbecauseofsmallpiecesnotlargeenoughtostorethefile,sothereisplentyofspaceis
wasted.
Anotherproblemisdetermininghowmuchspaceisneededforafile.Whenafileiscreated,
theamountoffilespaceshouldbedeterminedandallocated.Ifthespaceallocatedistoosmall
thenthefilecannotbeenlargedfromthathasbeenallocated.Toovercomethistherearetwo
possibilities.First,userprogramscanbeterminatedwithanappropriateerrormessage.Then,
theusermustallocateadditionalspaceandruntheprogramagain,butthishasgeneratedcost
moreexpensive.Tofixthis,userscanperformbetterestimateofthespaceshouldbeallocated
toafilebutthiswillgetridofdiskspace.Thesecondpossibilityistofindalargerspace,then

copythecontentsofthefileintothenewspaceandmengkosongkanspacepreviously.Itspent
quitealot.Althoughtheamountofspaceneededforafilecanbeknown,initialallocations
willbeinefficient.Filesizeisincreasedintheperiodoftimeshouldbeallocatedtothespace
enoughforthesizeoftheend,thoughspacewillnotbeusedforalongtime.Thiswillcause
thefilewithalargeamountofinternalfragmentation.
Toavoidthesethings,someoperatingsystemsmodifytheschemeofallocationmethodsside
byside,inwhichsmallpiecesofsequenceindiskspaceisinitializedfirst,thenwhenthe
amountofdiskspaceisnotbigenough,smallpiecesofanothersequence,addedtotheinitial
allocation.Suchaneventiscalledanextension.Internalfragmentationcanstilloccurifthe
extensionextensionistoolargeandexternalfragmentationisstillaproblemsotheextension
extensionofvarioussizesareallocatedanddidealokasi.

LinkedAllocation
Thismethodresolvedalltheissuescontainedinthecontiguousfileallocation.Withthis
method,eachfileisalinkedlistofdiskblocks,wherethediskblockscanbescatteredonthe
disk.Eachdirectorycontainsapointer(pointer)tothebeginningandendoftheblockofa
file.Eachblockhasapointertothenextblock.Tocreateanewfile,weeasilycreatenew
entriesinthedirectory.Withthismethod,eachdirectoryentryhasapointertothestartblock
ofthediskfromthefile.Thispointerisinitializedtonil(pointervaluetotheendofthelist)to
indicateanemptyfile.Thesizeisalsosetto0.Writingafilecausesthediscoveryoftheempty
blockspacemanagementsystem(freespacemanagementsystem),andanewblockiswritten
andattachedtotheendofthefile.Toreadafile,simplybyreadingtheblocksbyfollowingthe
movementofthepointer.
Thismethoddoesnothaveexternalfragmentationandwecanuseanemptyblockcontained
inthelistofemptyspacetomeetuserdemand.Thesizeofthefileneednotbespecifiedwhen
filesarefirstcreated,sothefilesizecangrowaslongasthereareemptyblocks.
Thismethodcertainlyhasaloss,thatthismethodcanonlybeusedeffectivelyforasequential
fileaccess(sequentialaccessfile).Tofindtheithblockofafile,itmustbeginfromthe
beginningofthefileandfollowthepointeruntilitisintheithblock.Everyaccessto
bookmarkswillreadthediscandsometimesdoasearchthedisk(diskseek).Thisisvery
inefficienttosupporttheabilityofdirectaccess(directaccess)tothefileusingthemethodof
allocationofthelink.Anotherdisadvantageofthismethodisthatspaceshouldbeprovidedfor
thepointer.Thecommonsolutiontothisproblemistocollectthesmallestallianceblocks
calledclustersandallocatetheclustersratherthanblock.Withthissolution,then,thepointer
usingthediskspaceafilewithaverysmallpercentage.Thismethodmakeslogicaltophysical
blockmappingremainssimple,butincreasesthediskthroughputandminimizethespace
requiredforblockallocationandmanagementofanemptylist(freelistmanagement).Asa
resultofthisapproachistheincreasedinternalfragmentation,becausemorespaceiswastedif
aclusterofpartiallyfullratherthanwhenablockispartiallyfull.Thereasontheclusterisused
bymostoperatingsystemsistheabilitythatcanincreasediskaccesstimesforvarious
algorithms.

Anotherproblemistheproblemofthedurabilityofthismethod.Becauseallfilesare
interconnectedwiththepointerthatspreadinallpartsofthedisk,whathappensifapointeris
corruptedormissing.Thiscausesthefiletoconnecttothelistofemptyspaceortoanother
file.Onesolutionistousedoublelinkedlistorsavethefilenameandrelativenumberof
blocksineachblock,butthissolutionrequiresmoreattentiontoeachfile.
Importantvariationofthismethodisusingthefileallocationtable(FAT),whichisusedbythe
operatingsystemMSDOSandOS/2.Theinitialpartofdisksoneachpartitiontoberemoved
toplacethetable.Thistablehasaninsertforeachdiskblock,andgiventheindexbythe
numberofblocks.Enterthedirectorycontainingtheblocknumbersoftheinitialblock
file.Enterthetablegiventheindexbynumberandthentheblockcontainsblocknumbersfor
thenextblockfromthefile.Thischaincontinuesuntilthelastblock,whichhasspecialvalue
asanendoffileenterthetable.Blocksnotusedgiventhevalue0.Toallocateanewblocktoa
fileonlytofindavalueof0thefirstinthetable,andreplacethevalueendofthepreviousfile
withthenewblockaddress.FATallocationmethodcanresultinthenumberofsearchesa
significantdiskhead,ifnotinthecachefile.DiskheadmustmovefromtheinitialFAT
partitiontoreadandfindthelocationoftheblockinquestion,thenfindthelocationofthe
blockitself.Thebadcases,thetwomovementsoccurredforeachblock.Theadvantageof
randomaccesstimeincreases,aresultofthediskheadtoseekthelocationofanyblockby
readingtheinformationintheFAT.

IndexedAllocation
Allocationmethodwithberangkaitosolvetheproblemofexternalfragmentationand
declaringthesizeofthecontiguousallocationmethod.AfterallwithoutFAT,berangkai
allocationmethoddoesnotsupportdirectaccessefficiency,becausethepointertoablock
litteredwithblockinthediskandneedtobeobtainedsequentially.Methodofallocationwith
indexresolvethisproblembycollectingallthebookmarkstobeinonelocation,calledthe
blockindex(indexblocks).Eachfilehasablockindex,whichisanarrayofarrayaddresses
diskblock.Directorieshavetheaddressoftheblockindex.Whenafileiscreated,allpointing
intheblockindexissettonil.Whentheithblockwasfirstwritten,ablockobtainedfromthe
regulatoryspacefreespacemanageranditsaddressisplacedintoablockoftheithindex.
Thismethodsupportsdirectaccess,withoutexternalfragmentationsinceanyemptyblocksin
thedisktomeetthedemandforadditionalspace.Butthismethodcanleadtonospaceis
wasted.Excessoftheblockpointerindexisgenerallygreaterthanthatoccursinberangkai
allocationmethod.
Mechanismstodealwithamatterofhowbigtheblockindex,whichisrequiredasfollows:
Linkedscheme:forlargefiles,donebyconnectingafewblocksintoasingleindex.
Multilevelindex:avariantofthechainrepresentationistousethefirstlevelindexblock
pointstothesetofsecondlevelindexblock,whicheventuallypointedtothefileblocks.
Combinedscheme:usedbytheBSDUNIXsystemisbydefiningthe15pointerfromtheindex

blockintheblockfileindex.12Thefirstpointerpointstothedirectblockswhichstoresthe
addressesofblocksthatcontaindatafromthefile.3Thenextpointerpointstoindirect
blocks.Thefirstindirectblockpointeristheaddressofthesingleindirectblock,whichisan
indexblockthatcontainstheaddressesofblocksthatcontaindata.Thenthere'sthedouble
indirectblockpointerthatcontainstheaddressofablockthatcontainstheaddressesofblocks
thatcontainpointerstoactualdatablocks.

PerformanceFileSystem
Onedifficultyincomparingtheperformanceofthesystemistodeterminehowthesystemwill
beused.Systemsthatusemoresequentialaccess(insequence)willusedifferentmethodswith
asystemthatmorefrequentuseofrandomaccess(random).Foranytypeofaccess,allocation
ofcontiguousonlyrequiresoneaccesstogetadiskblock.Becausewecansavetheinitial
addressofthefileinmemory,thediskaddressontheithblockcanbeimmediatelycalculated
andreaddirectly.
Fortheallocationberangkai(linkedlist),wecanalsosavetheaddressofthenextblockinto
memory,thenreaditdirectly.Thismethodisverygoodforsequentialaccess,butfordirect
access,accesstotheblocktodiskreadikemungkinanrequireasmuchasitimes.Thisproblem
indicatesthattheallocationberangkaishouldnotbeusedforapplicationsthatrequiredirect
access.
Therefore,somesystemssupportdirectaccessbyusingtheallocationadjoining(contiguous
allocation),aswellasaccesssequencewithallocationberangkai.Forthesesystems,access
typemustbedeclaredatthetimeoffilecreated.Filesthatarecreatedforsequentialaccess(in
sequence)willbebundled,andcannotbeusedfordirectaccess.Filesthatarecreatedfor
directaccesswillcoexistandcansupportbothdirectaccesswouldaccessanysequence,by
declaringamaximumdistance.Notethattheoperatingsystemmustsupportthedata
structuresandalgorithmsaresuitabletosupporttheallocationoftheabovetwomethods.
Allocationbyusingmorecomplexindices.Iftheblockindexhasbeenfoundinmemory,access
canbedonedirectly.However,storingtheindexinthememoryblockrequirespace(space)
aregreat.Ifmemoryspaceisnotavailable,thenwemighthavetoreadtheindexblockfirst,
thenthedesireddatablock.Fortwolevelindex,anindexreadingoftwoblocksmaybe
needed.Forverylargefiles,accessingtheblockneartheendofafilewillrequirereadingthe
entireblockindextofollowthechainpointerbeforethedatablockcanberead.Thus,the
performanceallocationisdeterminedbyusinganindex:anindexstructure,filesize,and
positionoftheblocksasdesired.
Somesystemscombinecontiguousallocationwithanallocationindex.Thetrickistouse
contiguousallocationforsmallfiles(34blocks),andautomaticallyswitchtotheallocationof
theindexifthefileisgettingbigger.

You might also like