Memory Management: High-Level Overview

Similar documents
the gamedesigninitiative at cornell university Lecture 10 Memory Management

the gamedesigninitiative at cornell university Lecture 13 Memory Management

the gamedesigninitiative at cornell university Lecture 9 Memory Management

CS3600 SYSTEMS AND NETWORKS

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

the gamedesigninitiative at cornell university Lecture 6 Scene Graphs

Motivation for Dynamic Memory. Dynamic Memory Allocation. Stack Organization. Stack Discussion. Questions answered in this lecture:

IOS PERFORMANCE. Getting the most out of your Games and Apps

LECTURE 5. Announcements

Game Architecture Revisited

Chapter 3.5 Memory and I/O Systems

Android Fundamentals - Part 1

Memory Management: The Details

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2017

Gecata by Movavi 5. Recording desktop. Recording with webcam Capture videos of the games you play. Record video of your full desktop.

Caching and Demand-Paged Virtual Memory

(Refer Slide Time: 1:26)

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

Activities and Fragments

Memory - Paging. Copyright : University of Illinois CS 241 Staff 1

Four Components of a Computer System

application components

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

the gamedesigninitiative at cornell university Lecture 15 Game Audio

Lecture 16. Introduction to Game Development IAP 2007 MIT

Mali Developer Resources. Kevin Ho ARM Taiwan FAE

Chapter 1 Computer System Overview

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2015

CIS Operating Systems Memory Management Cache and Demand Paging. Professor Qiang Zeng Spring 2018

Section 7: Wait/Exit, Address Translation

CSE 120 Principles of Operating Systems

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

2017 Pearson Educa2on, Inc., Hoboken, NJ. All rights reserved.

Profiling and Debugging Games on Mobile Platforms

Today: Segmentation. Last Class: Paging. Costs of Using The TLB. The Translation Look-aside Buffer (TLB)

CS399 New Beginnings. Jonathan Walpole

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Compressing loads of content into only 20mb

An introduction to checkpointing. for scientifc applications

CS 61C: Great Ideas in Computer Architecture. Direct Mapped Caches

Engine Support System. asyrani.com

Unity Software (Shanghai) Co. Ltd.

Reversed Buffer Overflow Cross Stack Attacks. Kris Kaspersky Endeavor Security, Inc.

CSE 373 OCTOBER 23 RD MEMORY AND HARDWARE

What Operating Systems Do An operating system is a program hardware that manages the computer provides a basis for application programs acts as an int

The Processor Memory Hierarchy

Lecture 14: Cache & Virtual Memory

Chapter 13: I/O Systems. Operating System Concepts 9 th Edition

BASIC OPERATIONS. Managing System Resources

iseries Managing disk units

ELEC 377 Operating Systems. Week 1 Class 2

Computer Memory. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

Naming in OOLs and Storage Layout Comp 412

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

TI2725-C, C programming lab, course

the gamedesigninitiative at cornell university Lecture 17 Color and Textures

Chapter 8: Main Memory

BACKUP APP V7 MICROSOFT SYSTEM BACKUP AND RESTORE GUIDE

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

CONSOLE ARCHITECTURE

Cisco Events Mobile Application

CSE 410 Final Exam 6/09/09. Suppose we have a memory and a direct-mapped cache with the following characteristics.

IT 540 Operating Systems ECE519 Advanced Operating Systems

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

Chapter 8: Memory-Management Strategies

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

The control of I/O devices is a major concern for OS designers

Broken Age's Approach to Scalability. Oliver Franzke Lead Programmer, Double Fine Productions

STORING DATA: DISK AND FILES

EECS 482 Introduction to Operating Systems

C06: Memory Management

Modern Virtual Memory Systems. Modern Virtual Memory Systems

DASH COPY GUIDE. Published On: 11/19/2013 V10 Service Pack 4A Page 1 of 31

Chapter 0 : MVC review / Threading & Concurrency. CSCI 251 Android App Development

Application Fundamentals

ECE 598 Advanced Operating Systems Lecture 22

Paging algorithms. CS 241 February 10, Copyright : University of Illinois CS 241 Staff 1

Streaming Massive Environments From Zero to 200MPH

Optimisation. CS7GV3 Real-time Rendering

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

CHAPTER 11: IMPLEMENTING FILE SYSTEMS (COMPACT) By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

Lecture 1 Introduction (Chapter 1 of Textbook)

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

ArcGIS Runtime: Maximizing Performance of Your Apps. Will Jarvis and Ralf Gottschalk

CS370 Operating Systems

Welcome to Part 3: Memory Systems and I/O

Ref: Chap 12. Secondary Storage and I/O Systems. Applied Operating System Concepts 12.1

Midterm Exam CPS 210: Operating Systems Spring 2013

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Chapter 8: Main Memory

Chapter 11: Implementing File Systems

Transcription:

Lecture 9 : High-Level Overview

Gaming Memory (Last Generation) Playstation 3 256 MB RAM for system 256 MB for graphics card X-Box 360 512 MB RAM (unified) Nintendo Wii 88 MB RAM (unified) 24 MB for graphics card iphone/ipad 1 GB RAM (unified) 2

Gaming Memory (Current Generation) Playstation 4 8 GB RAM (unified) X-Box One 8 GB RAM (unified) 5 GB for games Nintendo Wii-U 2 GB RAM (unified) 1 GB only for OS iphone/ipad 1 GB RAM (unified) 3

Why Not Virtual Memory? Secondary storage exists Consoles have 500 GB HD idevices have 64 GB Flash But access time is slow HDs transfer at ~160 MB/s Best SSD is ~500 MB/s Recall 16 ms per frame At best, can access 8 MB Yields uneven performance 4

Memory Usage: Images Pixel color is 4 bytes 1 byte each for r, b, g, alpha More if using HDR color Image a 2D array of pixels 1280x1024 monitor size 5,242,880 bytes ~ 5 MB More if using mipmaps Graphic card texture feature Smaller versions of image Cached for performance But can double memory use 5

Memory Usage: Images Pixel color is 4 bytes 1 byte each for r, b, g, alpha More if using HDR color Image a 2D array of pixels 1280x1024 monitor size 5,242,880 bytes ~ 5 MB MipMaps Original Image More if using mipmaps Graphic card texture feature Smaller versions of image Cached for performance But can double memory use 6

But My JPEG is only 8 KB! Formats often compressed JPEG, PNG, GIF But not always TIFF Must uncompress to display Need space to uncompress In RAM or graphics card Only load when needed Loading is primary I/O operation in AAA games 7 Causes texture popping

But My JPEG is only 8 KB! Formats often compressed JPEG, PNG, GIF But not always TIFF Must uncompress to display Need space to uncompress In RAM or graphics card Only load when needed Loading is primary I/O operation in AAA games 8 Causes texture popping

Loading Screens 9

Problems with Asset Loading How to load assets? May have a lot of assets Init May have large assets Loading is blocking Game stops until done Update Cannot draw or animate May need to unload Running out of memory Draw Free something first 10

Problems with Asset Loading How to load assets? May have a lot of assets May have large assets Loading is blocking Game stops until done Cannot draw or animate May need to unload Running out of memory Free something first Blocks all drawing Blocks next frame Init Update Draw 11

Loading Screens 12

Solution: Asynchronous Loader Game Thread Second Thread Update Draw Specify Asset Notify done Update and draw simple animations until assets loaded Asset Loader 13 Game Architecture

Solution: Asynchronous Loader Game Thread Second Thread Update Specify Asset Notify done Asset Loader Draw Also an asset manager Each asset given a key Can access asset by key Works like hash table 14 Game Architecture

Solution: Asynchronous Loader Game Thread Second Thread Update Specify Asset Notify done Asset Loader Draw Not always a good idea May need OpenGL utils Example: Textures Limited to main thread 15 Game Architecture

Alternative: Iterative Loader Game Thread Asset Manager Update Initialize Asset Update Loader Draw Access 16 Game Architecture

Alternative: Iterative Loader Uses a time budget Give set amount of time Do as much as possible Stop until next update Better for OpenGL Give time to manager Animate with remainder No resource contention LibGDX approach CUGL is asynchronous Asset Manager Initialize Asset Update Loader Access 17 Game Architecture

Alternative: Iterative Loader Uses a time budget Give set amount of time Do as much as possible Stop until next update Better for OpenGL Give time to manager Animate with remainder No resource contention LibGDX approach CUGL is asynchronous Load Assets Update Draw Budget b Remaining time t b 18 Game Architecture

Assets Beyond Images AAA games have a lot of 3D geometry Vertices for model polygons Physics bodies per polygon Scene graphs for organizing this data When are all se objects created? At load time (filling up memory)? Or only when y are needed? We need to understand memory better 19

Traditional Memory Organization High Address Stack Free Space Heap Program Data Program Code Static Variables 20 Low Address

Traditional Memory Organization High Address Stack Function parameters Local variables Return values Free Space Heap Low Address Program Data Program Code Static Variables 21

Traditional Memory Organization High Address Stack Function parameters Local variables Return values Free Space Heap Objects created via new (e.g. Every object in Java) Low Address Program Data Program Code Static Variables 22

Traditional Memory Organization High Address Stack Function parameters Local variables Return values Easy to Handle Free Space Heap Objects created via new (e.g. Every object in Java) 23 Low Address Program Data Program Code Static Variables Easy to Handle

Traditional Memory Organization High Address Stack Function parameters Local variables Return values Easy to Handle Free Space Heap Objects created via new (e.g. Every object in Java) Problems! 24 Low Address Program Data Program Code Static Variables Easy to Handle

Traditional Memory Organization High Address Stack Function parameters Local variables Return values Dedicated to process. Free Space Consists of machine addressable space. Heap Objects created via new Allocations with malloc Leverages Virtual Memory Low Address Program Data Program Code Static Variables 25

Device Memory Mobile Memory Organization Stack Program Data Heap Stack Program Data Stack Stack Program Data Program Data 26

How Do Apps Compete for Memory? Active app takes what it can Cannot steal from OS OS may suspend apps App Suspension App quits; memory freed ios: 5 min (or so) on exit Android: If needed Suspend apps can recover OS allows limited paging Page out on suspension Page back in on restart 27

How Do Apps Compete for Memory? Active app takes what it can Cannot steal from OS OS may suspend apps App Suspension App quits; memory freed ios: 5 min (or so) on exit Android: If needed Can override in ios 7 Suspend apps can recover OS allows limited paging Page out on suspension Page back in on restart 28

How Do Apps Compete for Memory? Active app takes what it can Cannot steal from OS OS may suspend apps App Suspension App quits; memory freed ios: 5 min (or so) on exit Android: If needed Suspend apps can recover OS allows limited paging Page out on suspension Page back in on restart Can override in ios 7 You must code this! Orwise, data is lost. 29

State Management in ios 7+ Active Running & getting input Inactive Running, but no input Transition to suspended Background Same as inactive But apps can stay here Example: Music 30 Suspended Stopped & Memory freed

State Management in ios 7+ Active Running & getting input Write handlers to process entering, leaving each state Inactive Running, but no input Transition to suspended Background Same as inactive But apps can stay here Example: Music 31 Suspended Stopped & Memory freed

ios State Handling applicationdidbecomeactive: Your app became (resumed as) foreground app. Use this to recover memory state. applicationwillresignactive: Your app will switch to inactive or background. Stop game loop and page out memory. applicationdidenterbackground: Your app is in background and may be suspended. applicationwillenterforeground: Your app is leaving background, but is not yet active. 32

Android State Handling All methods in Application class 33

Android State Handling Reload memory All methods in Application class 34

Android State Handling Page out memory All methods in Application class 35

CUGL is Simplified Android Model onstartup() Initialized and now active onsuspend() Sent to background Gives you chance to save Also time to pause music onresume() Returns to app to active Allows you to restore state 36 onshutdown() Stopped & memory freed

CUGL is Simplified Android Model onstartup() Initialized and now active onlowmemory() Warning memory is low Gives you chance to unload Else app will shut down onsuspend() Sent to background Gives you chance to save Also time to pause music onresume() Returns to app to active Allows you to restore state 37 onshutdown() Stopped & memory freed

Memory Organization and Games Inter-Frame Memory Carries over across frame boundaries Update Draw Intra-Frame Memory Recovered each frame 38

Memory Organization and Games Inter-Frame Memory Carries over across frame boundaries Heap Update or Stack? Does it matter? Draw Intra-Frame Memory Recovered each frame 39

Distinguishing Data Types Intra-Frame Local computation Local variables (managed by compiler) Temporary objects (not necessarily managed) Transient data structures Built at start of update Used to process update Can be deleted at end Inter-Frame Game state Model instances Controller state View state and caches Long-term data structures Built at start/during frame Lasts for multiple frames May adjust to data changes 40

Distinguishing Data Types Intra-Frame Local computation Local variables (managed by compiler) Temporary objects (not necessarily managed) Transient data structures Built at start of update Used to process update Can be deleted at end Inter-Frame Game state Model instances Controller state View state and caches Long-term data structures Built at start/during frame Lasts for multiple frames May adjust to data changes 41

Distinguishing Data Types Intra-Frame Local computation Local variables (managed by compiler) Temporary objects (not necessarily managed) Transient data structures Built at start of update Used to process update Can be deleted at end Inter-Frame Game state Model instances Controller state View state and caches Long-term data structures Built at start/during frame Lasts for multiple frames May adjust to data changes 42

Handling Game Memory Intra-Frame Does not need to be paged Drop latest frame Restart on frame boundary Want size reasonably fixed Local variables always are Limited # of allocations Limit new inside loops Often use custom allocator GC at frame boundaries Inter-Frame Potential to be paged Defines current game state May just want level start Size is more flexible No. of objects is variable Subsystems may turn on/off User settings may affect OS allocator okay, but Recycle with free lists 43

Handling Game Memory Intra-Frame Does not need to be paged Drop latest frame Restart on frame boundary Want size reasonably fixed Local variables always are Limited # of allocations Limit new inside loops Often use custom allocator GC at frame boundaries Inter-Frame Potential to be paged Defines current game state May just want level start Size is more flexible No. of objects is variable Subsystems may turn on/off User settings may affect OS allocator okay, but Recycle with free lists 44

Advanced: Spatial Loading Most game data is spatial Only load if player nearby Unload as player moves away Minimizes memory used Arrange memory in cells Different from a memory pool Track player visibility radius Load/unload via outer radius Alternative: loading zones Elevators in Mass Effect 45

Advanced: Spatial Loading Most game data is spatial Only load if player nearby Unload as player moves away Minimizes memory used Arrange memory in cells Different from a memory pool Track player visibility radius Load/unload via outer radius Alternative: loading zones Visibility Radius Elevators in Mass Effect 46

Advanced: Spatial Loading Most game data is spatial Only load if player nearby Loading Radius Unload as player moves away Minimizes memory used Arrange memory in cells Different from a memory pool Track player visibility radius Load/unload via outer radius Alternative: loading zones Visibility Radius Elevators in Mass Effect 47

Spatial Loading in Assassin s Creed 48

Implementing Spatial Loading Part of serialization model Level/save file has cells Cell addresses in memory Load/page on demand On Disk Sort of like virtual memory But paging strategy is spatial In RAM 49

Spatial Loading Challenges Not same as virtual memory Objects unloaded do not exist Do not save state when unload Objects loaded are new created Can lead to unexpected states Forgetful NPCs Creative Assassin s Creed kills Workaround: Global State Track major game conditions Example: Guards Alerted Use to load objects in standard, but appropriate, configurations See Piazza for There is No Spoon 50

Next Time: Low-Level Details 51