atop case leakage

Upload: anonymous-tauubik

Post on 02-Jun-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Atop Case Leakage

    1/12

    Case study with atop: memory leakage

    Gerlof Langeveld & Jan Christiaan van Winkel

    www.atoptool.nl

    May 2010

    This docuent descri!es the analysis of a slo" syste suffering fro a #rocess "ith a eoryleakage$ %uch #rocess regularly reuests for ore dynaic eory "ith the su!routine malloc'

    "hile the #rograer has (forgotten) to free the reuested eory again$ *n this "ay the #rocessgro"s virtually as "ell as #hysically$ Mainly !y thephysicalgro"th +the #rocess, resident set si-eincreases.' the #rocess inflates like a !alloon and #ushes other #rocesses out of ain eory$ *nsteadof a healthy syste "here #rocesses reach a #ro#er !alance in their eory consu#tion' the totalsyste #erforance ight degrade /ust !y one #rocess that leaks eory$

    otice that the Linu kernel does not liit the #hysical eory consu#tion of #rocesses$ very#rocess' either running under root identity or non3root identity' can gro" unliited$ *n the last sectionof this case study' soe suggestions "ill !e given to decrease the influence of leaking #rocesses onyour overall syste #erforance$

    *n order to !e a!le to inter#ret the figures #roduced !y atop' !asic kno"ledge of Linu eory

    anageent is reuired$ The net sections descri!e the utili-ation of #hysical eory as "ell as thei#act of virtual eory !efore focussing on the details of the case itself$

    Introduction to physical memory

    The #hysical eory +45M. of your syste is su!divided in eually3si-ed #ortions' called memorypages$ The si-e of a eory #age de#ends on the C673architecture and the settings issued !y theo#erating syste$ Let,s assue for this article that the si-e of a eory #age is 8 9i:$

    5t the oent that the syste is !ooted' the co#ressed kernel iage kno"n as the file/boot/vmlinuz-.... is loaded and deco#ressed in eory$ This static #art of the kernel is

    loaded soe"here at the !eginning of the 45M eory$

    The running kernel reuires ho"ever ore s#ace' e$g$ for the adinistration of #rocesses' o#en files'net"ork sockets' $$$ !ut also to load dynaic loada!le odules$ Therefore' the kernel dynaicallyallocates eory using so3called (sla! caches)' in short slab$ When this dynaically allocated kerneleory is not needed any ore +reoval of #rocess adinistration "hen a #rocess eits' unloading aloaded odule' $$$$.' the kernel ight free this eory$ This eans that the sla! s#ace "ill shrinkagain$ otice that all #ages in use !y the kernel are eory resident and "ill never !e s"a##ed$

  • 8/11/2019 Atop Case Leakage

    2/12

    5#art fro the kernel' also #rocesses reuire #hysical #ages for their tet +code.' static data and stack$The #hysical s#ace consued !y a #rocess is called (4esident %et %i-e)' in shortRSS$ ;o" a #age!ecoes #art of the 4%% "ill !e discussed in the net section$

    The reaining #art of the #hysical eory after the kernel and #rocesses have taken their share isainly used for thepage cache$ The #age cache kee#s as uch data as #ossi!le fro the disks

    +filesystes. in eory in order to i#rove the access s#eed to disk data$ The #age cache consists oft"o #arts< the #art "here the data !locks of files are stored and the #art "here the etadata !locks+su#er!locks' inodes' !ita#s' $$$. of filesystes are stored$ The latter #art is called the (!uffer cache)$Most tools +like free' top' atop. sho" t"o se#arate values for these #arts' res#$ (cached) and

    (!uffer)$ The su of these t"o values is the total si-e of the #age cache$

    The si-e of the #age cache varies$ *f there is #lenty free eory' the #age cache "ill gro" and if thereis a lack of eory' the #age cache "ill shrink again$

    =inally' the kernel kee#s a #ool of free #ages to !e a!le to fullfill a reuest for a ne" #age and deliver itfro stock straight a"ay$ When the nu!er of free #ages dro#s !elo" a #articular threshold' #ages thatare currently occu#ied "ill !e freed and added to the free #age #ool$ %uch #age can !e retrieved fro a#rocess +current #age contents ight have to !e s"a##ed to s"a# s#ace first. or it can !e stolen frothe #age cache +current #age contents ight have to !e flushed to the filesyste first.$ *n the first case'the 4%% of the concerning #rocess shrinks$ *n the second case' the si-e of the #age cache shrinks$

    ven the sla! ight shrink in case of a lack of free #ages$ 5lso the sla! contains data that is /ust eant

    to s#eed u# certain echaniss' !ut can !e shrunk in case of eory #ressure$ 5n ea#le is theincore inode cachethat contains inodes of files that are currently o#en' !ut also contains inodes of filesthat have recently !een o#en !ut are currently closed$ That last category is ke#t in eory' /ust in casesuch file "ill !e o#ened again in the near future +saves another inode retrieval fro disk.$ *f neededho"ever' the incore inodes of closed files can !e reoved$ 5nother ea#le is the directory namecache+dentry cache. that holds the naes of recently accessed files and directories$ The dentry cache iseant to s#eed u# the #athnae resolution !y avoiding accesses to disk$ *n case of eory #ressure'the least3recently accessed naes ight !e reoved to shrink the sla!$

  • 8/11/2019 Atop Case Leakage

    3/12

    *n the out#ut of atop' the si-es of the eory co#onents that have /ust !een discussed can !e found