Android 12 이상에서 실행되는 기기는 시스템이 메모리 압력을 받는 동안 주기적으로 캡처되는 메모리 관련 통계 집합인 mm_events를 활용합니다. mm_events는 perfetto 추적 메커니즘과 통합되며 메모리 압력이 감지될 때만 활성화되므로 추가된 성능 오버헤드가 최소화됩니다. 통계 수집은 커널의 kswapd나 direct reclaim,, compaction 메커니즘이 활성화될 때 시작되며 구성 가능한 기간 동안 활성 상태를 유지하여 일정한 간격으로 통계를 캡처합니다.
버그 신고가 제출될 때 시스템 메모리 상태의 일회성 스냅샷을 제공하는 대신 mm_events는 메모리 압력이 발생하는 기간 동안 이전 메모리 통계를 간략하게 보여줍니다. 캡처된 통계는 다음 표에 나열되어 있습니다.
vmstat 필드
nr_free_pages
nr_slab_reclaimable
nr_slab_unreclaimable
nr_active_file
nr_inactive_file
nr_active_anon
nr_inactive_anon
workingset_refault
workingset_activate
nr_file_pages
pgpgin
pgpgout
pswpin
pswpout
pgsteal_kswapd_dma
pgsteal_kswapd_normal
pgsteal_kswapd_movable
pgsteal_direct_dma
pgsteal_direct_normal
pgsteal_direct_movable
pgscan_kswapd_dma
pgscan_kswapd_normal
pgscan_kswapd_movable
pgscan_direct_dma
pgscan_direct_normal
pgscan_direct_movable
compact_migrate_scanned
compact_free_scanned
mm 관련 트레이스 이벤트
vmscan/mm_vmscan_kswapd_wake
vmscan/mm_vmscan_kswapd_sleep
vmscan/mm_vmscan_direct_reclaim_begin
vmscan/mm_vmscan_direct_reclaim_end
compaction/mm_compaction_begin
compaction/mm_compaction_end
mm_events 데이터 분석
mm_events가 사용 설정된 경우 기기에서 높은 메모리 압력을 받기 시작한 직후 캡처된 이벤트의 버그 신고는 FS/data/misc/perfetto-traces/bugreport/systrace.pftrace.에서 압축된 신고 형식으로 이전 mm_events 통계를 제공합니다.
vmstat 데이터와 ftrace 이벤트는 모두 Perfetto UI를 사용하여 분석을 위해 확인할 수 있습니다.
vmstat 데이터
systrace.pftrace 파일을 Perfetto UI에 업로드하여 그림 1에서와 같이 타임라인에 그래프로 표시된 vmstat 데이터를 확인합니다.
그림 1. vmstat 그래픽 데이터 타임라인
ftrace 이벤트
캡처된 ftracemm_events는 타임라인에 그래픽으로 표시되지 않습니다. 이를 확인하려면 그림 2와 같이 Qeury SQL 탭을 클릭합니다.
그림 2. Query(SQL)를 클릭하여 액세스
mm_events 사용 설정
mm_events를 사용 설정하려면 공급업체 init.rc에서 sysprop persist.mm_events.enabled=true를 설정합니다.
다음은 mm_events의 메모리와 CPU 공간을 줄이기 위한 것입니다.
mm-events ftrace 인스턴스는 CPU당 4KB 버퍼를 사용합니다.
kmem_activity 트리거는 분당 1회로 속도가 제한됩니다.
언제든지 mm-events 트레이스 세션 1개만 활성화될 수 있습니다.
맞춤설정
mm_events는 perfetto 트레이스 구성 파일을 사용하여 추적 세션 중에 캡처할 통계를 지정합니다.
/vendor/etc/mm_events.cfg에서 맞춤 Perfetto 트레이스 구성을 제공할 수 있습니다.
사용 가능한 트레이스 구성 필드에 관한 설명은 Perfetto 문서를 참고하세요.
샘플 트레이스 구성은 이 mm_events.cfg 예를 참고하세요.
메모리 압력으로 트리거되도록 트레이스 구성에 포함할 중요한 필드는 스니펫에 나와 있습니다.
# 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
}
}
이 구성에서 mm_events는 perfetto kmem_activity 트리거를 시작하고 Perfetto 트레이스 세션은 구성된 stop_delay_ms 기간 36,000ms(6분)가 종료될 때까지 vm_stats 및 ftrace 메모리 이벤트를 캡처합니다.
트리거 제한 시간은 큰 값(이 경우 1시간)으로 설정되며 mm_events config는 mm_events가 항상 사용 설정되도록 주기적으로 다시 설정됩니다. 그 결과 그림 1과 그림 2에 표시된 데이터 유형을 포함하는 버그 신고가 생성됩니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","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-07-27(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."]]