SlideShare a Scribd company logo
1 of 30
Download to read offline
Premium community conference on Microsoft technologies itcampro@ itcamp14#
.NET Memory Primer
Martin Kulov
martin@kulov.net
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Huge thanks to our sponsors & partners!
Premium community conference on Microsoft technologies itcampro@ itcamp14#
"Out of CPU, memory and disk, memory is typically
the most important for overall system performance."
Mark Russinovich
“All you worry about in a .NET application is the
memory.”
John Robbins
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• x86
–2 ^ 32 bits = 4GB /0x FFFF FFFF/
• x64
–2 ^ 64 bits = 16 EB /0x FFFF FFFF' FFFF FFFF/
Virtual Memory Limits
Premium community conference on Microsoft technologies itcampro@ itcamp14#
x86 Memory Mapping
* PFN - Page Frame Number database
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Max 4GB
–Windows Client, Windows Srv 2008 Standard
• Max 128GB
–Windows Srv 2003 SP1 Datacenter (PAE)
x86 Physical Memory Limits
Premium community conference on Microsoft technologies itcampro@ itcamp14#
x64 Memory Mapping
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Max 4TB - Windows Srv 2012 Standard
• Limited per SKU
x64 Physical Memory Limits
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Canonical Form Addresses
48-bit implementation 56-bit implementation 64-bit implementation
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Virtual Address Space
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Code
• Data
• Stacks
• Heaps
User Mode Memory
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Created for Each Thread
• Default to 1MB
• Hold Method Data /stack frame/
–Parameters
–Local variables
–Return address
• First In, First Out
Stacks
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Stack Layout
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• ChildEBP RetAddr Caller,Callee
• 08e4e1a4 751b149d _WaitForSingleObjectEx@12+0x98, calling _ZwWaitForSingleObject@12
• 08e4e1e8 718b53c2 ?LeaveRuntimeNoThrow@Thread@@SGJI@Z+0xd7, calling __EH_epilog3
• 08e4e210 755b1194 _WaitForSingleObjectExImplementation@12+0x75, calling
_WaitForSingleObjectEx@12
• 08e4e228 718b54d7 ?LoadImage@PEImage@@SGPAV1@PAUHINSTANCE__@@@Z+0x1af
• ...
• 08e4f5f4 71a10647 ?intermediateThreadProc@Thread@@CGKPAX@Z+0x49
• 08e4f784 71a10635 ?intermediateThreadProc@Thread@@CGKPAX@Z+0x37, calling
__alloca_probe_16
• 08e4f798 755b336a @BaseThreadInitThunk@12+0xe
• 08e4f7a4 77639f72 ___RtlUserThreadStart@8+0x70
• 08e4f7e4 77639f45 __RtlUserThreadStart@8+0x1b, calling ___RtlUserThreadStart@8
Call Stack Example
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Hold Dynamically Allocated Data
• 1 Heap Per Logical Processor
• Heap Has Segments
–Process Heap
–Code Heap /JITed code/
–Small Object Heap /SOH/
–Large Object Heap /LOH/
Heaps
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Stack
–Value Types /Int32, Bool, Struct, etc…/
–Pointers to Reference Types
• Heap
–Reference Types /Object, String, Array, etc…/
–Free Areas
Allocating .NET Memory
Premium community conference on Microsoft technologies itcampro@ itcamp14#
DEMO: ALLOCATING MEMORY
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Stack References
• Static References /Fields, ThreadStatic/
• CPU Registers
• Interop References /COM, API calls/
• Finalization Queue References
Object Roots /GC Roots/
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• a.k.a. Generational Garbage Collector /GC/
• Three Generations /SOH/
–Gen0 – short lived
–Gen1 – medium lived
–Gen2 – long lived
Nondeterministic Finalization
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Before GC #1
Gen1 Gen0
Before GC #500
Gen2
Gen2
Gen2 Gen1 Gen0
Gen0
Before GC #0
Before GC #2
Gen2 Gen1 Gen0
Before GC #100
Gen2
Gen2 Gen1 Gen0
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Gen0 is Full
• Induced GC /System.GC.Collect()/
• System Pressure
Collection - When
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Rule of Thumb – Ratio 1:10:100
• .NET CLR Memory% time in GC
• .NET CLR Memory# Induced GC
• .NET CLR Memory# Gen X collections
Collection - Cost
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Size > 85KB
• Memory is marked as free during Gen2
• Avoid Temporary Large Objects
• Reuse Objects in LOH If Possible
• Many LOH Segments
• Fragmentation Problems
Large Object Heap
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Suspend Managed Threads
• Collect Garbage
• Resume Managed Threads
• Two Phases of GC
–Mark
–Compact
Collection - How
Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Workstation GC – Non Concurrent
• Server GC – Non Concurrent
• Workstation GC – Concurrent
–Background GC /New in .NET 4/
• Server GC – Background /New in .NET 4.5/
GC Types
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Workstation GC
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Server GC
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Concurrent GC – Before and After
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Testing Concurrent Server GC
Premium community conference on Microsoft technologies itcampro@ itcamp14#
Q & A

More Related Content

What's hot

What's hot (19)

Mongodb meetup
Mongodb meetupMongodb meetup
Mongodb meetup
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
 
Parallel computing with GPars
Parallel computing with GParsParallel computing with GPars
Parallel computing with GPars
 
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's index
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's indexFOSDEM 2020: Querying over millions and billions of metrics with M3DB's index
FOSDEM 2020: Querying over millions and billions of metrics with M3DB's index
 
FleetDB
FleetDBFleetDB
FleetDB
 
Ceph Month 2021: RADOS Update
Ceph Month 2021: RADOS UpdateCeph Month 2021: RADOS Update
Ceph Month 2021: RADOS Update
 
Ai meetup Neural machine translation updated
Ai meetup Neural machine translation updatedAi meetup Neural machine translation updated
Ai meetup Neural machine translation updated
 
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicumBsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 
Crimson: Ceph for the Age of NVMe and Persistent Memory
Crimson: Ceph for the Age of NVMe and Persistent MemoryCrimson: Ceph for the Age of NVMe and Persistent Memory
Crimson: Ceph for the Age of NVMe and Persistent Memory
 
Performance
PerformancePerformance
Performance
 
In a Nutshell: Rancher
In a Nutshell: RancherIn a Nutshell: Rancher
In a Nutshell: Rancher
 
OpenNebulaConf2018 - OpenNebula and LXD Containers - Rubén S. Montero - OpenN...
OpenNebulaConf2018 - OpenNebula and LXD Containers - Rubén S. Montero - OpenN...OpenNebulaConf2018 - OpenNebula and LXD Containers - Rubén S. Montero - OpenN...
OpenNebulaConf2018 - OpenNebula and LXD Containers - Rubén S. Montero - OpenN...
 
Seastore: Next Generation Backing Store for Ceph
Seastore: Next Generation Backing Store for CephSeastore: Next Generation Backing Store for Ceph
Seastore: Next Generation Backing Store for Ceph
 
Log Event Stream Processing In Flink Way
Log Event Stream Processing In Flink WayLog Event Stream Processing In Flink Way
Log Event Stream Processing In Flink Way
 
mypipe: Buffering and consuming MySQL changes via Kafka
mypipe: Buffering and consuming MySQL changes via Kafkamypipe: Buffering and consuming MySQL changes via Kafka
mypipe: Buffering and consuming MySQL changes via Kafka
 
Continuous Go Profiling & Observability
Continuous Go Profiling & ObservabilityContinuous Go Profiling & Observability
Continuous Go Profiling & Observability
 
Clique square storage
Clique square storageClique square storage
Clique square storage
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools
 

Similar to .NET Memory Primer (Martin Kulov)

ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game developmentITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp
 
ITCamp 2011 - Cristian Lefter - SQL Server code-name Denali
ITCamp 2011 - Cristian Lefter - SQL Server code-name DenaliITCamp 2011 - Cristian Lefter - SQL Server code-name Denali
ITCamp 2011 - Cristian Lefter - SQL Server code-name Denali
ITCamp
 
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
Chester Chen
 
ITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance Tools
ITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance ToolsITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance Tools
ITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance Tools
ITCamp
 
ITCamp 2013 - Alessandro Pilotti - Git crash course for Visual Studio devs
ITCamp 2013 - Alessandro Pilotti - Git crash course for Visual Studio devsITCamp 2013 - Alessandro Pilotti - Git crash course for Visual Studio devs
ITCamp 2013 - Alessandro Pilotti - Git crash course for Visual Studio devs
ITCamp
 
amrapali builders @@ hacking challenges.pdf
amrapali builders @@ hacking challenges.pdfamrapali builders @@ hacking challenges.pdf
amrapali builders @@ hacking challenges.pdf
amrapalibuildersreviews
 
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just BeganITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp
 
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp
 
causos da linha de frente - #rsonrails 2011
causos da linha de frente - #rsonrails 2011causos da linha de frente - #rsonrails 2011
causos da linha de frente - #rsonrails 2011
bzanchet
 

Similar to .NET Memory Primer (Martin Kulov) (20)

ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game developmentITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
 
14 scaleabilty wics
14 scaleabilty wics14 scaleabilty wics
14 scaleabilty wics
 
ITCamp 2011 - Cristian Lefter - SQL Server code-name Denali
ITCamp 2011 - Cristian Lefter - SQL Server code-name DenaliITCamp 2011 - Cristian Lefter - SQL Server code-name Denali
ITCamp 2011 - Cristian Lefter - SQL Server code-name Denali
 
Cryptography - You're doing it wrong! (Attila Balazs)
Cryptography - You're doing it wrong! (Attila Balazs)Cryptography - You're doing it wrong! (Attila Balazs)
Cryptography - You're doing it wrong! (Attila Balazs)
 
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
Patterns for Scalability in Windows Azure Applications (Alex Mang)
Patterns for Scalability in Windows Azure Applications (Alex Mang)Patterns for Scalability in Windows Azure Applications (Alex Mang)
Patterns for Scalability in Windows Azure Applications (Alex Mang)
 
Linux Perf Tools
Linux Perf ToolsLinux Perf Tools
Linux Perf Tools
 
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...
 
Migrating from eRoom to SharePoint, A Success Story (Valy Greavu)
Migrating from eRoom to SharePoint, A Success Story (Valy Greavu)Migrating from eRoom to SharePoint, A Success Story (Valy Greavu)
Migrating from eRoom to SharePoint, A Success Story (Valy Greavu)
 
ITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance Tools
ITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance ToolsITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance Tools
ITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance Tools
 
ITCamp 2013 - Alessandro Pilotti - Git crash course for Visual Studio devs
ITCamp 2013 - Alessandro Pilotti - Git crash course for Visual Studio devsITCamp 2013 - Alessandro Pilotti - Git crash course for Visual Studio devs
ITCamp 2013 - Alessandro Pilotti - Git crash course for Visual Studio devs
 
amrapali builders @@ hacking challenges.pdf
amrapali builders @@ hacking challenges.pdfamrapali builders @@ hacking challenges.pdf
amrapali builders @@ hacking challenges.pdf
 
SQL Server 2014 for Developers (Cristian Lefter)
SQL Server 2014 for Developers (Cristian Lefter)SQL Server 2014 for Developers (Cristian Lefter)
SQL Server 2014 for Developers (Cristian Lefter)
 
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just BeganITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
ITCamp 2013 - Tobiasz Koprowski - 2AM A Disaster Just Began
 
KoprowskiT_it_camp2013 - 2amADisasterJustBegan
KoprowskiT_it_camp2013 - 2amADisasterJustBeganKoprowskiT_it_camp2013 - 2amADisasterJustBegan
KoprowskiT_it_camp2013 - 2amADisasterJustBegan
 
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
 
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
 
causos da linha de frente - #rsonrails 2011
causos da linha de frente - #rsonrails 2011causos da linha de frente - #rsonrails 2011
causos da linha de frente - #rsonrails 2011
 
Trends in Systems and How to Get Efficient Performance
Trends in Systems and How to Get Efficient PerformanceTrends in Systems and How to Get Efficient Performance
Trends in Systems and How to Get Efficient Performance
 

More from ITCamp

ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UXITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp
 

More from ITCamp (20)

ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
 
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
 
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Peter Leeson - Managing SkillsITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Peter Leeson - Managing Skills
 
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Mihai Tataran - Governing your Cloud ResourcesITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
 
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UXITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
 
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Coros - Implementing Clean ArchitectureITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
 
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp 2019 - Florin Flestea -  How 3rd Level support experience influenced m...ITCamp 2019 - Florin Flestea -  How 3rd Level support experience influenced m...
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
 
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
 
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The EnterpriseITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
 
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal TrendsITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
 
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data LakeITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
 
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andy Cross - Business Outcomes from AIITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andy Cross - Business Outcomes from AI
 
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud StoryITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
 
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
 
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
 
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go NowITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
 
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2019 - Peter Leeson - Vitruvian QualityITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2019 - Peter Leeson - Vitruvian Quality
 
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World ApplicationITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
 
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
 
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

.NET Memory Primer (Martin Kulov)

  • 1. Premium community conference on Microsoft technologies itcampro@ itcamp14# .NET Memory Primer Martin Kulov martin@kulov.net
  • 2. Premium community conference on Microsoft technologies itcampro@ itcamp14# Huge thanks to our sponsors & partners!
  • 3. Premium community conference on Microsoft technologies itcampro@ itcamp14# "Out of CPU, memory and disk, memory is typically the most important for overall system performance." Mark Russinovich “All you worry about in a .NET application is the memory.” John Robbins
  • 4. Premium community conference on Microsoft technologies itcampro@ itcamp14# • x86 –2 ^ 32 bits = 4GB /0x FFFF FFFF/ • x64 –2 ^ 64 bits = 16 EB /0x FFFF FFFF' FFFF FFFF/ Virtual Memory Limits
  • 5. Premium community conference on Microsoft technologies itcampro@ itcamp14# x86 Memory Mapping * PFN - Page Frame Number database
  • 6. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Max 4GB –Windows Client, Windows Srv 2008 Standard • Max 128GB –Windows Srv 2003 SP1 Datacenter (PAE) x86 Physical Memory Limits
  • 7. Premium community conference on Microsoft technologies itcampro@ itcamp14# x64 Memory Mapping
  • 8. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Max 4TB - Windows Srv 2012 Standard • Limited per SKU x64 Physical Memory Limits
  • 9. Premium community conference on Microsoft technologies itcampro@ itcamp14# Canonical Form Addresses 48-bit implementation 56-bit implementation 64-bit implementation
  • 10. Premium community conference on Microsoft technologies itcampro@ itcamp14# Virtual Address Space
  • 11. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Code • Data • Stacks • Heaps User Mode Memory
  • 12. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Created for Each Thread • Default to 1MB • Hold Method Data /stack frame/ –Parameters –Local variables –Return address • First In, First Out Stacks
  • 13. Premium community conference on Microsoft technologies itcampro@ itcamp14# Stack Layout
  • 14. Premium community conference on Microsoft technologies itcampro@ itcamp14# • ChildEBP RetAddr Caller,Callee • 08e4e1a4 751b149d _WaitForSingleObjectEx@12+0x98, calling _ZwWaitForSingleObject@12 • 08e4e1e8 718b53c2 ?LeaveRuntimeNoThrow@Thread@@SGJI@Z+0xd7, calling __EH_epilog3 • 08e4e210 755b1194 _WaitForSingleObjectExImplementation@12+0x75, calling _WaitForSingleObjectEx@12 • 08e4e228 718b54d7 ?LoadImage@PEImage@@SGPAV1@PAUHINSTANCE__@@@Z+0x1af • ... • 08e4f5f4 71a10647 ?intermediateThreadProc@Thread@@CGKPAX@Z+0x49 • 08e4f784 71a10635 ?intermediateThreadProc@Thread@@CGKPAX@Z+0x37, calling __alloca_probe_16 • 08e4f798 755b336a @BaseThreadInitThunk@12+0xe • 08e4f7a4 77639f72 ___RtlUserThreadStart@8+0x70 • 08e4f7e4 77639f45 __RtlUserThreadStart@8+0x1b, calling ___RtlUserThreadStart@8 Call Stack Example
  • 15. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Hold Dynamically Allocated Data • 1 Heap Per Logical Processor • Heap Has Segments –Process Heap –Code Heap /JITed code/ –Small Object Heap /SOH/ –Large Object Heap /LOH/ Heaps
  • 16. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Stack –Value Types /Int32, Bool, Struct, etc…/ –Pointers to Reference Types • Heap –Reference Types /Object, String, Array, etc…/ –Free Areas Allocating .NET Memory
  • 17. Premium community conference on Microsoft technologies itcampro@ itcamp14# DEMO: ALLOCATING MEMORY
  • 18. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Stack References • Static References /Fields, ThreadStatic/ • CPU Registers • Interop References /COM, API calls/ • Finalization Queue References Object Roots /GC Roots/
  • 19. Premium community conference on Microsoft technologies itcampro@ itcamp14# • a.k.a. Generational Garbage Collector /GC/ • Three Generations /SOH/ –Gen0 – short lived –Gen1 – medium lived –Gen2 – long lived Nondeterministic Finalization
  • 20. Premium community conference on Microsoft technologies itcampro@ itcamp14# Before GC #1 Gen1 Gen0 Before GC #500 Gen2 Gen2 Gen2 Gen1 Gen0 Gen0 Before GC #0 Before GC #2 Gen2 Gen1 Gen0 Before GC #100 Gen2 Gen2 Gen1 Gen0
  • 21. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Gen0 is Full • Induced GC /System.GC.Collect()/ • System Pressure Collection - When
  • 22. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Rule of Thumb – Ratio 1:10:100 • .NET CLR Memory% time in GC • .NET CLR Memory# Induced GC • .NET CLR Memory# Gen X collections Collection - Cost
  • 23. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Size > 85KB • Memory is marked as free during Gen2 • Avoid Temporary Large Objects • Reuse Objects in LOH If Possible • Many LOH Segments • Fragmentation Problems Large Object Heap
  • 24. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Suspend Managed Threads • Collect Garbage • Resume Managed Threads • Two Phases of GC –Mark –Compact Collection - How
  • 25. Premium community conference on Microsoft technologies itcampro@ itcamp14# • Workstation GC – Non Concurrent • Server GC – Non Concurrent • Workstation GC – Concurrent –Background GC /New in .NET 4/ • Server GC – Background /New in .NET 4.5/ GC Types
  • 26. Premium community conference on Microsoft technologies itcampro@ itcamp14# Workstation GC
  • 27. Premium community conference on Microsoft technologies itcampro@ itcamp14# Server GC
  • 28. Premium community conference on Microsoft technologies itcampro@ itcamp14# Concurrent GC – Before and After
  • 29. Premium community conference on Microsoft technologies itcampro@ itcamp14# Testing Concurrent Server GC
  • 30. Premium community conference on Microsoft technologies itcampro@ itcamp14# Q & A