Reducing the memory footprint of drivers and apps
Download
1 / 31

Reducing the memory footprint of drivers and apps - PowerPoint PPT Presentation


  • 173 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Reducing the memory footprint of drivers and apps' - garren


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
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
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


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


Why is memory important
Why is memory important? ensures a consistent and responsive user experience.

  • 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


Platform approach to ensures a consistent and responsive user experience.

Reducing Memory Usage


Optimizing memory footprint
Optimizing memory ensures a consistent and responsive user experience.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


Understanding ensures a consistent and responsive user experience.

memory usage

KeyConcepts


Key concepts
Key concepts ensures a consistent and responsive user experience.

  • App cost in totality

  • Impact to system responsiveness

  • Short term vs. long term impact

  • Allocation patterns


App cost in totality
App cost in totality ensures a consistent and responsive user experience.

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


Composition of physical m emory
Composition of physical ensures a consistent and responsive user experience.memory

Composition of Physical Memory

In Use

Available

  • Process working sets

  • Standby Cache

  • Non Paged Memory

  • Free

Critical for system responsiveness

  • Modified


Windows memory m anagement
Windows memory ensures a consistent and responsive user experience.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


System responsiveness and the standby cache
System responsiveness and the Standby Cache ensures a consistent and responsive user experience.

  • 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


Short t erm vs long t erm i mpact
Short ensures a consistent and responsive user experience.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


Example peak vs steady s tate
Example: peak vs. steady ensures a consistent and responsive user experience.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?


Allocation patterns
Allocation Patterns ensures a consistent and responsive user experience.

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


Classification of Memory ensures a consistent and responsive user experience.

Types


Basic memory classification
Basic memory classification ensures a consistent and responsive user experience.

  • 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)


Dynamic user m ode a llocations

  • VirtualAlloc ensures a consistent and responsive user experience.

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:


Dynamic kernel m ode a llocations

  • Paged ensures a consistent and responsive user experience.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:


Memory data
Memory data ensures a consistent and responsive user experience.

  • 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


Collecting and analyzing memory data

d ensures a consistent and responsive user experience.emo

Collecting and analyzing memory data


Guidelines and Best ensures a consistent and responsive user experience.

Practices


General philosophy
General philosophy ensures a consistent and responsive user experience.

  • 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


    Best practices for driver developers
    Best practices for Driver Developers ensures a consistent and responsive user experience.

    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


    Best practices for a pp d evelopers
    Best practices for ensures a consistent and responsive user experience.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


    Key takeaways
    Key takeaways ensures a consistent and responsive user experience.

    • 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


  • Q&A ensures a consistent and responsive user experience.


    For more information
    For more information ensures a consistent and responsive user experience.

    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


    Feedback and q uestions http forums dev windows com session f eedback http bldw in sessionfeedback

    t ensures a consistent and responsive user experience.hank you

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

    Session feedbackhttp://bldw.in/SessionFeedback


    © ensures a consistent and responsive user experience.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.


    ad