SlideShare a Scribd company logo
.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

More Related Content

What's hot

Adaptive Linear Solvers and Eigensolvers
Adaptive Linear Solvers and EigensolversAdaptive Linear Solvers and Eigensolvers
Adaptive Linear Solvers and Eigensolvers
inside-BigData.com
 
Slide smallfiles
Slide smallfilesSlide smallfiles
Slide smallfiles
rledisez
 
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
Andrey Vagin
 
Ceph RBD Update - June 2021
Ceph RBD Update - June 2021Ceph RBD Update - June 2021
Ceph RBD Update - June 2021
Ceph Community
 
Disaggregating Ceph using NVMeoF
Disaggregating Ceph using NVMeoFDisaggregating Ceph using NVMeoF
Disaggregating Ceph using NVMeoF
Zoltan 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 Rosen
Anne 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 Beyond
ScyllaDB
 
Couchbase live 2016
Couchbase live 2016Couchbase live 2016
Couchbase live 2016
Pierre Mavro
 
Evaluation of RBD replication options @CERN
Evaluation of RBD replication options @CERNEvaluation of RBD replication options @CERN
Evaluation of RBD replication options @CERN
Ceph Community
 
Fedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIUFedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIU
Andrey 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 Yield
ScyllaDB
 
Some analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDBSome analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDB
Xiao Yan Li
 
Gnocchi v3 brownbag
Gnocchi v3 brownbagGnocchi v3 brownbag
Gnocchi v3 brownbag
Gordon 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 System
sjreese
 
An Introduction to Priam
An Introduction to PriamAn Introduction to Priam
An Introduction to Priam
Jason 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 Capture
Tokyo University of Science
 

What's hot (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 to .NET Memory Primer

Caches microP
Caches microPCaches microP
Memory Hierarchy PPT of Computer Organization
Memory Hierarchy PPT of Computer OrganizationMemory Hierarchy PPT of Computer Organization
Memory Hierarchy PPT of Computer Organization
2022002857mbit
 
Basics of JVM Tuning
Basics of JVM TuningBasics of JVM Tuning
Basics of JVM Tuning
Vladislav Gangan
 
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performance
Codemotion
 
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 Cache
Nicolas Poggi
 
Memory (Computer Organization)
Memory (Computer Organization)Memory (Computer Organization)
Memory (Computer Organization)
JyotiprakashMishra18
 
Diagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - CassandraDiagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - Cassandra
Jon 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 Java
Abhishek Asthana
 
Clr jvm implementation differences
Clr jvm implementation differencesClr jvm implementation differences
Clr jvm implementation differences
Jean-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-NL
Thijs 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-final
Tommy 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 Group
HungWei 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 4
aminmesbahi
 
Ct213 memory subsystem
Ct213 memory subsystemCt213 memory subsystem
Ct213 memory subsystem
Sandeep 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 Demos
AMD 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
 
All The Little Pieces
All The Little PiecesAll The Little Pieces
All The Little Pieces
Andrei Zmievski
 

Similar to .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
 

More from Martin Kulov

10 Customizations in VSTS
10 Customizations in VSTS10 Customizations in VSTS
10 Customizations in VSTS
Martin 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
 
Inside CoreCLR
Inside CoreCLRInside CoreCLR
Inside CoreCLR
Martin Kulov
 
postBuild 2012 Highlights
postBuild 2012 HighlightspostBuild 2012 Highlights
postBuild 2012 Highlights
Martin Kulov
 
Demystifying Visual Studio 2012 Performance Tools
Demystifying Visual Studio 2012 Performance ToolsDemystifying Visual Studio 2012 Performance Tools
Demystifying Visual Studio 2012 Performance Tools
Martin 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 website
Martin Kulov
 
SofiaDev L9 Source Control Management
SofiaDev L9 Source Control ManagementSofiaDev L9 Source Control Management
SofiaDev L9 Source Control Management
Martin Kulov
 

More from 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
 

Recently uploaded

dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 

Recently uploaded (20)

dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 

.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 /

Editor's Notes

  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); }