.NET Memory Primer Martin Kulov. "Out of CPU, memory and disk, memory is typically the most important for overall system performance." Mark Russinovich.

Slides:



Advertisements
Similar presentations
An Implementation of Mostly- Copying GC on Ruby VM Tomoharu Ugawa The University of Electro-Communications, Japan.
Advertisements

Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Wenjin Xu. BasicsAllocationCollectionFinalization GC Mode Sample.
A Block-structured Heap Simplifies Parallel GC Simon Marlow (Microsoft Research) Roshan James (U. Indiana) Tim Harris (Microsoft Research) Simon Peyton.
1 Overview Assignment 5: hints  Garbage collection Assignment 4: solution.
The Linux Kernel: Memory Management
Memory management.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Memory Management Case study (JVM & CLR) KIRAN KUMAR V KIRAN KUMAR V LENIN THUMMALAPALLI LENIN THUMMALAPALLI.
An Overview of Palm OS n Designed for special hardware –small screen ( 160 x 160 ) –less processing power than desktop PCs –quick turnaround expected –limited.
Memory Management Tom Roeder CS fa. Motivation Recall unmanaged code eg C: { double* A = malloc(sizeof(double)*M*N); for(int i = 0; i < M*N; i++)
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
Spring 2014Jim Hogg - UW - CSE P501W-1 CSE P501 – Compiler Construction Conventional Heap Storage Garbage Collection.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
CS 536 Spring Automatic Memory Management Lecture 24.
This presentation: Sasha GoldshteinCTO, Sela Group Garbage Collection Performance Tips.
Chapter 10 Storage management
MOSTLY PARALLEL GARBAGE COLLECTION Authors : Hans J. Boehm Alan J. Demers Scott Shenker XEROX PARC Presented by:REVITAL SHABTAI.
Chapter 10 Storage Management Implementation details beyond programmer’s control Storage/CPU time trade-off Binding times to storage.
Run-Time Storage Organization
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection.
CLR: Garbage Collection Inside Out
Oracle Memory Configuration on Windows Server Configuring Large Memory for Oracle on 32-bit and 64-bit Windows.
By Matthew Smith, John Allred, Chris Fulton. Requirements Relocation Protection Sharing Logical Organization Physical Organization.
Tutorial 6 Memory Management
1 Thread Synchronization (Un)Fairness in the.NET Common Language Runtime If you are building an application that absolutely requires fair thread synchronization,
Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
File I/O Applied Component-Based Software Engineering File I/O CSE 668 / ECE 668 Prof. Roger Crawfis.
GC Algorithm inside.NET Luo Bingqiao 5/22/2009. Agenda 1. 经典基本垃圾回收算法 2.CLR 中垃圾回收算法介绍 3.SSCLI 中 Garbage Collection 源码分析.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Fast Conservative Garbage Collection Rifat Shahriyar Stephen M. Blackburn Australian National University Kathryn S. M cKinley Microsoft Research.
The Structure of Processes (Chap 6 in the book “The Design of the UNIX Operating System”)
How to be a C# ninja in 10 easy steps Benjamin Day.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
Topic 2d High-Level languages and Systems Software
Writing faster managed code Claudio Caldato Program Manager CLR Performance Team.
Chapter 4 Memory Management Virtual Memory.
1 Memory Management Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.
Runtime System CS 153: Compilers. Runtime System Runtime system: all the stuff that the language implicitly assumes and that is not described in the program.
SQL Server Memory Architecture Sumit Sarabhai Microsoft Corp.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
® July 21, 2004GC Summer School1 Cycles to Recycle: Copy GC Without Stopping the World The Sapphire Collector Richard L. Hudson J. Eliot B. Moss Originally.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
.NET Garbage Collection Performance Tips Sasha Goldshtein | SELA Group.
Embedded Real-Time Systems
CS 140 Lecture Notes: Virtual Memory
Memory Management.
Processes and threads.
Module 9: Memory and Resource Management
Java 9: The Quest for Very Large Heaps
CS703 - Advanced Operating Systems
Instructors: Haryadi Gunawi
CS 140 Lecture Notes: Virtual Memory
AVG 24th 2015 ADVANCED c# - part 1.
Patrick Dussud Technical Fellow Developer Division
Strategies for automatic memory management
CS 140 Lecture Notes: Virtual Memory
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
Oracle Memory Configuration on Windows Server
Created By: Asst. Prof. Ashish Shah, J.M.Patel College, Goregoan West
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
CS 140 Lecture Notes: Virtual Memory
Buddy Allocation CS 161: Lecture 5 2/11/19.
Run-time environments
Presentation transcript:

.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 calling 08e4e1e8 718b53c2 calling __EH_epilog3 08e4e b1194 calling 08e4e b54d7 08e4f5f4 71a e4f784 71a10635 calling __alloca_probe_16 08e4f b336a 08e4f7a f72 08e4f7e f45 calling 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 #1Gen1Gen0 Before GC #500Gen2 Gen2 Gen2Gen1Gen0 Gen0 Before GC #0 Before GC #2Gen2Gen1Gen0 Before GC #100Gen2 Gen2Gen1Gen0

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

CLR Profiler Visual Studio Memory Profiler Visual Studio Debug Managed Memory 3 rd Party Commercial Tools Memory Visualization

Thank blog.kulov.net