Detecting Memory Leak OnAIX.docx

上传人:b****5 文档编号:5771375 上传时间:2023-01-01 格式:DOCX 页数:12 大小:62.95KB
下载 相关 举报
Detecting Memory Leak OnAIX.docx_第1页
第1页 / 共12页
Detecting Memory Leak OnAIX.docx_第2页
第2页 / 共12页
Detecting Memory Leak OnAIX.docx_第3页
第3页 / 共12页
Detecting Memory Leak OnAIX.docx_第4页
第4页 / 共12页
Detecting Memory Leak OnAIX.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

Detecting Memory Leak OnAIX.docx

《Detecting Memory Leak OnAIX.docx》由会员分享,可在线阅读,更多相关《Detecting Memory Leak OnAIX.docx(12页珍藏版)》请在冰豆网上搜索。

Detecting Memory Leak OnAIX.docx

DetectingMemoryLeakOnAIX

MethodsforIdentifyingMemoryLeaksinAIXSystems

ByBarryJ.SaadandHaroldR.Lee

 

Applicationmemoryleakscanbedifficulttodetectandonmodernmulti-taskingsystemswheremanyapplicationsarerunning,itcanbeevenmoredifficulttoidentifytheoffendingprocess(es).

Thispaperwillexplorethereasonsformemoryleaks,andusingtheAIXsystemperformancetools,provideamethodologyforidentifyingthemtotheprocesslevel.Thispaperwillconsistoffourmajorparts:

(1)definitionandcausesforamemoryleakonasystem,

(2)examiningaprocessheapusingsvmonandps,(3)amethodfordetectingmemoryleaksonasystem,(4)amethodforidentifyingindividualprocesseswhichhavememoryleaks.

 

TheCausesforMemoryLeaks

TheJargonFileversion4.2.0definesamemoryleakas:

memoryleak

n.Anerrorinaprogram'sdynamic-store

allocationlogicthatcausesittofailtoreclaimdiscardedmemory,

leadingtoeventualcollapseduetomemoryexhaustion.Theseproblems

weresevereonoldermachineswithsmall,fixed-sizeaddress

spaces,andspecial"leakdetection"toolswerecommonlywritten

torootthemout.Withtheadventofvirtualmemory,itisunfortunatelyeasiertobesloppyaboutwastingabitofmemory(althoughwhenyourunoutofmemoryonaVMmachine,itmeansyou'vegota_real_leak!

).

Memoryisallocatedtoaprocessesheapbyusingthemalloc()ClibrarycallorinC++whenaclassisinstantiatedbycallinga“constructor”whichwill“setup”theclassbyallocatingtherequiredmemoryfortheclassandinitializingthemembers.Whenthememoryisnolongerrequiredbytheprocess,itisreleasedforreusebythefree()ClibrarysystemcallorinC++whentheclassis“torndown”bycallinga“destructor”whichwillreleasethememoryforreuse.Whenaprocessterminates,alloftheprogram’sdynamic-storewhichisalsocalledtheprocessesheapandstackarereturnedtooperatingsystemforreallocationtootherprocesses.

Memoryleaksoccurwhenmemorythatisallocatedtotheheapisnotreleasedbytheprocessandtheheapwillcontinuetogrow.Overtime,theprocesswilleitherallocateallofthememoryandfillits’addressspacewhichmaycauseabnormalterminationoftheprocessoritwilluseupthevirtualmemoryandcausethekerneltotakeprotectivemeasurestopreservetheintegrityoftheoperatingsystembykillingprocessestorelievethevirtualmemorydemands.Unfortunately,memoryleaksareusuallycausedbylongrunningprocessesandthealgorithmwhichthekernelusestoreducevirtualmemorydemandsistostartkillingprocessesbasedonthe“youngest”process(mostrecentlycreated)andworkingtowardthe“oldest”.Thiscanhavetheeffectofmanyprocessesbeing“killed”beforetheoffendingprocessisdealtwith.

Duetothecomplexityofprogramsandthelevelsofmemoryallocationanddeallocationabstractioninobjectorientedprograms,memoryleaksaresometimesverydifficultifnotimpossibletocompletelyeliminate.Oneapproachtothisproblemistolimitthelifespanofaprogramwheretheprogramisterminatedbeforeanypotentialmemoryleaksareallowedtogrowenoughtobecomeaproblem.TheApachewebserverisanexampleofthisapproach.WhentheApacheserverisstarted,aparentprocessstartedwhichallocatesverylittlememoryanddoesverylittlework.Theparent’sjobistoinitiallyspawnsomenumberofchildserverprocesssetbytheStartServersdirectiveintheconfigurationfile,andthentotrytomaintainthenumberofchildserverprocessbetweentwolevelseitherbycreatingorkillingadditionalprocesses.ThiswindowissetbytheMaxSpareServersandMinSpareServersdirectivesinthestartupconfigurationfile.

MaxRequestsPerChilddirective

TheMaxRequestsPerChilddirectivesetsthelimitonthenumberofrequeststhatanindividualchildserverprocesswillhandle.AfterMaxRequestsPerChildrequests,thechildprocesswilldie.IfMaxRequestsPerChildis0,thentheprocesswillneverexpire.

SettingMaxRequestsPerChildtoanon-zerolimithastwobeneficialeffects:

∙itlimitstheamountofmemorythatprocesscanconsumeby(accidental)memoryleakage;

∙bygivingprocessesafinitelifetime,ithelpsreducethenumberofprocesseswhentheserverloadreduces.

Eachchildserverprocesseswillkeeptrackofthenumberofrequestswhichitwillhandleandafterthisnumberhasbeenreached,theprocesswilldieandreturnallofthevirtualmemorytothekernelheapforreallocation.Thefollowingsnippetisfromtheconfigurationfileinstructionpage.Noticethereasongivenforlimitingthelifetimeofthechild:

NotallapplicationshavetheflexibilityofApachetodealwithpotentialleaks.Anotherstrategyisforcompaniestoscheduleregularintervalsfortheapplicationstoberecycled.Thisinvolvesshuttingdowntheapplicationsandrestartingthem.Whilesomereboottheentiresystem,thisisnotnecessaryunlesstherearemitigatingcircumstancessuchasamaintenancepatchorarebootspecifictuningchange(e.g.changingtheasynchronoussubsystemparameters).

Anotherformofprocessmemoryleakageiscalled“heapfragmentation”.Heapfragmentation,whichisthebaneofoperatingsystemdesign,issomethingdevelopershavehadtocontendwithsincethebeginning.Agooglesearchon“heapfragmentation”willreturnover64,000hitsillustratingthemagnitudeofthisissue.Heapfragmentationiswhenavailablememoryisbrokenintosmall,non-contiguousblocks.Whenthisoccurs,memoryallocationcanfaileventhoughthereisenoughmemoryintheheaptosatisfytherequest,becausenooneblockofmemoryislargeenoughtosatisfytheallocationrequest.

Forapplicationsthathavealowmemoryusage,thestandardheapisadequate;allocationswillnotfailduetoheapfragmentation.However,iftheapplicationallocatesmemoryfrequentlyandusesavarietyofallocationsizes,memoryallocationcanfailduetoheapfragmentation.

Heapfragmentationiscausedbynumeroussubsequentmalloc()sandfree()sontheprocessheapwithwidelyvaryingsizes.Thiscause“holes”toforminthecontiguousheapandunlessamalloc()issmallenoughtousethespacewithina“hole”theprocessheapmustgrowtosatisfytherequest.

Onestrategyfordealingwithheapfragmentationistoemployatechniquecalled“GarbageCollection”.Whenarequestcannotbesatisfiedfromtheheapduetofragmentation,thegarbagecollectionroutineiscalledwhichmovesallofthe“holes”totheendoftheheap,makingallofthespaceavailableattheendoftheheap.Thisgarbagecollectionisanalogoustodefragmentingaharddrive,whichmovesalloftheunusedspacetotheend.

Someoftheearlyoperatingsystemsemployedgarbagecollectiontechniqueshoweverthiscausesveryerraticperformancefromthesystemsinceallactivityhadtostopwhilethememorywasrearranged.TheJavavirtualmachine(JVM),whichisa“guest”operatingsystem,currentlyusesthismethodwithsimilarresults.Garbagecollectionisnotusedonmostoperatingsystemstodaydueinparttotheerraticperformanceitproduces.

Anotherstrategywhichsomeprogramsusetoeliminatethisistomanagetheheapinternallythroughtheuseofpointers.Whentheprogramstartsthereisasinglememoryallocationcalltoobtaintheheapandthentheprogramitselfwillallocateportionsoutofittosatisfytheinternalrequests.MostdatabaseprogramslikeOracleandDB2usethismethodofinternalmemorymanagement.

Operatingsystemdeveloperscontinuetoworkonmoreefficientmemoryallocationalgorithmsandincorporatethemintothekernelstoreducethisissuetooneonminimumimpact.TheWindows™developershaveintroducedaheapmanagercalledthe“LowFragmentationHeap”(LFH)whichplacestheholesinaCartesianbtreestructuresimilartotheAIX4.2–5.2mallocroutineknownasthe“Yorktownmalloc”sinceitwasdevelopedbytheYorktownresearchfacility.

Anewmalloccalledthe“watsonmalloc”isavailableonAIX5.3.TheWatsonmallocwhichiscachebasedandusesasimplifiedrbtree(red-blacktree)structureincreasesmallocperformanceaswellasreducingheapfragmentation.Thenewmalloc()isoptimizedforlargemulti-threadedapplicationsandtimewilltellhowmuchmoreefficientitis.Formoreinformationonthismallocrefertothefollowinglink:

Refertothesection-UnderstandingtheWatsonAllocationPolicy

Fromasystemadministrationperspective,heapfragmentationisdealtwiththesamemannerasamemoryleak.Theapplicationsmustbequiescedandrestarted.

ExaminingAProcessHeapUsingsvmonandps

Foranoverviewofthevirtualmemorymanagementataprocesslevel,refertothefollowingarticlesandinfopages:

http:

//w3-

Article–UnderstandingVirtualMemoryManagement

Alsorefertothemanorinfopageonthesvmonandpscommands

Theprocessesvirtualmemoryfootprintconsistsofthreeseparateitems.Theactual

(1)heapandthe

(2)processstackwhichisaddressedby(esid)register“2”,andthe(3)sharedlibrarydatawhichisaddressedbyregister“f”.Theloadersegment“d”issharedbyallprocessesandisignored.

#svmon-nrP262188

-------------------------------------------------------------------------------

PidCommandInusePinPgspVirtual64-bitMthrdLPage

262188mamain659804784065977NNN

VsidEsidTypeDescriptionLPageInusePinPgspVirtual

23e92workprocessprivate-532633053263

AddrRange:

0..53247:

65314..65535

1f09ddworkloadersegment-3508003508

AddrRange:

0..8684

63adfworksharedlibrarydata-

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1