understanding heap data using windows performance analyzer

19
www.buildwindows.com Understanding heap data Using Windows Performance Analyzer Joe Laughlin Principal SDE Microsoft Corporation HW-928P

Upload: christian-boyd

Post on 16-Dec-2015

245 views

Category:

Documents


2 download

TRANSCRIPT

www.buildwindows.com

Understanding heap data Using Windows Performance Analyzer

Joe LaughlinPrincipal SDEMicrosoft Corporation

HW-928P

www.buildwindows.com

Agenda

• Heap Overview and Concepts• Demo: Collecting and Analyzing Heap Data• Guidelines and Best Practices• Key Takeaways

Heap Overview

www.buildwindows.com

The Windows Heap

• The Windows heap is a memory pool that processes use to dynamically allocate memory as needed

• Primary Audience – Application developers• The Windows heap has three basic allocation areas:

Services allocation requests of all sizes < 64 KB, until allocation thresholds are reached

Mainline (NT Heap)

Composed of sub-segments that service allocation requests using fixed size blocks once allocation thresholds are met

Low Fragmentation

Heap (LFH)

All allocation requests above 64 KB are serviced using VirtualAllocVirtualAlloc

www.buildwindows.com

Heap Overview

• Heap is used for all dynamic allocations• Allocations are made directly via Heap APIs, HeapAlloc,

HeapRealloc• C/C++ allocators , new, alloc, realloc, calloc

• Understand how allocations impact the Heap usage of a process

• Key Concepts• Low Fragmentation Heap (LFH) –once allocation

thresholds are met• Sub-segment – chunks of LFH bucket size• Fragmentation – caused by intermingling allocations of

differing lifetimes

Heap Data Collectionand Analysis

www.buildwindows.com

Heap Vocabulary• Basic Data

• Allocation Lifetime – How long an allocation remains outstanding• Stack – Stack corresponding to the allocation• Address – Address corresponding to allocation• Page Address – Page within which the allocation resides• LFH Bucket Size – size of block the allocation is placed within

• Metadata• Sub-segment Slot Count – number of bucket sized chunks in the sub-

segment• Heap Overhead – each allocation has an overhead of 8 bytes on 32 bit

and 16 bytes on 64 bit

• Context• Transient – allocations with a short lifetime, measured in milliseconds• Outstanding – allocations that remain alive at the point in time being

investigated

www.buildwindows.com

Data Collection

• Heap data collection is restricted to a single process

• Steps1. Open Windows performance

recorder UI2. Select Target application3. Select Heap usage from the

Memory Profiles4. Click on ‘Start’ to start tracing5. Execute scenario of interest6. Click on ‘Save’ to save the trace

when doneWindows Performance

Recorder UI

www.buildwindows.com

WPA Heap Analysis

• Heap Outstanding Allocation Size• What is the total size of allocations alive at a

given point in time?• Heap Outstanding Allocation Count• What is the total number of allocations to a

particular point in time?• Heap Total Allocation Size• What is the total number of allocation to a

particular point in time?• Heap Total Allocation Count• What is the total number of allocations alive

at a given point in time?

www.buildwindows.com

WPA Heap Analysis

• Low Frag Heap Outstanding Allocation Slots• What is the total number of allocations slots

available at a given point in time?• Low Frag Heap Unused Allocation Slots

• What is the total number of unused allocation slots at a given point in time?

• Low Frag Heap Unused Allocation Slot Size• What is the total size of unused allocation

slots at a given point in time?• Heap Extents• What is the size of the heaps and the

contained allocations (includes overhead)

www.buildwindows.com

Summary Table

• Raw data is exposed via summary tables• Vocabulary• Allocation lifetime is expressed based on the visible

region of the trace• AIFO - Allocated inside, freed outside• AIFI - Allocated inside, freed inside• AOFO - Allocated outside, freed outside• AOFI - Allocated outside, freed inside

Demo

Guidelines and Best Practices

www.buildwindows.com

Guidance/Best Practices

• Approach• Understand how dynamic memory allocations impact the

Heap usage of a process• Follow your allocation patterns – Transient and Steady

state• Guidance• Reduce • Number and size of outstanding allocations• Reduce the number of sub-segments

• Reduce the total number of allocations• Reduce the number of heaps

• Avoid intermingling long lived allocations with short lived ones which causes fragmentation

www.buildwindows.com

Key Takeaways

• Understand how heap allocations impact the memory usage of your process

• Understand the concepts of LFH, sub-segments, and fragmentation

• Understand Heap usage of your component and utilize the tools to identify areas for optimization

www.buildwindows.com

For more information

RELATED SESSIONS• HW-59T Improving performance with

the Windows Performance Toolkit

• HW-141T Reducing the memory footprint of drivers and apps

• HW-927P Understanding pool usage using Windows Performance Analyzer

• HW-977P Understanding VirtualAlloc usage using Windows Performance Analyzer

• HW-925P Customizing WPA Trace Views

• HW-926P Introduction to the new WPA Uuser interface

www.buildwindows.com

• Feedback and questions http://forums.dev.windows.com

• Session feedbackhttp://bldw.in/SessionFeedback

thank you

© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to

be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.