Home
%3CLINGO-SUB%20id%3D%22lingo-sub-333991%22%20slang%3D%22en-US%22%3EThe%20Tao%20of%20a%20Deadlock%20Scheduler%20in%20SQL%20Server%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-333991%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Dec%2014%2C%202012%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EJust%20thought%20I%20would%20summarize%20the%20concept%20of%20a%20SOS%20Scheduler%20and%20a%20Deadlocked%20Scheduler%26nbsp%3Bsince%20many%20have%20inquired%20over%20the%20years%20for%20a%20brief%20summary%20of%20these%20concepts%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EUMS%2FSOS%20Scheduler%20in%20SQL%26nbsp%3B%20Server%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20SQL%20Server%207.0%2C%20SQL%26nbsp%3B%20Server%20has%20used%20its%20own%20scheduling%20mechanism%2C%20called%20UMS%20(User-mode%20scheduler)%26nbsp%3B%20in%207.0%20and%202000%20and%20later%20renamed%20to%20SOS%20(SQL%20on%20OS%20scheduler).%20UMS%2FSOS%20is%20a%26nbsp%3B%20cooperative%20(non-preemptive)%20scheduler%20which%20means%20that%20it%20relies%20on%20threads%20to%20voluntarily%20give%20up%20CPU%20usage%20-%20yield%20-%20to%20the%20next%20thread%20waiting%20in%20line.%20That%20means%20that%20there%20are%20locations%20in%20the%20SQL%20Server%20code%20where%20the%20Microsoft%20developer%20built%20in%20yield%20points%2C%20causing%20execution%20to%20%E2%80%9Cpause%E2%80%9D%20and%20gracefully%20let%20another%20citizen%20in%20the%20SQL%20kingdom%20to%20exercise%20its%20right%20to%20execute.%20Of%26nbsp%3B%20course%2C%20once%20a%20thread%20%22leaves%22%20SQL%20Server%20SOS%20kingdom%2C%20that%20thread%20is%20still%20handed%20off%20to%20the%20Windows%20preemptive%20scheduler%20(ruled%20by%20another%20Master%20so%20to%20speak).%20The%20goal%20of%20SOS%20is%20for%20SQL%20Server%20to%20expose%20only%20one%26nbsp%3B%20thread%20at%20a%20time%20per%20CPU%20and%20thus%20minimize%20competition%20among%20SQL%20threads%20exposed%20to%20the%20OS.%20The%20ultimate%20goal%20is%20to%20reduce%20the%20very%20expensive%20kernel-mode%20context%20switching%20from%20one%20thread%20to%20another.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20SQL%20Server%20uses%20a%20cooperative%20scheduler%2C%20it%20relies%20on%20the%20good%20heart%20of%20each%20developer%20who%26nbsp%3B%20writes%20code%20in%20SQL%20Server%20to%20call%20a%20Yield()%20function%20of%20some%20kind%20that%20prevents%20the%20thread%20from%20monopolizing%20the%20CPU.%20But%20even%20the%20best-intentioned%20developer%20could%20make%20mistakes%20(and%20introduce%20a%26nbsp%3B%20bug%20in%20his%20code)%2C%20or%20a%20SQL%20thread%20could%20be%20at%20the%20mercy%20of%20some%20external%20component%20%E2%80%93%20like%20calling%20into%20code%20outside%20of%20SQL%20Server.%20Because%20of%20that%2C%20the%20SOS%20scheduler%20has%20a%20dedicated%20thread%20-Scheduler%20Monitor%20-%20that%20periodically%20checks%20the%26nbsp%3B%20state%20of%20each%20scheduler%20and%20reports%20any%20%22irregularities%22.%20Examples%20of%20irregularities%20include%20a%20thread%20not%20yielding%20voluntarily%20(a%20non-yielding%20scheduler)%20or%20all%20schedulers%20are%20%22stuck%22%20not%20processing%20any%20requests%20(deadlocked%20schedulers).%20Typically%20this%26nbsp%3B%20Scheduler%20Monitor%20thread%20will%20report%20problems%20every%2060%20seconds%2C%20though%20it%20monitors%20the%20%3CA%20title%3D%22IOCP%20thread%20that%20accepts%20connections%20every%2015%20seconds%22%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fb%2Fsqlmeditation%2Farchive%2F2012%2F12%2F12%2Fmeditation-is-iocp-listener-actually-listening-or-taking-a-break.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20IOCP%20thread%20that%20accepts%20connections%20every%2015%20seconds%20%3C%2FA%3E%20.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAn%20entire%20white%20paper%20could%20be%20written%20about%20how%20SOS%20scheduler%20works%20but%20for%20this%20discussion%20I%20will%20limit%20the%20information%26nbsp%3Bto%20some%20summary%20points.%20Actually%2C%20a%20white%20paper%20has%20been%26nbsp%3B%20written%20already%20-%20%3CA%20href%3D%22http%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fcc917684.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20SOS%20Scheduler%26nbsp%3B%20white%20paper%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3E%3CSTRONG%3EWhat%20is%20a%20Deadlocked%26nbsp%3B%20Scheduler%3F%3C%2FSTRONG%3E%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20deadlocked%26nbsp%3B%20scheduler%20scenario%20is%20reported%20when%20ALL%20SOS%20Schedulers%20are%20reported%20to%20be%26nbsp%3B%20%22stuck%22.%20Technically%2C%20this%20means%20that%20since%20the%20last%20Scheduler%20Monitor%20check%20-%26nbsp%3B%20say%20about%2060%20seconds%20earlier%20-%20nothing%20has%20changed%20and%20no%20work%20is%20being%20processed.%20Here%20are%20some%20of%20things%20checked%3A%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CDIV%3EAre%20there%20any%20tasks%20waiting%20to%20be%20processed%3F%26nbsp%3B%20(check%20if%20sys.dm_os_schedulers.work_queue_count%20%26gt%3B%200)%3C%2FDIV%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CDIV%3EHave%20any%20new%20worker%20threads%20been%20created%20since%20last%20check%3F%3C%2FDIV%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CDIV%3EHas%20any%20work%20been%20processed%20since%20last%20check%20(i.e.%20have%20any%20new%20tasks%20been%20assigned%20to%20workers)%3F%3C%2FDIV%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3EIf%20any%20of%20these%20conditions%20is%20met%20(not%20all)%2C%20the%20Scheduler%20Monitor%20declares%26nbsp%3B%20that%20schedulers%20are%20stuck%20-%20deadlocked.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20note%20on%20NUMA%3A%20SQL%26nbsp%3B%20Server%20can%20report%20Deadlocked%20Schedulers%20if%20all%20the%20SOS%20schedulers%20on%20a%20single%20NUMA%20node%26nbsp%3B%20are%20stuck%2C%20even%20if%20other%20NUMA%20nodes%20are%20processing%20tasks%20just%20fine.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20the%20Scheduler%26nbsp%3B%20monitor%20detectes%20a%20%22deadlock%20schedulers%22%20condition%2C%20it%20reports%20an%20error%20in%20the%26nbsp%3B%20Errorlog%20and%20triggers%20a%20memory%20dump%20to%20be%20generated%20by%20the%20SQLDumper.exe%20against%26nbsp%3B%20SQL%20Server%20process.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EWhat%20%22Deadlocked%26nbsp%3BSchedulers%22%20is%20not%3F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20phraase%26nbsp%3B%20%22deadlocked%20schedulers%22%20has%20confused%20many%20and%20rightly%20so.%20The%20term%20does%26nbsp%3BNOT%20imply%20a%20classic%20Lock-Manager%20deadlock%20where%20multiple%20sessions%20are%20trying%20to%20access%20locks%26nbsp%3Bin%20the%20opposite%20order%20and%20permanently%20block%20each%20other.%20The%20term%20applies%20to%20SOS%20Schedulers%20and%20the%20fact%20that%20none%20of%26nbsp%3Bthem%20are%20processing%20queries%2C%20logins%2C%20etc.%20So%20if%20you%20are%20thinking%20of%26nbsp%3B%20%22traditional%22%20lock%20deadlocks%2C%20you%20may%20steer%20away%20from%20such%20thoughts.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EMost%20Common%20Causes%20of%26nbsp%3B%20Deadlocked%20Schedulers%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEven%20though%20many%26nbsp%3B%20conditions%20can%20cause%20all%20schedulers%20to%20be%20stuck%20at%20the%20same%20time%2C%20in%2095%25%20of%20the%26nbsp%3Btime%20that%20I%20have%20looked%20at%20memory%20dumps%2C%20the%20reason%20has%20been%20that%20the%20majority%20of%26nbsp%3B%20worker%20threads%20were%20tied%20up%20waiting%20for%20a%20lock%20resource.%20Yes%2C%20the%20good%20ol'%20blocking%26nbsp%3B%20chains%20with%20a%20head%20blocker%20that%20you%20are%20so%20familiar%20with%2C%20is%20the%20most%20common%26nbsp%3B%20example.%20This%20causes%20the%20number%20of%20available%20SQL%20worker%20threads%20to%20be%20exhausted.%26nbsp%3B%20The%20worker%20threads%20themselves%20are%20tied%20up%20because%20they%20are%20waiting%20for%20a%20lock%20and%20when%20new%20tasks%26nbsp%3B(work)%20is%20submitted%20to%20the%20SQL%20Server%2C%20there%20are%20no%20worker%20threads%20available%20to%26nbsp%3Bpick%20the%20tasks%20up%20and%20execute%20them.%20Of%20courses%2C%20Locks%20are%20not%20the%20only%20resource%20you%20see%26nbsp%3Bcontention%20on.%20Here%20is%20the%20list%20of%20other%20types%20of%20resources%20that%20have%26nbsp%3B%20caused%20long%20%22blocking%22%20(I%20use%20the%20term%20loosely%20here)%20chains.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3ELock(s)%20%3C%2FSTRONG%3E%20-%20a%20very%20long%20blocking%20chain%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%3CBR%20%2F%3E%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%20Latch(es)%20%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%3CBR%20%2F%3E%3CUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EI%2FO%20latches%20-%20which%20means%20stuck%20I%2FO%3C%2FLI%3E%0A%3CLI%3EHeavy%20Latch%20chain%3C%2FLI%3E%0A%3CLI%3EOrphaned%2Funreleased%20page%20or%20non-page%20latches%20(commonly%20due%20to%20a%20previous%20AV%20exception%20or%20assert)%20-%20not%20common%26nbsp%3B%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%3CBR%20%2F%3E%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%20Spinlock(s)%20%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EOrphaned%2Funreleased%20spinlock%20(due%20to%20a%20previous%20AV%2C%20assert%20or%20other%26nbsp%3B%20exception)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%3CBR%20%2F%3E%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%20Parallel%20queries%20%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EHuge%20number%20of%20child%20threads%20spawned%20causing%20exhaustion%20of%20worker%20threads%20on%26nbsp%3B%20the%20system%20to%20service%20one%20or%20two%20queries%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EHow%20to%20Troubleshoot%20Deadlocked%20Schedulers%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESome%20deadlock%20scheduler%20scenarios%20will%20resolve%20by%20themselves%20-%20as%20in%20the%20case%20of%20parallel%20queries%2C%20long-held%20I%2FO%20latch%26nbsp%3Bor%2C%20rarely%2C%20blocking.%26nbsp%3B%20Orphaned%20structures%20like%20spinlocks%20or%20latches%20would%20require%20that%20you%20restart%20SQL%20Server.%20In%20most%20realistic%20cases%2C%20you%20will%20be%20aware%20of%20the%20issue%20only%20after%20it%20has%20been%20going%20on%20for%20awhile%20or%20after%20it%20has%20resolved%20itself.%20Therefore%2C%20in%20those%20cases%2C%20you%20will%20be%20focusing%20on%20post-mortem%20analysis%20of%20the%20problem.%20However%2C%20in%20rare%20cases%2C%20you%20may%20be%20able%20to%20take%20action%20while%20the%20problem%20is%20happening%20and%20resolve%20it%20(see%20using%20DAC%20connection%20below).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20two%20ways%20to%20find%20the%20root%20cause%20of%20deadlocked%20schedulers%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.Using%20DAC%20connection%20and%20examining%20some%20DMVs%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.Examining%20a%20memory%20dump%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%201.%20Troubleshooting%20Deadlocked%20Schedulers%20using%20the%20DAC%20connection%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20essence%2C%20the%20sole%20purpose%20of%20the%20Dedicated%20Admin%20Connection%20(DAC)%20is%20to%20troubleshoot%20server%20problems%20like%20deadlocked%20schedulers.%20That%20is%2C%20if%20you%20catch%20it%20%22live%22%2C%20while%20it%20is%20happening.%20You%20can%20find%20details%20on%20how%20to%20connect%20to%20SQL%20Server%20using%20DAC%20%3CA%20title%3D%22here%22%20href%3D%22http%3A%2F%2Ftechnet.microsoft.com%2Fen-US%2Flibrary%2Fms189595(v%3Dsql.105).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20here%20%3C%2FA%3E%20.%26nbsp%3BThe%20most%20effective%20use%20of%20DAC%20to%26nbsp%3Binvestigate%20and%20resolve%20deadlock%20scheduler%20problems%20is%20if%20the%20issue%20is%20caused%20by%20blocking.%20Luckily%2C%20this%20is%20the%20most%20common%20reason%20for%26nbsp%3Bdeadlocked%20schedulers%20so%26nbsp%3BDAC%20can%20be%20an%20effective%20tool.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20once%20you%20connect%20with%20DAC%20(I%20would%20suggest%20using%20%3CSTRONG%3E%20sqlcmd%20-A%20%3C%2FSTRONG%3E%20instead%20of%26nbsp%3BSSMS%2C%20since%20the%20latter%26nbsp%3Bmay%20attempt%20multiple%20connections%20to%26nbsp%3BSQL%20Server)%26nbsp%3B%2C%20you%20can%20investigate%20a%20couple%20of%20things%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20The%20state%20of%20all%20schedulers%20-%20sys.dm_os_schedulers%20and%20specifically%20if%20there%20is%20any%20queued%20work%20that%20is%20waiting.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.%20If%20there%20are%20hundreds%20of%20blocked%20threads%20-%20sys.dm_exec_requests%20-%20Wait_type%20%3D%20LCK_*%26nbsp%3B%26nbsp%3B%20(any%20type%20of%20lock%20wait)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3.%20Identify%20the%20head%20blocker%20from%20sys.dm_exec_requests%20by%20manually%20tracing%20which%20session%20is%20blocking%20all%20others%2C%20and%20terminate%20it%20by%20using%20the%20KILL%20command.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%20%3C%2FSTRONG%3E%20%3A%20If%20the%20issue%20is%20caused%20by%20an%20orphaned%20latch%20or%20orphaned%20spinlock%2C%20then%20the%20only%20way%20to%20get%20out%20of%20this%20situation%20is%20to%20restart%20SQL%20Server.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%202.%20Troubleshooting%20Deadlocked%20Schedulers%20by%20Examining%20a%20Memory%20Dump%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMost%20commonly%20the%20best%20way%20to%20find%20the%20root%20cause%20of%20deadlocked%20schedulers%20is%20to%20figure%20out%20what%20the%20majority%20of%20worker%20threads%20are%20stuck%20behind.%20And%20the%20way%20to%20do%20this%20by%20examining%20the%20memory%20dumps%20that%20SQL%20Server%20automatically%20generates%20for%20this%20purpose.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20are%20some%20examples%20of%20stacks%20that%20you%20will%20observe%20if%20you%20were%20to%20examine%20a%20memory%20dump%20(details%20on%20how%20to%20do%20so%20using%20public%20symbols%20can%20be%20found%20%3CA%20title%3D%22here%22%20href%3D%22http%3A%2F%2Fmssqlwiki.com%2F2010%2F06%2F15%2Fhow-to-analyze-deadlocked-schedulers-dumps%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20here%20%3C%2FA%3E%20)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%20Blocking%3A%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20typical%20call%20stack%20of%20all%20the%20threads%20that%20are%20stuck%20on%20Lock%20waits%20will%20include%20the%20%3CSTRONG%3E%20LockOwner%3A%3ASleep()%20%3C%2FSTRONG%3E%20function.%20Here%20is%20a%20example%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Entdll!KiFastSystemCallRet%20%3CBR%20%2F%3Entdll!ZwSignalAndWaitForSingleObject%2B0xc%20%3CBR%20%2F%3Ekernel32!SignalObjectAndWait%2B0xaf%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ASwitch%2B0x81%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ASwitchContext%2B0x2fd%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ASuspendNonPreemptive%2B0xb9%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ASuspend%2B0x2e%20%3CBR%20%2F%3Esqlservr!SOS_Event%3A%3AWait%2B0x12a%20%3CBR%20%2F%3Esqlservr!%20%3CSTRONG%3E%20LockOwner%3A%3ASleep%20%3C%2FSTRONG%3E%20%2B0x13e%20%3CBR%20%2F%3Esqlservr!lck_lockInternal%2B0x990%20%3CBR%20%2F%3Esqlservr!GetLock%2B0x178%20%3CBR%20%2F%3Esqlservr!BTreeRow%3A%3AAcquireLock%2B0x14c%20%3CBR%20%2F%3Esqlservr!IndexRowScanner%3A%3AAcquireNextRowLock%2B0x1da%20%3CBR%20%2F%3Esqlservr!IndexDataSetSession%3A%3AGetNextRowValuesInternal%2B0x53a%20%3CBR%20%2F%3Esqlservr!IndexDataSetSession%3A%3AGetNextRowValues%2B0x2d%20%3CBR%20%2F%3Esqlservr!RowsetNewSS%3A%3AFetchNextRow%2B0x3e%20%3CBR%20%2F%3Esqlservr!CQScanRowsetNew%3A%3AGetRowWithPrefetch%2B0x2b%20%3CBR%20%2F%3Esqlservr!CQScanRangeNew%3A%3AGetRow%2B0x141%20%3CBR%20%2F%3Esqlservr!CQScanTopNew%3A%3AGetRow%2B0x108%20%3CBR%20%2F%3Esqlservr!CQScanUpdateNew%3A%3AGetRow%2B0x76%20%3CBR%20%2F%3Esqlservr!CQueryScan%3A%3AGetRow%2B0x5a%20%3CBR%20%2F%3Esqlservr!CXStmtQuery%3A%3AInitForExecute%2B0x51%20%3CBR%20%2F%3Esqlservr!CXStmtQuery%3A%3AErsqExecuteQuery%2B0x291%20%3CBR%20%2F%3Esqlservr!CXStmtDML%3A%3AXretDMLExecute%2B0x284%20%3CBR%20%2F%3Esqlservr!CXStmtDML%3A%3AXretExecute%2B0x8b%20%3CBR%20%2F%3Esqlservr!CMsqlExecContext%3A%3AExecuteStmts%26lt%3B0%2C1%26gt%3B%2B0x7cf%20%3CBR%20%2F%3Esqlservr!CMsqlExecContext%3A%3AFExecute%2B0x550%20%3CBR%20%2F%3Esqlservr!CSQLSource%3A%3AExecute%2B0x73b%20%3CBR%20%2F%3Esqlservr!CStmtPrepQuery%3A%3AXretExecute%2B0x45b%20%3CBR%20%2F%3Esqlservr!CExecuteStatement%3A%3AXretExecute%2B0x1b%20%3CBR%20%2F%3Esqlservr!CMsqlExecContext%3A%3AExecuteStmts%26lt%3B1%2C1%26gt%3B%2B0x360%20%3CBR%20%2F%3Esqlservr!CMsqlExecContext%3A%3AFExecute%2B0x55b%20%3CBR%20%2F%3Esqlservr!CSQLSource%3A%3AExecute%2B0x73b%20%3CBR%20%2F%3Esqlservr!process_request%2B0x2e3%20%3CBR%20%2F%3Esqlservr!process_commands%2B0x2e0%20%3CBR%20%2F%3Esqlservr!SOS_Task%3A%3AParam%3A%3AExecute%2B0xe2%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ARunTask%2B0xb9%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3AProcessTasks%2B0x141%20%3CBR%20%2F%3Esqlservr!SchedulerManager%3A%3AWorkerEntryPoint%2B0x1a8%20%3CBR%20%2F%3Esqlservr!SystemThread%3A%3ARunWorker%2B0x7f%20%3CBR%20%2F%3Esqlservr!SystemThreadDispatcher%3A%3AProcessWorker%2B0x225%20%3CBR%20%2F%3Esqlservr!SchedulerManager%3A%3AThreadEntryPoint%2B0x143%20%3CBR%20%2F%3Emsvcr80!_callthreadstartex%2B0x1b%20%3CBR%20%2F%3Emsvcr80!_threadstartex%2B0x66%20%3CBR%20%2F%3Ekernel32!BaseThreadStart%2B0x34%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%20Orphaned%2Funreleased%20Latch%3A%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20will%20observe%20that%20most%20thread%20that%20are%20stuck%20behind%20a%20latch%20will%20contain%20the%20%3CSTRONG%3E%20LatchBase%3A%3ASuspend()%20%3C%2FSTRONG%3E%20call.%20Here%20is%20an%20example%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Entdll!ZwWaitForSingleObject%2B0xa%20%3CBR%20%2F%3Ekernel32!WaitForSingleObjectEx%2B0x130%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ASwitchContext%2B0x623%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ASuspendNonPreemptive%2B0xc5%20%3CBR%20%2F%3Esqlservr!EventInternal%3CSPINLOCK%3E%26lt%3B149%2C1%2C0%26gt%3B%20%26gt%3B%3A%3AWait%2B0x428%20%3CBR%20%2F%3Esqlservr!%20%3CSTRONG%3E%20LatchBase%3A%3ASuspend%20%3C%2FSTRONG%3E%20%2B0x42c%20%3CBR%20%2F%3Esqlservr!LatchBase%3A%3AAcquireInternal%2B0xfa%20%3CBR%20%2F%3Esqlservr!CTraceController%3A%3AFAcquireLock%2B0x53%20%3CBR%20%2F%3Esqlservr!CTraceController%3A%3ACAutoLock%3A%3AFAcquire%2B0x18%20%3CBR%20%2F%3Esqlservr!CTraceController%3A%3AProduceRecord%2B0xb58456%20%3CBR%20%2F%3Esqlservr!CRpcTraceHelper%3A%3ATracePostRPC%2B0x347%20%3CBR%20%2F%3Esqlservr!CRpcTraceHelper%3A%3ATracePostExec%2B0xfc8b44%20%3CBR%20%2F%3Esqlservr!CRPCExecEnv%3A%3AOnExecFinish%2B0xaf%20%3CBR%20%2F%3Esqlservr!process_request%2B0x399%20%3CBR%20%2F%3Esqlservr!process_commands%2B0x1ba%20%3CBR%20%2F%3Esqlservr!SOS_Task%3A%3AParam%3A%3AExecute%2B0x11b%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ARunTask%2B0xca%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3AProcessTasks%2B0x95%20%3CBR%20%2F%3Esqlservr!SchedulerManager%3A%3AWorkerEntryPoint%2B0x110%20%3CBR%20%2F%3Esqlservr!SystemThread%3A%3ARunWorker%2B0x60%20%3CBR%20%2F%3Esqlservr!SystemThreadDispatcher%3A%3AProcessWorker%2B0x12c%20%3CBR%20%2F%3Esqlservr!SchedulerManager%3A%3AThreadEntryPoint%2B0x12f%20%3CBR%20%2F%3Emsvcr80!_callthreadstartex%2B0x17%20%3CBR%20%2F%3Emsvcr80!_threadstartex%2B0x84%20%3CBR%20%2F%3Ekernel32!BaseThreadStart%2B0x3a%3C%2FSPINLOCK%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%20Orphaned%2Funreleased%20Spinlock%3A%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20what%20a%20stack%20might%20look%20like%20from%20a%20thread%20stuck%20behind%20a%20spinlock%20-%20note%20the%20%3CSTRONG%3E%20SpinlockBase%3A%3ASleep()%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Entdll!ZwDelayExecution%2B0xa%20%3CBR%20%2F%3Ekernel32!SleepEx%2B0xaf%20%3CBR%20%2F%3Esqlservr!%20%3CSTRONG%3E%20SpinlockBase%3A%3ASleep%20%3C%2FSTRONG%3E%20%2B0x15d5a1%20%3CBR%20%2F%3Esqlservr!SpinlockBase%3A%3ASpinToAcquire%2B0x11b%20%3CBR%20%2F%3Esqlservr!TSyncHashTable_EntryAccessor%26lt%3B...%26gt%3B%3A%3ATSyncHashTable_EntryAccessor%26lt%3B...%26gt%3B%2B0x76%20%3CBR%20%2F%3Esqlservr!CQSIndexStatsMgr%3A%3AUsedFor%2B0x68%20%3CBR%20%2F%3Esqlservr!CQueryScan%3A%3AUncache%2B0x4788a6%20%3CBR%20%2F%3Esqlservr!CXStmtQuery%3A%3ASetupQueryScanAndExpression%2B0x252%20%3CBR%20%2F%3Esqlservr!CXStmtQuery%3A%3AErsqExecuteQuery%2B0x232%20%3CBR%20%2F%3Esqlservr!CXStmtSelect%3A%3AXretExecute%2B0x110%20%3CBR%20%2F%3Esqlservr!CExecStmtLoopVars%3A%3AExecuteXStmtAndSetXretReturn%2B0x13%20%3CBR%20%2F%3Esqlservr!CMsqlExecContext%3A%3AExecuteStmts%26lt%3B1%2C0%26gt%3B%2B0x9e5%20%3CBR%20%2F%3Esqlservr!CMsqlExecContext%3A%3AFExecute%2B0x4c5270%20%3CBR%20%2F%3Esqlservr!CSQLSource%3A%3AExecute%2B0x36d%20%3CBR%20%2F%3Esqlservr!ExecuteSql%2B0x700%20%3CBR%20%2F%3Esqlservr!CSpecProc%3A%3AExecuteSpecial%2B0x4c7%20%3CBR%20%2F%3Esqlservr!CSpecProc%3A%3AExecute%2B0x1d5%20%3CBR%20%2F%3Esqlservr!process_request%2B0x312%20%3CBR%20%2F%3Esqlservr!process_commands%2B0x1c4%20%3CBR%20%2F%3Esqlservr!SOS_Task%3A%3AParam%3A%3AExecute%2B0xee%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3ARunTask%2B0xc9%20%3CBR%20%2F%3Esqlservr!SOS_Scheduler%3A%3AProcessTasks%2B0xb4%20%3CBR%20%2F%3Esqlservr!SchedulerManager%3A%3AWorkerEntryPoint%2B0xe7%20%3CBR%20%2F%3Esqlservr!SystemThread%3A%3ARunWorker%2B0x59%20%3CBR%20%2F%3Esqlservr!SystemThreadDispatcher%3A%3AProcessWorker%2B0x130%20%3CBR%20%2F%3Esqlservr!SchedulerManager%3A%3AThreadEntryPoint%2B0x128%20%3CBR%20%2F%3Emsvcr80!_callthreadstartex%2B0x17%20%3CBR%20%2F%3Emsvcr80!_threadstartex%2B0x84%20%3CBR%20%2F%3Ekernel32!BaseThreadStart%2B0x3a%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENamaste!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EJoseph%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-333991%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20MSDN%20on%20Dec%2014%2C%202012%20Just%20thought%20I%20would%20summarize%20the%20concept%20of%20a%20SOS%20Scheduler%20and%20a%20Deadlocked%20Scheduler%26nbsp%3Bsince%20many%20have%20inquired%20over%20the%20years%20for%20a%20brief%20summary%20of%20these%20concepts%26nbsp%3BUMS%2FSOS%20Scheduler%20in%20SQL%26nbsp%3B%20ServerSince%20SQL%20Server%207.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-333991%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Econnectivity%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPerformance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%20OS%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETroubleshooting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on MSDN on Dec 14, 2012

Just thought I would summarize the concept of a SOS Scheduler and a Deadlocked Scheduler since many have inquired over the years for a brief summary of these concepts

 

 

 

UMS/SOS Scheduler in SQL  Server

 

Since SQL Server 7.0, SQL  Server has used its own scheduling mechanism, called UMS (User-mode scheduler)  in 7.0 and 2000 and later renamed to SOS (SQL on OS scheduler). UMS/SOS is a  cooperative (non-preemptive) scheduler which means that it relies on threads to voluntarily give up CPU usage - yield - to the next thread waiting in line. That means that there are locations in the SQL Server code where the Microsoft developer built in yield points, causing execution to “pause” and gracefully let another citizen in the SQL kingdom to exercise its right to execute. Of  course, once a thread "leaves" SQL Server SOS kingdom, that thread is still handed off to the Windows preemptive scheduler (ruled by another Master so to speak). The goal of SOS is for SQL Server to expose only one  thread at a time per CPU and thus minimize competition among SQL threads exposed to the OS. The ultimate goal is to reduce the very expensive kernel-mode context switching from one thread to another.

 

Since SQL Server uses a cooperative scheduler, it relies on the good heart of each developer who  writes code in SQL Server to call a Yield() function of some kind that prevents the thread from monopolizing the CPU. But even the best-intentioned developer could make mistakes (and introduce a  bug in his code), or a SQL thread could be at the mercy of some external component – like calling into code outside of SQL Server. Because of that, the SOS scheduler has a dedicated thread -Scheduler Monitor - that periodically checks the  state of each scheduler and reports any "irregularities". Examples of irregularities include a thread not yielding voluntarily (a non-yielding scheduler) or all schedulers are "stuck" not processing any requests (deadlocked schedulers). Typically this  Scheduler Monitor thread will report problems every 60 seconds, though it monitors the IOCP thread that accepts connections every 15 seconds .

 

An entire white paper could be written about how SOS scheduler works but for this discussion I will limit the information to some summary points. Actually, a white paper has been  written already - SOS Scheduler  white paper

 

What is a Deadlocked  Scheduler?

 

A deadlocked  scheduler scenario is reported when ALL SOS Schedulers are reported to be  "stuck". Technically, this means that since the last Scheduler Monitor check -  say about 60 seconds earlier - nothing has changed and no work is being processed. Here are some of things checked:



    • Are there any tasks waiting to be processed?  (check if sys.dm_os_schedulers.work_queue_count > 0)

 

    • Have any new worker threads been created since last check?

 

    • Has any work been processed since last check (i.e. have any new tasks been assigned to workers)?



If any of these conditions is met (not all), the Scheduler Monitor declares  that schedulers are stuck - deadlocked.

 

A note on NUMA: SQL  Server can report Deadlocked Schedulers if all the SOS schedulers on a single NUMA node  are stuck, even if other NUMA nodes are processing tasks just fine.

 

When the Scheduler  monitor detectes a "deadlock schedulers" condition, it reports an error in the  Errorlog and triggers a memory dump to be generated by the SQLDumper.exe against  SQL Server process.

 

 

 

What "Deadlocked Schedulers" is not?

 

The phraase  "deadlocked schedulers" has confused many and rightly so. The term does NOT imply a classic Lock-Manager deadlock where multiple sessions are trying to access locks in the opposite order and permanently block each other. The term applies to SOS Schedulers and the fact that none of them are processing queries, logins, etc. So if you are thinking of  "traditional" lock deadlocks, you may steer away from such thoughts.

 

 

 

Most Common Causes of  Deadlocked Schedulers:

 

Even though many  conditions can cause all schedulers to be stuck at the same time, in 95% of the time that I have looked at memory dumps, the reason has been that the majority of  worker threads were tied up waiting for a lock resource. Yes, the good ol' blocking  chains with a head blocker that you are so familiar with, is the most common  example. This causes the number of available SQL worker threads to be exhausted.  The worker threads themselves are tied up because they are waiting for a lock and when new tasks (work) is submitted to the SQL Server, there are no worker threads available to pick the tasks up and execute them. Of courses, Locks are not the only resource you see contention on. Here is the list of other types of resources that have  caused long "blocking" (I use the term loosely here) chains.

 

 

 



    • Lock(s) - a very long blocking chain

    • Latch(es)

      • I/O latches - which means stuck I/O
      • Heavy Latch chain
      • Orphaned/unreleased page or non-page latches (commonly due to a previous AV exception or assert) - not common 

    • Spinlock(s)
      • Orphaned/unreleased spinlock (due to a previous AV, assert or other  exception)

    • Parallel queries
      • Huge number of child threads spawned causing exhaustion of worker threads on  the system to service one or two queries



 

How to Troubleshoot Deadlocked Schedulers

 

Some deadlock scheduler scenarios will resolve by themselves - as in the case of parallel queries, long-held I/O latch or, rarely, blocking.  Orphaned structures like spinlocks or latches would require that you restart SQL Server. In most realistic cases, you will be aware of the issue only after it has been going on for awhile or after it has resolved itself. Therefore, in those cases, you will be focusing on post-mortem analysis of the problem. However, in rare cases, you may be able to take action while the problem is happening and resolve it (see using DAC connection below).

 

 

 

There are two ways to find the root cause of deadlocked schedulers:

 

1.Using DAC connection and examining some DMVs

 

2.Examining a memory dump

 

 

 

1. Troubleshooting Deadlocked Schedulers using the DAC connection

 

In essence, the sole purpose of the Dedicated Admin Connection (DAC) is to troubleshoot server problems like deadlocked schedulers. That is, if you catch it "live", while it is happening. You can find details on how to connect to SQL Server using DAC here . The most effective use of DAC to investigate and resolve deadlock scheduler problems is if the issue is caused by blocking. Luckily, this is the most common reason for deadlocked schedulers so DAC can be an effective tool.

 

So, once you connect with DAC (I would suggest using sqlcmd -A instead of SSMS, since the latter may attempt multiple connections to SQL Server) , you can investigate a couple of things:

 

1. The state of all schedulers - sys.dm_os_schedulers and specifically if there is any queued work that is waiting.

 

2. If there are hundreds of blocked threads - sys.dm_exec_requests - Wait_type = LCK_*   (any type of lock wait)

 

3. Identify the head blocker from sys.dm_exec_requests by manually tracing which session is blocking all others, and terminate it by using the KILL command.

 

 

 

Note : If the issue is caused by an orphaned latch or orphaned spinlock, then the only way to get out of this situation is to restart SQL Server.

 

 

 

2. Troubleshooting Deadlocked Schedulers by Examining a Memory Dump

 

 

 

Most commonly the best way to find the root cause of deadlocked schedulers is to figure out what the majority of worker threads are stuck behind. And the way to do this by examining the memory dumps that SQL Server automatically generates for this purpose.

 

Here are some examples of stacks that you will observe if you were to examine a memory dump (details on how to do so using public symbols can be found here )

 

Blocking:

 

A typical call stack of all the threads that are stuck on Lock waits will include the LockOwner::Sleep() function. Here is a example

 

ntdll!KiFastSystemCallRet
ntdll!ZwSignalAndWaitForSingleObject+0xc
kernel32!SignalObjectAndWait+0xaf
sqlservr!SOS_Scheduler::Switch+0x81
sqlservr!SOS_Scheduler::SwitchContext+0x2fd
sqlservr!SOS_Scheduler::SuspendNonPreemptive+0xb9
sqlservr!SOS_Scheduler::Suspend+0x2e
sqlservr!SOS_Event::Wait+0x12a
sqlservr! LockOwner::Sleep +0x13e
sqlservr!lck_lockInternal+0x990
sqlservr!GetLock+0x178
sqlservr!BTreeRow::AcquireLock+0x14c
sqlservr!IndexRowScanner::AcquireNextRowLock+0x1da
sqlservr!IndexDataSetSession::GetNextRowValuesInternal+0x53a
sqlservr!IndexDataSetSession::GetNextRowValues+0x2d
sqlservr!RowsetNewSS::FetchNextRow+0x3e
sqlservr!CQScanRowsetNew::GetRowWithPrefetch+0x2b
sqlservr!CQScanRangeNew::GetRow+0x141
sqlservr!CQScanTopNew::GetRow+0x108
sqlservr!CQScanUpdateNew::GetRow+0x76
sqlservr!CQueryScan::GetRow+0x5a
sqlservr!CXStmtQuery::InitForExecute+0x51
sqlservr!CXStmtQuery::ErsqExecuteQuery+0x291
sqlservr!CXStmtDML::XretDMLExecute+0x284
sqlservr!CXStmtDML::XretExecute+0x8b
sqlservr!CMsqlExecContext::ExecuteStmts<0,1>+0x7cf
sqlservr!CMsqlExecContext::FExecute+0x550
sqlservr!CSQLSource::Execute+0x73b
sqlservr!CStmtPrepQuery::XretExecute+0x45b
sqlservr!CExecuteStatement::XretExecute+0x1b
sqlservr!CMsqlExecContext::ExecuteStmts<1,1>+0x360
sqlservr!CMsqlExecContext::FExecute+0x55b
sqlservr!CSQLSource::Execute+0x73b
sqlservr!process_request+0x2e3
sqlservr!process_commands+0x2e0
sqlservr!SOS_Task::Param::Execute+0xe2
sqlservr!SOS_Scheduler::RunTask+0xb9
sqlservr!SOS_Scheduler::ProcessTasks+0x141
sqlservr!SchedulerManager::WorkerEntryPoint+0x1a8
sqlservr!SystemThread::RunWorker+0x7f
sqlservr!SystemThreadDispatcher::ProcessWorker+0x225
sqlservr!SchedulerManager::ThreadEntryPoint+0x143
msvcr80!_callthreadstartex+0x1b
msvcr80!_threadstartex+0x66
kernel32!BaseThreadStart+0x34

 

 

 

Orphaned/unreleased Latch:

 

You will observe that most thread that are stuck behind a latch will contain the LatchBase::Suspend() call. Here is an example

 

 

 

ntdll!ZwWaitForSingleObject+0xa
kernel32!WaitForSingleObjectEx+0x130
sqlservr!SOS_Scheduler::SwitchContext+0x623
sqlservr!SOS_Scheduler::SuspendNonPreemptive+0xc5
sqlservr!EventInternal<Spinlock<149,1,0> >::Wait+0x428
sqlservr! LatchBase::Suspend +0x42c
sqlservr!LatchBase::AcquireInternal+0xfa
sqlservr!CTraceController::FAcquireLock+0x53
sqlservr!CTraceController::CAutoLock::FAcquire+0x18
sqlservr!CTraceController::ProduceRecord+0xb58456
sqlservr!CRpcTraceHelper::TracePostRPC+0x347
sqlservr!CRpcTraceHelper::TracePostExec+0xfc8b44
sqlservr!CRPCExecEnv::OnExecFinish+0xaf
sqlservr!process_request+0x399
sqlservr!process_commands+0x1ba
sqlservr!SOS_Task::Param::Execute+0x11b
sqlservr!SOS_Scheduler::RunTask+0xca
sqlservr!SOS_Scheduler::ProcessTasks+0x95
sqlservr!SchedulerManager::WorkerEntryPoint+0x110
sqlservr!SystemThread::RunWorker+0x60
sqlservr!SystemThreadDispatcher::ProcessWorker+0x12c
sqlservr!SchedulerManager::ThreadEntryPoint+0x12f
msvcr80!_callthreadstartex+0x17
msvcr80!_threadstartex+0x84
kernel32!BaseThreadStart+0x3a

 

 

 

Orphaned/unreleased Spinlock:

 

Here is what a stack might look like from a thread stuck behind a spinlock - note the SpinlockBase::Sleep()

 

 

 

ntdll!ZwDelayExecution+0xa
kernel32!SleepEx+0xaf
sqlservr! SpinlockBase::Sleep +0x15d5a1
sqlservr!SpinlockBase::SpinToAcquire+0x11b
sqlservr!TSyncHashTable_EntryAccessor<...>::TSyncHashTable_EntryAccessor<...>+0x76
sqlservr!CQSIndexStatsMgr::UsedFor+0x68
sqlservr!CQueryScan::Uncache+0x4788a6
sqlservr!CXStmtQuery::SetupQueryScanAndExpression+0x252
sqlservr!CXStmtQuery::ErsqExecuteQuery+0x232
sqlservr!CXStmtSelect::XretExecute+0x110
sqlservr!CExecStmtLoopVars::ExecuteXStmtAndSetXretReturn+0x13
sqlservr!CMsqlExecContext::ExecuteStmts<1,0>+0x9e5
sqlservr!CMsqlExecContext::FExecute+0x4c5270
sqlservr!CSQLSource::Execute+0x36d
sqlservr!ExecuteSql+0x700
sqlservr!CSpecProc::ExecuteSpecial+0x4c7
sqlservr!CSpecProc::Execute+0x1d5
sqlservr!process_request+0x312
sqlservr!process_commands+0x1c4
sqlservr!SOS_Task::Param::Execute+0xee
sqlservr!SOS_Scheduler::RunTask+0xc9
sqlservr!SOS_Scheduler::ProcessTasks+0xb4
sqlservr!SchedulerManager::WorkerEntryPoint+0xe7
sqlservr!SystemThread::RunWorker+0x59
sqlservr!SystemThreadDispatcher::ProcessWorker+0x130
sqlservr!SchedulerManager::ThreadEntryPoint+0x128
msvcr80!_callthreadstartex+0x17
msvcr80!_threadstartex+0x84
kernel32!BaseThreadStart+0x3a

 

 

 

 

 

Namaste!

 

 

 

Joseph