SlideShare una empresa de Scribd logo
1 de 38
.NET Memory Primer
Martin Kulov
"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
• x86
– 2 ^ 32 bits = 4GB /0x FFFF FFFF/
• x64
– 2 ^ 64 bits = 16 EB /0x FFFF FFFF' FFFF
FFFF/
Addressing Limits /Virtual
Limits/
• x86
– 4GB Windows Client, Windows Srv 2008
Standard
– 128GB Windows Srv 2003 SP1 Datacenter
(PAE)
Physical Memory Limits
x86 Memory Mapping
* PFN - Page Frame Number database
• x64
– 4TB Windows Srv 2012 Standard
– per SKU
Physical Memory Limits
x64 Memory
Mapping (AMD64)
Canonical Form Addresses
48-bit implementation 56-bit implementation 64-bit implementation
Virtual Address
Space
• Code
• Data
• Heaps
• Stacks
User Mode Memory
• Created for Each Thread
• Default to 1MB
• Hold Method Data /stack frame/
– Parameters
– Local variables
– Return address
Stacks
Stack Layout
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
• Hold Dynamically Allocated Data
• Code Heap /JITed code/
• Small Object Heap /SOH/
• Large Object Heap /LOH/
• Process Heap
Heaps
• Stack
– Value Types /Int32, Bool, Struct, etc…/
– Pointers to Reference Types
• Heap
– Reference Types
/Object, String, Array, etc…/
– Free Areas
Allocating .NET Memory
DEMO: Allocating Memory
• Stack References
• Static References /Fields, ThreadStatic/
• CPU Registers
• Interop References /COM, API calls/
• Finalization Queue References
Object Roots /GC Roots/
• a.k.a. Generational Garbage Collector
/GC/
• Three Generations /SOH/
– Gen0 – short lived
– Gen1 – medium lived
– Gen2 – long lived
Nondeterministic Finalization
• Contiguous Memory Areas
• Ephemeral Segment
– Holds Gen0, Gen1
– There Can Be Only One
• Gen2 Segments
Segments
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
Allocation - Cost
• Cheap Lock on UP; Lock Free on MP
• Moving a Pointer Forward
• Clearing the Memory for New Objects
• Register for Finalization if Applicable
• Object Proximity
Collection - When
• Gen0 is Full
• Induced GC /System.GC.Collect()/
• System Pressure
DEMO: Collecting Memory
Collection - Cost
• Rule of Thumb – Ratio 1:10:100
• .NET CLR Memory% time in GC
• .NET CLR Memory# Induced GC
• .NET CLR Memory# Gen X collections
Large Object Heap
• > 85KB /or >1,000 doubles/
• Memory is Swept During Gen2 /Marked as
Free/
• Avoid Temporary Large Objects in LOH
• Reuse Objects in LOH If Possible
• Many LOH Segments
• Fragmentation Problems
Collection - How
• Suspend Managed Threads
• Collect Garbage
• Resume Managed Threads
• Two Phases of GC
– Mark
– Compact
GC Types
• 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/
Workstation GC – Non
Concurrent
Server GC – Non Concurrent
Workstation GC - Concurrent
Workstation GC - Background
Server GC - Background
Server GC – Before and After
Testing Server GC
New in .NET 4.5.1 RC
• LOH Compacting!
GCSettings.LargeObjectHeapCompactionMode =
GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();
• Very Fast Allocation
• Automatic GC
• Nondeterministic Finalization
• Finalizers and Finalization Queue
• Deterministic Finalization - IDisposable
Resource Management
CHALLENGE:
Implement Dispose Pattern
/ Volunteer is Needed /
Thank you!
@kulov
blog.kulov.net
www.linkedin.com/in/kulov
martin@kulov.net

Más contenido relacionado

La actualidad más candente

Adaptive Linear Solvers and Eigensolvers
Adaptive Linear Solvers and EigensolversAdaptive Linear Solvers and Eigensolvers
Adaptive Linear Solvers and Eigensolversinside-BigData.com
 
Slide smallfiles
Slide smallfilesSlide smallfiles
Slide smallfilesrledisez
 
FOSDEM2015: Live migration for containers is around the corner
FOSDEM2015: Live migration for containers is around the cornerFOSDEM2015: Live migration for containers is around the corner
FOSDEM2015: Live migration for containers is around the cornerAndrey Vagin
 
Ceph RBD Update - June 2021
Ceph RBD Update - June 2021Ceph RBD Update - June 2021
Ceph RBD Update - June 2021Ceph Community
 
Disaggregating Ceph using NVMeoF
Disaggregating Ceph using NVMeoFDisaggregating Ceph using NVMeoF
Disaggregating Ceph using NVMeoFZoltan Arnold Nagy
 
Embedded Recipes 2017 - Reliable monitoring with systemd - Jérémy Rosen
Embedded Recipes 2017 - Reliable monitoring with systemd - Jérémy RosenEmbedded Recipes 2017 - Reliable monitoring with systemd - Jérémy Rosen
Embedded Recipes 2017 - Reliable monitoring with systemd - Jérémy RosenAnne Nicolas
 
Is It Faster to Go with Redpanda Transactions than Without Them?!
Is It Faster to Go with Redpanda Transactions than Without Them?!Is It Faster to Go with Redpanda Transactions than Without Them?!
Is It Faster to Go with Redpanda Transactions than Without Them?!ScyllaDB
 
Scylla Summit 2022: The Future of Consensus in ScyllaDB 5.0 and Beyond
Scylla Summit 2022: The Future of Consensus in ScyllaDB 5.0 and BeyondScylla Summit 2022: The Future of Consensus in ScyllaDB 5.0 and Beyond
Scylla Summit 2022: The Future of Consensus in ScyllaDB 5.0 and BeyondScyllaDB
 
Couchbase live 2016
Couchbase live 2016Couchbase live 2016
Couchbase live 2016Pierre Mavro
 
Evaluation of RBD replication options @CERN
Evaluation of RBD replication options @CERNEvaluation of RBD replication options @CERN
Evaluation of RBD replication options @CERNCeph Community
 
Fedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIUFedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIUAndrey Vagin
 
QNIBTerminal: Understand your datacenter by overlaying multiple information l...
QNIBTerminal: Understand your datacenter by overlaying multiple information l...QNIBTerminal: Understand your datacenter by overlaying multiple information l...
QNIBTerminal: Understand your datacenter by overlaying multiple information l...QNIB Solutions
 
Object Compaction in Cloud for High Yield
Object Compaction in Cloud for High YieldObject Compaction in Cloud for High Yield
Object Compaction in Cloud for High YieldScyllaDB
 
Some analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDBSome analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDBXiao Yan Li
 
Gnocchi v3 brownbag
Gnocchi v3 brownbagGnocchi v3 brownbag
Gnocchi v3 brownbagGordon Chung
 
Health Check Your DB2 UDB For Z/OS System
Health Check Your DB2 UDB For Z/OS SystemHealth Check Your DB2 UDB For Z/OS System
Health Check Your DB2 UDB For Z/OS Systemsjreese
 
An Introduction to Priam
An Introduction to PriamAn Introduction to Priam
An Introduction to PriamJason Brown
 
Experiments with Practical On-Demand Multi-Core Packet Capture
Experiments with Practical On-Demand Multi-Core Packet CaptureExperiments with Practical On-Demand Multi-Core Packet Capture
Experiments with Practical On-Demand Multi-Core Packet CaptureTokyo University of Science
 

La actualidad más candente (18)

Adaptive Linear Solvers and Eigensolvers
Adaptive Linear Solvers and EigensolversAdaptive Linear Solvers and Eigensolvers
Adaptive Linear Solvers and Eigensolvers
 
Slide smallfiles
Slide smallfilesSlide smallfiles
Slide smallfiles
 
FOSDEM2015: Live migration for containers is around the corner
FOSDEM2015: Live migration for containers is around the cornerFOSDEM2015: Live migration for containers is around the corner
FOSDEM2015: Live migration for containers is around the corner
 
Ceph RBD Update - June 2021
Ceph RBD Update - June 2021Ceph RBD Update - June 2021
Ceph RBD Update - June 2021
 
Disaggregating Ceph using NVMeoF
Disaggregating Ceph using NVMeoFDisaggregating Ceph using NVMeoF
Disaggregating Ceph using NVMeoF
 
Embedded Recipes 2017 - Reliable monitoring with systemd - Jérémy Rosen
Embedded Recipes 2017 - Reliable monitoring with systemd - Jérémy RosenEmbedded Recipes 2017 - Reliable monitoring with systemd - Jérémy Rosen
Embedded Recipes 2017 - Reliable monitoring with systemd - Jérémy Rosen
 
Is It Faster to Go with Redpanda Transactions than Without Them?!
Is It Faster to Go with Redpanda Transactions than Without Them?!Is It Faster to Go with Redpanda Transactions than Without Them?!
Is It Faster to Go with Redpanda Transactions than Without Them?!
 
Scylla Summit 2022: The Future of Consensus in ScyllaDB 5.0 and Beyond
Scylla Summit 2022: The Future of Consensus in ScyllaDB 5.0 and BeyondScylla Summit 2022: The Future of Consensus in ScyllaDB 5.0 and Beyond
Scylla Summit 2022: The Future of Consensus in ScyllaDB 5.0 and Beyond
 
Couchbase live 2016
Couchbase live 2016Couchbase live 2016
Couchbase live 2016
 
Evaluation of RBD replication options @CERN
Evaluation of RBD replication options @CERNEvaluation of RBD replication options @CERN
Evaluation of RBD replication options @CERN
 
Fedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIUFedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIU
 
QNIBTerminal: Understand your datacenter by overlaying multiple information l...
QNIBTerminal: Understand your datacenter by overlaying multiple information l...QNIBTerminal: Understand your datacenter by overlaying multiple information l...
QNIBTerminal: Understand your datacenter by overlaying multiple information l...
 
Object Compaction in Cloud for High Yield
Object Compaction in Cloud for High YieldObject Compaction in Cloud for High Yield
Object Compaction in Cloud for High Yield
 
Some analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDBSome analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDB
 
Gnocchi v3 brownbag
Gnocchi v3 brownbagGnocchi v3 brownbag
Gnocchi v3 brownbag
 
Health Check Your DB2 UDB For Z/OS System
Health Check Your DB2 UDB For Z/OS SystemHealth Check Your DB2 UDB For Z/OS System
Health Check Your DB2 UDB For Z/OS System
 
An Introduction to Priam
An Introduction to PriamAn Introduction to Priam
An Introduction to Priam
 
Experiments with Practical On-Demand Multi-Core Packet Capture
Experiments with Practical On-Demand Multi-Core Packet CaptureExperiments with Practical On-Demand Multi-Core Packet Capture
Experiments with Practical On-Demand Multi-Core Packet Capture
 

Similar a .NET Memory Primer

Memory Hierarchy PPT of Computer Organization
Memory Hierarchy PPT of Computer OrganizationMemory Hierarchy PPT of Computer Organization
Memory Hierarchy PPT of Computer Organization2022002857mbit
 
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performanceCodemotion
 
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
 
Accelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket CacheAccelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket CacheNicolas Poggi
 
Diagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - CassandraDiagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - CassandraJon Haddad
 
An Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAbhishek Asthana
 
Clr jvm implementation differences
Clr jvm implementation differencesClr jvm implementation differences
Clr jvm implementation differencesJean-Philippe BEMPEL
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)MongoDB
 
Spil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLSpil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLThijs Terlouw
 
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward
 
Shak larry-jeder-perf-and-tuning-summit14-part2-final
Shak larry-jeder-perf-and-tuning-summit14-part2-finalShak larry-jeder-perf-and-tuning-summit14-part2-final
Shak larry-jeder-perf-and-tuning-summit14-part2-finalTommy Lee
 
High performace network of Cloud Native Taiwan User Group
High performace network of Cloud Native Taiwan User GroupHigh performace network of Cloud Native Taiwan User Group
High performace network of Cloud Native Taiwan User GroupHungWei Chiu
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4aminmesbahi
 
Ct213 memory subsystem
Ct213 memory subsystemCt213 memory subsystem
Ct213 memory subsystemSandeep Kamath
 
MM-4105, Realtime 4K HDR Decoding with GPU ACES, by Gary Demos
MM-4105, Realtime 4K HDR Decoding with GPU ACES, by Gary DemosMM-4105, Realtime 4K HDR Decoding with GPU ACES, by Gary Demos
MM-4105, Realtime 4K HDR Decoding with GPU ACES, by Gary DemosAMD Developer Central
 
MemGuard: Memory Bandwidth Reservation System for Efficient Performance Isola...
MemGuard: Memory Bandwidth Reservation System for Efficient Performance Isola...MemGuard: Memory Bandwidth Reservation System for Efficient Performance Isola...
MemGuard: Memory Bandwidth Reservation System for Efficient Performance Isola...Heechul Yun
 

Similar a .NET Memory Primer (20)

Caches microP
Caches microPCaches microP
Caches microP
 
Memory Hierarchy PPT of Computer Organization
Memory Hierarchy PPT of Computer OrganizationMemory Hierarchy PPT of Computer Organization
Memory Hierarchy PPT of Computer Organization
 
Basics of JVM Tuning
Basics of JVM TuningBasics of JVM Tuning
Basics of JVM Tuning
 
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performance
 
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 ...
 
Accelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket CacheAccelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket Cache
 
Memory (Computer Organization)
Memory (Computer Organization)Memory (Computer Organization)
Memory (Computer Organization)
 
Diagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - CassandraDiagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - Cassandra
 
An Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in Java
 
Clr jvm implementation differences
Clr jvm implementation differencesClr jvm implementation differences
Clr jvm implementation differences
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)
 
Spil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLSpil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NL
 
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
 
Shak larry-jeder-perf-and-tuning-summit14-part2-final
Shak larry-jeder-perf-and-tuning-summit14-part2-finalShak larry-jeder-perf-and-tuning-summit14-part2-final
Shak larry-jeder-perf-and-tuning-summit14-part2-final
 
High performace network of Cloud Native Taiwan User Group
High performace network of Cloud Native Taiwan User GroupHigh performace network of Cloud Native Taiwan User Group
High performace network of Cloud Native Taiwan User Group
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4
 
Ct213 memory subsystem
Ct213 memory subsystemCt213 memory subsystem
Ct213 memory subsystem
 
MM-4105, Realtime 4K HDR Decoding with GPU ACES, by Gary Demos
MM-4105, Realtime 4K HDR Decoding with GPU ACES, by Gary DemosMM-4105, Realtime 4K HDR Decoding with GPU ACES, by Gary Demos
MM-4105, Realtime 4K HDR Decoding with GPU ACES, by Gary Demos
 
MemGuard: Memory Bandwidth Reservation System for Efficient Performance Isola...
MemGuard: Memory Bandwidth Reservation System for Efficient Performance Isola...MemGuard: Memory Bandwidth Reservation System for Efficient Performance Isola...
MemGuard: Memory Bandwidth Reservation System for Efficient Performance Isola...
 
All The Little Pieces
All The Little PiecesAll The Little Pieces
All The Little Pieces
 

Más de Martin Kulov

10 Customizations in VSTS
10 Customizations in VSTS10 Customizations in VSTS
10 Customizations in VSTSMartin Kulov
 
Performance Testing for Scalable Microservices - Martin Kulov
Performance Testing for Scalable Microservices - Martin KulovPerformance Testing for Scalable Microservices - Martin Kulov
Performance Testing for Scalable Microservices - Martin KulovMartin Kulov
 
postBuild 2012 Highlights
postBuild 2012 HighlightspostBuild 2012 Highlights
postBuild 2012 HighlightsMartin Kulov
 
Demystifying Visual Studio 2012 Performance Tools
Demystifying Visual Studio 2012 Performance ToolsDemystifying Visual Studio 2012 Performance Tools
Demystifying Visual Studio 2012 Performance ToolsMartin Kulov
 
How to build CDN for your website
How to build CDN for your websiteHow to build CDN for your website
How to build CDN for your websiteMartin Kulov
 
SofiaDev L9 Source Control Management
SofiaDev L9 Source Control ManagementSofiaDev L9 Source Control Management
SofiaDev L9 Source Control ManagementMartin Kulov
 

Más de Martin Kulov (7)

10 Customizations in VSTS
10 Customizations in VSTS10 Customizations in VSTS
10 Customizations in VSTS
 
Performance Testing for Scalable Microservices - Martin Kulov
Performance Testing for Scalable Microservices - Martin KulovPerformance Testing for Scalable Microservices - Martin Kulov
Performance Testing for Scalable Microservices - Martin Kulov
 
Inside CoreCLR
Inside CoreCLRInside CoreCLR
Inside CoreCLR
 
postBuild 2012 Highlights
postBuild 2012 HighlightspostBuild 2012 Highlights
postBuild 2012 Highlights
 
Demystifying Visual Studio 2012 Performance Tools
Demystifying Visual Studio 2012 Performance ToolsDemystifying Visual Studio 2012 Performance Tools
Demystifying Visual Studio 2012 Performance Tools
 
How to build CDN for your website
How to build CDN for your websiteHow to build CDN for your website
How to build CDN for your website
 
SofiaDev L9 Source Control Management
SofiaDev L9 Source Control ManagementSofiaDev L9 Source Control Management
SofiaDev L9 Source Control Management
 

Último

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 

Último (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 

.NET Memory Primer

  • 2. "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
  • 3. • x86 – 2 ^ 32 bits = 4GB /0x FFFF FFFF/ • x64 – 2 ^ 64 bits = 16 EB /0x FFFF FFFF' FFFF FFFF/ Addressing Limits /Virtual Limits/
  • 4. • x86 – 4GB Windows Client, Windows Srv 2008 Standard – 128GB Windows Srv 2003 SP1 Datacenter (PAE) Physical Memory Limits
  • 5. x86 Memory Mapping * PFN - Page Frame Number database
  • 6. • x64 – 4TB Windows Srv 2012 Standard – per SKU Physical Memory Limits
  • 8. Canonical Form Addresses 48-bit implementation 56-bit implementation 64-bit implementation
  • 10. • Code • Data • Heaps • Stacks User Mode Memory
  • 11. • Created for Each Thread • Default to 1MB • Hold Method Data /stack frame/ – Parameters – Local variables – Return address Stacks
  • 13. 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
  • 14. • Hold Dynamically Allocated Data • Code Heap /JITed code/ • Small Object Heap /SOH/ • Large Object Heap /LOH/ • Process Heap Heaps
  • 15. • Stack – Value Types /Int32, Bool, Struct, etc…/ – Pointers to Reference Types • Heap – Reference Types /Object, String, Array, etc…/ – Free Areas Allocating .NET Memory
  • 17. • Stack References • Static References /Fields, ThreadStatic/ • CPU Registers • Interop References /COM, API calls/ • Finalization Queue References Object Roots /GC Roots/
  • 18. • a.k.a. Generational Garbage Collector /GC/ • Three Generations /SOH/ – Gen0 – short lived – Gen1 – medium lived – Gen2 – long lived Nondeterministic Finalization
  • 19. • Contiguous Memory Areas • Ephemeral Segment – Holds Gen0, Gen1 – There Can Be Only One • Gen2 Segments Segments
  • 20. 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. Allocation - Cost • Cheap Lock on UP; Lock Free on MP • Moving a Pointer Forward • Clearing the Memory for New Objects • Register for Finalization if Applicable • Object Proximity
  • 22. Collection - When • Gen0 is Full • Induced GC /System.GC.Collect()/ • System Pressure
  • 24. Collection - Cost • Rule of Thumb – Ratio 1:10:100 • .NET CLR Memory% time in GC • .NET CLR Memory# Induced GC • .NET CLR Memory# Gen X collections
  • 25. Large Object Heap • > 85KB /or >1,000 doubles/ • Memory is Swept During Gen2 /Marked as Free/ • Avoid Temporary Large Objects in LOH • Reuse Objects in LOH If Possible • Many LOH Segments • Fragmentation Problems
  • 26. Collection - How • Suspend Managed Threads • Collect Garbage • Resume Managed Threads • Two Phases of GC – Mark – Compact
  • 27. GC Types • 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/
  • 28. Workstation GC – Non Concurrent
  • 29. Server GC – Non Concurrent
  • 30. Workstation GC - Concurrent
  • 31. Workstation GC - Background
  • 32. Server GC - Background
  • 33. Server GC – Before and After
  • 35. New in .NET 4.5.1 RC • LOH Compacting! GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GC.Collect();
  • 36. • Very Fast Allocation • Automatic GC • Nondeterministic Finalization • Finalizers and Finalization Queue • Deterministic Finalization - IDisposable Resource Management
  • 37. CHALLENGE: Implement Dispose Pattern / Volunteer is Needed /

Notas del editor

  1. Operating Systems and PAE Supporthttp://msdn.microsoft.com/en-us/windows/hardware/gg487512.aspxPhysical Address ExtensionHttp://en.wikipedia.org/wiki/Physical_Address_ExtensionMemory Limits for Windows Releaseshttp://msdn.microsoft.com/en-us/library/aa366778.aspx
  2. Pushing the Limits of Windows: Physical Memoryhttp://blogs.technet.com/b/markrussinovich/archive/2008/07/21/3092070.aspxPushing the Limits of Windows: Virtual Memoryhttp://blogs.technet.com/b/markrussinovich/archive/2008/11/17/3155406.aspxPage Frame Number (PFN) databasehttp://social.technet.microsoft.com/wiki/contents/articles/15259.page-frame-number-pfn-database.aspx
  3. Operating Systems and PAE Supporthttp://msdn.microsoft.com/en-us/windows/hardware/gg487512.aspxPhysical Address ExtensionHttp://en.wikipedia.org/wiki/Physical_Address_ExtensionMemory Limits for Windows Releaseshttp://msdn.microsoft.com/en-us/library/aa366778.aspx
  4. x86-64http://en.wikipedia.org/wiki/X86-64
  5. Virtual address spacehttp://en.wikipedia.org/wiki/Virtual_address_space
  6. Pushing the Limits of Windows: Processes and Threadshttp://blogs.technet.com/b/markrussinovich/archive/2009/07/08/3261309.aspx
  7. .load sosArgument passed by val and ref – !clrstack -aShow stack objects – !clrstack -aModify arguments by valReference typesStop on unrooted reference typeShow !gcrootShow !eeheap -gc
  8. http://blogs.msdn.com/b/tess/archive/2008/04/17/how-does-the-gc-work-and-what-are-the-sizes-of-the-different-generations.aspxhttp://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-08-40-25-69/FUN421_5F00_Stephens.ppt
  9. Call GC.Collect()!eeheap -gc!heapstat!gcwhere
  10. .NET CLR Memory\% time in GC - This counter measures the amount of CPU time you spend in GC and it is calculated as (CPU time for GC/CPU time since last GC) .NET CLR Memory\# Induced GC – This is the number of garbage collections that have occurred as a result of someone calling GC.Collect(). Ideally this should be 0 since inducing full collections means that you spend more time in the GC, and also because the GC continuously adapts itself to the allocation patterns in the application, and performing manual GCs skews this optimization. .NET CLR Memory\# Gen X collections – This counter displays the amount of collections that have been performed for a given generation. Since the cost of gen 2 collections is high compared to Gen 1 and Gen 0 you want to have as few Gen 2 collections per Gen 1 and Gen 0 collections as possible. A ratio of 1:10:100 is pretty good.
  11. http://msdn.microsoft.com/library/ee787088(v=vs.110).aspx
  12. http://msdn.microsoft.com/en-us/library/system.runtime.gcsettings.largeobjectheapcompactionmode.aspx
  13. Resource managementhttp://blogs.msdn.com/b/brada/archive/2005/02/11/371015.aspxhttp://www.vineetgupta.com/2007/01/notes-on-the-clr-garbage-collector/
  14. protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // dispose-only, i.e. non-finalizable logic } // shared cleanup logic disposed = true; } } ~ComplexCleanupBase() { Dispose(false); } public void Dispose() { Dispose(true);GC.SuppressFinalize(this); }