hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 1 | # Memory Usage in CC |
| 2 | |
| 3 | This document gives an overview of memory usage in the CC component, as well as |
| 4 | information on how to analyze that memory. |
| 5 | |
| 6 | [TOC] |
| 7 | |
| 8 | ## Types of Memory in Use |
| 9 | |
| 10 | CC uses a number of types of memory: |
| 11 | |
| 12 | 1. Malloc Memory - Standard system memory used for all manner of objects in CC. |
| 13 | 2. Discardable Memory - Memory allocated by the discardable memory system. |
| 14 | Designed to be freeable by the system at any time (under memory pressure). |
| 15 | In most cases, only pinned discardable memory should be considered to |
| 16 | have a cost; however, the implementation of discardable memory is platform |
| 17 | dependent, and on certain platforms unpinned memory can contribute to |
| 18 | memory pressure to some degree. |
| 19 | 3. Shared Memory - Memory which is allocated by the Browser and can safely |
| 20 | be transferred between processes. This memory is allocated by the browser |
| 21 | but may count against a renderer process depending on who logically "owns" |
| 22 | the memory. |
| 23 | 4. GPU Memory - Memory which is allocated on the GPU and typically does not |
| 24 | count against system memory. This mainly includes OpenGL objects. |
| 25 | |
| 26 | ## Categories Of Memory |
| 27 | |
| 28 | Memory-infra tracing will grab dumps of CC memory in several categories. |
| 29 | |
| 30 | ### CC Category |
| 31 | |
| 32 | The CC category contains resource allocations made by ResourceProvider. All |
| 33 | resource allocations are enumerated under cc/resource_memory. A subset of |
| 34 | resources are used as tile memory, and are also enumerated under cc/tile_memory. |
| 35 | For resources that appear in both cc/tile_memory and cc/resource_memory, the |
| 36 | size will be attributed to cc/tile_memory (effective_size of cc/resource_memory |
| 37 | will not include these resources). |
| 38 | |
| 39 | If the one-copy tile update path is in use, the cc category will also enumerate |
| 40 | staging resources used as intermediates when drawing tiles. These resources are |
| 41 | like tile_memory, in that they are shared with cc/resource_memory. |
| 42 | |
| 43 | Note that depending on the path being used, CC memory may be either shared |
| 44 | memory or GPU memory: |
| 45 | |
primiano | b48bcd6 | 2017-04-03 09:45:34 | [diff] [blame] | 46 | ``` |
hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 47 | Path | Tile Memory Type | Staging Memory Type |
| 48 | -------------|------------------------------------------- |
| 49 | Bitmap | Shared Memory | N/A |
| 50 | One Copy | GPU Memory | Shared Memory |
| 51 | Zero Copy | GPU or Shared Memory | N/A |
| 52 | GPU | GPU Memory | N/A |
primiano | b48bcd6 | 2017-04-03 09:45:34 | [diff] [blame] | 53 | ``` |
hjd | 0304f11 | 2016-11-14 22:36:53 | [diff] [blame] | 54 | |
| 55 | Note that these values can be determined from a memory-infra dump. For a given |
| 56 | resource, hover over the small green arrow next to it's "size". This will show |
| 57 | the other allocations that this resource is aliased with. If you see an |
| 58 | allocation in the GPU process, the memory is generally GPU memory. Otherwise, |
| 59 | the resource is typically Shared Memory. |
| 60 | |
| 61 | Tile and Staging memory managers are set up to evict any resource not used |
| 62 | within 1s. |
| 63 | |
| 64 | ### GPU Category |
| 65 | |
| 66 | This category lists the memory allocations needed to support CC's GPU path. |
| 67 | Despite the name, the data in this category (within a Renderer process) is not |
| 68 | GPU memory but Shared Memory. |
| 69 | |
| 70 | Allocations tracked here include GL command buffer support allocations such as: |
| 71 | |
| 72 | 1. Command Buffer Memory - memory used to send commands across the GL command |
| 73 | buffer. This is backed by Shared Memory. |
| 74 | 2. Mapped Memory - memory used in certain image upload paths to share data |
| 75 | with the GPU process. This is backed by Shared Memory. |
| 76 | 3. Transfer Buffer Memory - memory used to transfer data to the GPU - used in |
| 77 | different paths than mapped memory. Also backed by Shared Memory. |
| 78 | |
| 79 | ### Discardable Category |
| 80 | |
| 81 | Cached images make use of Discardable memory. These allocations are managed by |
| 82 | Skia and a better summary of these allocations can likely be found in the Skia |
| 83 | category. |
| 84 | |
| 85 | ### Malloc Category |
| 86 | |
| 87 | The malloc category shows a summary of all memory allocated through malloc. |
| 88 | |
| 89 | Currently the information here is not granular enough to be useful, and a |
| 90 | good project would be to track down and instrument any large pools of memory |
| 91 | using malloc. |
| 92 | |
| 93 | Some Skia caches also make use of malloc memory. For these allocations, a better |
| 94 | summary can be seen in the Skia category. |
| 95 | |
| 96 | ### Skia Category |
| 97 | |
| 98 | The Skia category shows all resources used by the Skia rendering system. These |
| 99 | can be divided into a few subcategories. skia/gpu_resources/* includes all |
| 100 | resources using GPU memory. All other categories draw from either Shared or |
| 101 | malloc memory. To determine which type of memory a resource is using, hover |
| 102 | over the green arrow next to its size. This will show the other allocations |
| 103 | which the resource is aliased with. |
| 104 | |
| 105 | ## Other Areas of Interest |
| 106 | |
| 107 | Many of the allocations under CC are aliased with memory in the Browser or GPU |
| 108 | process. When investigating CC memory it may be worth looking at the following |
| 109 | external categories: |
| 110 | |
| 111 | 1. GPU Process / GPU Category - All GPU resources allocated by CC have a |
| 112 | counterpart in the GPU/GPU category. This includes GL Textures, buffers, and |
| 113 | other GPU backed objects such as Native GPU Memory Buffers. |
| 114 | 2. Browser Process / GpuMemoryBuffer Category - Resources backed by Shared |
| 115 | Memory GpuMemoryBuffers are allocated by the browser and will be tracked |
| 116 | in this category. |
| 117 | 3. Browser Process / SharedMemory Category - Resources backed by Bitmap and |
| 118 | Shared Memory GpuMemoryBuffer objects are allocated by the browser and will |
| 119 | also tracked in this category. |
| 120 | |
| 121 | ## Memory TODOs |
| 122 | |
| 123 | The following areas have insufficient memory instrumentation. |
| 124 | |
| 125 | 1. DisplayLists - DisplayLists can be quite large and are currently |
| 126 | un-instrumented. These use malloc memory and currently contribute to |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 127 | malloc/allocated_objects/<unspecified>. [BUG](https://crbug.com/567465) |