Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reducing the memory footprint of drivers and apps

Similar presentations


Presentation on theme: "Reducing the memory footprint of drivers and apps"— Presentation transcript:

1 Reducing the memory footprint of drivers and apps
9/19/2018 6:26 AM HW-141T Reducing the memory footprint of drivers and apps Rahul Nair Program Manager Joe Laughlin Principal Software Developer Microsoft Corporation © 2010 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.

2 Agenda You’ll leave with 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 Partners and Ecosystem Reductions in idle memory usage Telemetry to help identify opportunities Platform investments that improve general memory usage Memory analysis tools Targeted optimizations for key user scenarios Education and outreach Telemetry to help identify additional OS opportunities

7 Understanding memory usage Key Concepts

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

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

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

11 Windows memory management
Available In Use Close /Unmap File Standby Cache FIFO Soft Fault Repurposed Working Sets Modify Modified Allocation Hard Fault Disk De-allocation Free 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 Peak Steady-state Time Memory Usage

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 Ideal Fragmentation Fragmentation
Steady state Peaks Ideal Steady state Peaks Fragmentation 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

16 Classification of Memory
Types

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

18 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: Services allocations of all sizes, until allocation thresholds are reached Mainline (NT Heap) Composed of sub-segments that service allocations of fixed size once allocation thresholds are met Low Fragmentation Heap (LFH) Allocations above 512KB/1MB are allocated using VirtualAlloc VirtualAlloc

19 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: Allocations that can be paged out of memory to the pagefile Paged Pool Allocations that are guaranteed to reside in physical memory NonPaged Pool New for Windows 8: Non executable pages used for these allocations NX NonPaged Pool Allocations that are associated to a particular user session Session Pool

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

21 Collecting and analyzing memory data
9/19/2018 6:26 AM demo Collecting and analyzing memory data © 2010 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.

22 Guidelines and Best Practices

23 General philosophy Understand peaks and steady state 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 Manage memory allocations efficiently 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 Understand allocation patterns 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
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 Driver Development Tools Windows Hardware Dev Center Windows Dev Center

29 thank you Feedback and questions http://forums.dev.windows.com
Session feedback

30 9/19/2018 6:26 AM © 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. © 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.

31


Download ppt "Reducing the memory footprint of drivers and apps"

Similar presentations


Ads by Google