# Ensures only 1 tracing session with this key can be active
unique_session_name: "perfetto_mm_events_session"
# If a trace with bugreport_score > 0 is running,
# the captured data is made available in the zipped bugreport
# at FS/data/misc/perfetto-traces/bugreport/systrace.pftrace
bugreport_score: 100
trigger_config {
trigger_mode: START_TRACING
trigger_timeout_ms: 3600000 # 1 hour
triggers {
# kmem_activity trigger gets activated when memory pressure
# is detected
name: "kmem_activity"
stop_delay_ms: 360000 # 6 mins
}
}
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-10 UTC。"],[],[],null,["# MM events historical memory statistics\n\nDevices that launch on Android 12 and higher\nutilize `mm_events`, a set of memory-related statistics that get captured\nperiodically while a system experiences memory pressure. `mm_events` is\nintegrated with `perfetto` tracing mechanisms, and because it's activated only\nwhen memory pressure is detected, its added performance overhead is minimal. The\nstatistics collection starts when the kernel's `kswapd`, `direct reclaim,` or\n`compaction` mechanisms get activated, and it stays active for a [configurable\nperiod of time](#customization)\nto capture statistics at regular intervals.\n\nInstead of providing a one-time snapshot of the system memory state when a bug\nreport is filed, `mm_events` shows a brief historical view of the memory\nstatistics during periods of memory pressure. The captured statistics are listed\nin the following tables.\n\n**vmstat fields**\n\n|---------------------------|--------------------------|\n| `nr_free_pages` | `nr_slab_reclaimable` |\n| `nr_slab_unreclaimable` | `nr_active_file` |\n| `nr_inactive_file` | `nr_active_anon` |\n| `nr_inactive_anon` | `workingset_refault` |\n| `workingset_activate` | `nr_file_pages` |\n| `pgpgin` | `pgpgout` |\n| `pswpin` | `pswpout` |\n| `pgsteal_kswapd_dma` | `pgsteal_kswapd_normal` |\n| `pgsteal_kswapd_movable` | `pgsteal_direct_dma` |\n| `pgsteal_direct_normal` | `pgsteal_direct_movable` |\n| `pgscan_kswapd_dma` | `pgscan_kswapd_normal` |\n| `pgscan_kswapd_movable` | `pgscan_direct_dma` |\n| `pgscan_direct_normal` | `pgscan_direct_movable` |\n| `compact_migrate_scanned` | `compact_free_scanned` |\n\n**mm-related trace events**\n\n|-----------------------------------------|---------------------------------------|\n| `vmscan/mm_vmscan_kswapd_wake` | `vmscan/mm_vmscan_kswapd_sleep` |\n| `vmscan/mm_vmscan_direct_reclaim_begin` | `vmscan/mm_vmscan_direct_reclaim_end` |\n| `compaction/mm_compaction_begin` | `compaction/mm_compaction_end` |\n\nAnalyze mm_events data\n----------------------\n\nIf `mm_events` is enabled, the bug reports for the events that get captured soon\nafter a device begins to experience high memory pressure provide the historical\n`mm_events` stats, in the form of a zipped report in\n`FS/data/misc/perfetto-traces/bugreport/systrace.pftrace.`\n\nBoth the `vmstat` data and `ftrace` events can be viewed for analysis using the\n[Perfetto UI](https://ui.perfetto.dev/).\n\n### vmstat data\n\nUpload the `systrace.pftrace` file to Perfetto UI to see the `vmstat` data\ngraphed on a timeline as shown in Figure 1:\n\n**Figure 1.** Timeline of vmstat graphical data.\n\n### ftrace events\n\nThe captured `ftrace` `mm_events` aren't shown graphically on the timeline. To\nview them, click the **Query SQL** tab, located as shown in Figure 2:\n\n**Figure 2.** Click Query (SQL) to access.\n\nEnable mm_events\n----------------\n\nTo enable mm_events, set sysprop `persist.mm_events.enabled=true` from vendor\n`init.rc`.\n| **Note:** When enabling `mm_events`, set `persist.mm_events.enabled` to `true` before `post-fs-data` is triggered to ensure that the `mm_events` tracing instance is available before `mm_events` is started.\n| **Warning:** `mm_events` has \\~0.3% max CPU usage when capturing data. Proceed carefully if you are considering using `mm_events` for production builds, since the frequency of memory pressure events is highly device-dependent. For example, devices with low memory budgets experience memory pressure events more frequently, and consequently, `mm_events` *can stay active* (always on) for them.\n\nThe following are in place to mitigate the memory and CPU footprint of mm_events:\n\n- An `mm-events ftrace` instance uses a 4 KB buffer per CPU.\n- The `kmem_activity` trigger is rate-limited to once per minute.\n- Only 1 `mm-events` trace session can be active at any time.\n\nCustomization\n-------------\n\n`mm_events` uses a `perfetto` trace config file to specify which stats to capture\nduring the tracing session.\n\nYou can provide a custom Perfetto trace config in `/vendor/etc/mm_events.cfg`.\nFor a description of the available trace config fields, see the [Perfetto\nDocs](https://perfetto.dev/docs/reference/trace-config-proto).\nFor a sample trace configuration, see this\n[`mm_events.cfg`](https://android.googlesource.com/platform/external/perfetto/+/9a1689eeaa281b21c5bcedcad5d54ddaeeb7889c/test/configs/mm_events.cfg)\nexample.\n\nThe important fields to include in your trace config to ensure it gets triggered\nby memory pressure are shown in the snippet: \n\n # Ensures only 1 tracing session with this key can be active\n unique_session_name: \"perfetto_mm_events_session\"\n\n # If a trace with bugreport_score \u003e 0 is running,\n # the captured data is made available in the zipped bugreport\n # at FS/data/misc/perfetto-traces/bugreport/systrace.pftrace\n bugreport_score: 100\n\n trigger_config {\n trigger_mode: START_TRACING\n trigger_timeout_ms: 3600000 # 1 hour\n triggers {\n # kmem_activity trigger gets activated when memory pressure\n # is detected\n name: \"kmem_activity\"\n stop_delay_ms: 360000 # 6 mins\n }\n }\n\nIn this configuration `mm_events` initiates the perfetto `kmem_activity` trigger\nand the Perfetto trace session begins capturing `vm_stats` and `ftrace` memory\nevents until the end of the configured `stop_delay_ms` period, 36000 ms (6 minutes).\nThe trigger timeout is set to a large value (in this case, 1 hour) and\n[`mm_events config`](https://android.googlesource.com/platform/external/perfetto/+/9a1689eeaa281b21c5bcedcad5d54ddaeeb7889c/tools/mm_events)\nis periodically rearmed to ensure that `mm_events` is always enabled. A bug report\ngets generated as a result, containing the type of data shown in [Figure 1](#figure1)\nand [Figure 2](#figure2).\n| **Note:** If you don't provide a custom config, a [default](https://android.googlesource.com/platform/external/perfetto/+/9a1689eeaa281b21c5bcedcad5d54ddaeeb7889c/tools/mm_events) trace configuration is used instead."]]