自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
實作儲存空間
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 8 新增了對 storaged
的支援,這是 Android 原生 Daemon,可在 Android 裝置上收集及發布儲存空間指標。
- 針對每日磁碟狀態,
storaged
會定期剖析 /sys/block/mmcblk0/stat
(eMMC 儲存裝置) 或 /sys/block/sda/stat
(非 eMMC 裝置)。
- 針對 eMMC 壽命,
storaged
會剖析 /d/mmc0/mmc0:001/ext_csd
(如有)。
- 針對應用程式 I/O 歸咎,
storaged
會定期遍歷 /proc/uid_io/stats
,並維護已剖析的資料,包括來自所有應用程式 (而非僅限於執行中的應用程式) 的資料。dumpsys
可以呼叫 storaged
,在錯誤報告中記錄應用程式 I/O 用量。
磁碟狀態 (包括停止的磁碟狀態) 和 eMMC 資訊會記錄到 Android 事件記錄檔,平台簽入服務會收集這些記錄。
storaged
作業會自動執行,且完全由 Android 架構處理,因此您不必執行任何實作工作。本頁說明 storaged
的設計 (包括新的介面),以及如何使用該設計從核心取得 I/O 狀態。
儲存設計
為了提供彈性的記錄和權限功能,storaged
會以核心模組的形式實作,以便傳回個別使用者 ID 的 I/O 資訊 (而非使用標準 proc/PID/io
)。每個 I/O 要求的原始 I/O 資料會繼續儲存在核心 task_struct
中並進行更新,而核心會持續追蹤程序結束的時間,以免錯過上次 storaged
輪詢事件發生的 I/O 用量。
只有在架構通知模組關於 uid 的前景/背景切換,或是 storaged
守護程序要求報告時,模組才會讀取原始資料並加以處理。屆時,模組會從核心匯出檔案節點,以便與架構和 storaged
守護程序進行通訊。
storaged
會導入 /proc/uid_io/stats
介面,傳回系統中每個 UID 的 I/O 統計資料清單。格式如下:
<uid>: <foreground read bytes> <foreground write bytes> <foreground read chars> <foreground write chars> <background read bytes> <background write bytes> <background read chars> <background write chars>
- 讀取/寫入位元組是儲存裝置的 I/O 事件。
- 讀取/寫入字元 (也以位元組為單位) 是讀取/寫入系統呼叫要求的資料。
從核心取得 I/O 狀態
如要從核心傾印 I/O 用量,請使用 storaged
指令搭配 -u
選項。
指令:storaged -u
指令輸出格式:name/uid fg_rchar fg_wchar fg_rbytes fg_wbytes
bg_rchar bg_wchar bg_rbytes bg_wbytes fg_fsync bg_fsync
注意:這個輸出結果與 proc/uid_io/stats
的輸出結果類似。這是因為 storaged
會處理 /proc/uid_io/stats
的資料,並產生自己的資料。
輸出內容範例:
com.google.android.backuptransport 2269 60 0 0 1719845663 143912573 149065728 184180736
com.android.vending 2170 60 0 0 219904796 38693092 174436352 18944000
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[],[],null,["# Implement storaged\n\nAndroid 8 adds support for `storaged`, an Android native daemon that\ncollects and publishes storage metrics on Android devices.\n\n- For daily diskstats, `storaged` periodically parses `/sys/block/mmcblk0/stat` (eMMC storage devices) or `/sys/block/sda/stat` (non-eMMC devices).\n- For eMMC lifetime, `storaged` parses `/d/mmc0/mmc0:001/ext_csd` (if available).\n- For app I/O blaming, `storaged` periodically traverses `/proc/uid_io/stats` and maintains parsed data, which includes data from all apps (not just running apps). `dumpsys` can call `storaged` to log the app I/O usage in a bug report.\n\nDiskstat (including stalled diskstats) and eMMC information is logged to the\nAndroid event log, where a platform checkin service collects the logs.\n\n`storaged` operations occur automatically and are handled entirely by the Android\nframework, so you don't need to do any implementation work. This page\ndescribes the design of `storaged` (including new interfaces) and how to use it to\nget I/O status from the kernel.\n\nstoraged design\n---------------\n\nFor accounting and permission flexibility, `storaged` is implemented as a kernel\nmodule that returns per-uid I/O information (instead of using standard\n`proc/PID/io`). Raw I/O data for each I/O request continues to be\nstored and updated in kernel `task_struct`, and the kernel keeps\ntrack of when a process exits so it doesn't miss I/O usage that occurs from the\nlast `storaged` polling event.\n\nThe module reads raw data and processes it only when the framework notifies it\nof a uid foreground/background switch or when the `storaged` daemon requests a\nreport. At that time, the module exports a file node from kernel for\ncommunication with framework and `storaged` daemon.\n\n`storaged` introduces the `/proc/uid_io/stats` interface, which returns\na list of I/O stats for each UID in the system. The format is: \n\n```\n\u003cuid\u003e: \u003cforeground read bytes\u003e \u003cforeground write bytes\u003e \u003cforeground read chars\u003e \u003cforeground write chars\u003e \u003cbackground read bytes\u003e \u003cbackground write bytes\u003e \u003cbackground read chars\u003e \u003cbackground write chars\u003e\n```\n\n- read/write bytes are I/O events from a storage device.\n- read/write chars (also in bytes) are data requested by read/write syscalls.\n\nGet I/O status from the kernel\n------------------------------\n\nTo dump I/O usage from the kernel, use the `storaged` command with\nthe **`-u`** option.\n\nCommand: `storaged -u`\n\nCommand output format: `name/uid fg_rchar fg_wchar fg_rbytes fg_wbytes\nbg_rchar bg_wchar bg_rbytes bg_wbytes fg_fsync bg_fsync`\n\n**Note:** This output is similar to the output for\n`proc/uid_io/stats`. This is because `storaged` processes data from\n`/proc/uid_io/stats` and generates its own data.\n\nExample output: \n\n```\ncom.google.android.backuptransport 2269 60 0 0 1719845663 143912573 149065728 184180736\ncom.android.vending 2170 60 0 0 219904796 38693092 174436352 18944000\n```"]]