1 / 31

Reducing the memory footprint of drivers and apps

HW-141T. Reducing the memory footprint of drivers and apps. Rahul Nair Program Manager Joe Laughlin Principal Software Developer Microsoft Corporation. Agenda. Platform approach to reducing memory usage Understanding memory usage Classification of memory t ypes

garren
Download Presentation

Reducing the memory footprint of drivers and apps

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HW-141T Reducing the memory footprint of drivers and apps Rahul Nair Program Manager Joe Laughlin Principal Software Developer Microsoft Corporation

  2. Agenda Platform approach to reducing memory usage Understanding memory usage Classification of memory types Using Windows Performance Analyzer Guidelines and best practices You’ll leave with • How to understand the memory impact of an app/driver • How to identify areas of opportunity for optimizing memory usage

  3. Memory is a key resource, and optimizing memory usage ensures a consistent and responsive user experience.

  4. Why is memory important? • Being leaner and more efficient in terms of memory footprint • Ensures a responsive and smooth app experience • Shapes user perception regarding resource utilization • Improves scalability across a range of hardware platforms • Reduces power consumption

  5. Platform approach to Reducing Memory Usage

  6. Optimizing memory footprint • Multi-pronged strategy: • Windows • Reductions in idle memory usage • Platform investments that improve general memory usage • Targeted optimizations for key user scenarios • Telemetry to help identify additional OS opportunities • Partners and Ecosystem • Telemetry to help identify opportunities • Memory analysis tools • Education and outreach

  7. Understanding memory usage KeyConcepts

  8. Key concepts • App cost in totality • Impact to system responsiveness • Short term vs. long term impact • Allocation patterns

  9. App cost in totality Dimensions Holistic view of memory usage Breadth of impact • Direct usage • Files • Allocations Frequency of use • Memory usage of an app/driver • Indirect usage Targeted platform and audience • System memory resources • Subsystems

  10. Composition of physical memory Composition of Physical Memory In Use Available • Process working sets • Standby Cache • Non Paged Memory • Free Critical for system responsiveness • Modified

  11. Windows memory management FIFO Standby Cache In Use Hard Fault Available Soft Fault Repurposed Close /Unmap File Modify Modified Working Sets Allocation Free De-allocation Disk FIFO

  12. System responsiveness and the Standby Cache • Standby Cache holds contents that were recently accessed by apps and is critical for ensuring system responsiveness • Enables more efficient utilization of physical memory • Cost of accessing memory from RAM is much lower than the cost of a Disk IO • Important Considerations: • The higher your persistent memory usage  Lesser the availability of RAM for other purposes • Large transient usage can push out more valuable contents

  13. Short term vs. long term impact • Understand the memory usage of your Scenario/Component in terms of • Transient or Peak Impact • Persistent or Steady-state Impact • Important considerations • Frequency of peaks will have significant impact on standby cache • Focus on memory usage associated with common user scenarios Memory Usage Peak Steady-state Time

  14. Example: peak vs. steady state • Why is the steady state memory usage growing for this scenario? • Why is there a transient peak in memory usage for this part of the scenario?

  15. Allocation Patterns Steady state Peaks • Fragmentation • Occurs when unused ‘gaps’ arise between blocks of allocated memory • You can no longer allocate a block of memory as big as the available free memory • Due to mixing allocations of longer lifetimes with shorter lifetimes • Important considerations • Focus on grouping together allocations of similar lifetime and size to minimize fragmentation Ideal Steady state Peaks Fragmentation

  16. Classification of Memory Types

  17. Basic memory classification • File Examples HighLevel Classification • Heap • VirtualAlloc • Paged Pool • Pageable • Dynamic • Non Paged Pool • Non Paged Driver code • Non-Pageable • Executables (exe, dll) • Data files (txt, db) • Driver Images (.sys)

  18. VirtualAlloc Mainline (NT Heap) Low Fragmentation Heap (LFH) • Services allocations of all sizes, until allocation thresholds are reached • Composed of sub-segments that service allocations of fixed size once allocation thresholds are met • Allocations above 512KB/1MB are allocated using VirtualAlloc Dynamic user mode allocations • The Windows heap is a memory pool created at start-up that processes use to dynamically allocate memory as needed • Windows heap has three basic dynamic allocation areas:

  19. Paged Pool • NonPaged Pool • NX NonPaged Pool • Session Pool • Allocations that can be paged out of memory to the pagefile • Allocations that are guaranteed to reside in physical memory • New for Windows 8: Non executable pages used for these allocations • Allocations that are associated to a particular user session Dynamic kernel mode allocations • Pool is the kernel mode equivalent of heap • Memory resource that the OS and device drivers use to store their data structures • The Windows Pool has four basic allocation areas:

  20. Memory data • Windows Performance Analyzer presents data in the form of graphs and summary tables • Memory data: • Context • Basic data • Metadata • Size - How much? • Lifetime - How long? • Allocationstack - By who? • Address - Where? Transient - Short lived Outstanding - Alive at a given point in time • Based on Memory Type • Example • Heap Handle • Pool Type • Pool tag

  21. demo Collecting and analyzing memory data

  22. Guidelines and Best Practices

  23. General philosophy • Understand peaks and steady state Manage memory allocations efficiently • Understand allocation patterns • Questions • When do you need to allocate memory? • When do you release memory? • Considerations • Be lazy in allocating and diligent in releasing • Avoid excessive pre-allocation that you might never use • Questions • What do you need long term for normal usage? • What is scenario specific? • Considerations • Minimize steady state • Optimize for your most frequent and most important user scenarios • Questions • How frequently do you access a particular allocation? • Would your patterns result in fragmentation? • Considerations • Group together allocations with similar lifetime • Reuse temporary allocations • Avoid frequent allocation/deallocation Use the Windows Performance Analyzer to analyze and identify areas of optimization

  24. Best practices for Driver Developers Optimizing memory footprint • Understand pool usage • Focus on the most frequent usage and important scenarios like System Boot Best practices • Focus on non-paged memory usage • Avoid excessive pre-allocation that you might never use • Layout data structures efficiently and reuse them when possible • Avoid mixing long lived allocations with short lived ones which can cause fragmentation • Test and validate to eliminate memory leaks • Move non-paged allocations to the more secure non-executable non-paged pool

  25. Best practices for app developers Optimizing memory footprint • Understand your dynamic memory usage • Focus on the most frequent and important user scenarios • Understand the new Metro style app model and implications Best practices • Defer memory allocations until you need to use them, especially during app launch • Ensure that scenario specific allocations are freed as soon as possible • Reuse dynamic allocations/temporary buffers whenever possible • Avoid frequent mapping and unmapping of Virtual Address space • Avoid mixing long lived allocations with short lived ones which can cause fragmentation

  26. Key takeaways • Memory is a shared resource and good citizenship is important • Has a direct impact on system responsiveness • Approach to reducing memory usage should include • Optimizing for long term and short term impact • Efficiently managing memory allocations • Optimal allocation patterns • Use the tools to actively invest in improving your memory usage

  27. Q&A

  28. For more information Related sessions Documentation & articles • Driver Development Tools • Windows Hardware Dev Center • Windows Dev Center • HW-59T Improving performance with the Windows Performance Toolkit • HW-927P Understanding pool usage using Windows Performance Analyzer • HW-928P Understanding heap data 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 user interface

  29. thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback

  30. © 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.

More Related