實施儲存

Android O 增加了對storaged的支持,storaged 是一個 Android 原生守護進程,用於收集和發布 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 使用量。

Diskstat(包括停止的 diskstats)和 eMMC 資訊記錄到 Android 事件日誌中,平台簽入服務在其中收集日誌。

storaged操作會自動發生,並完全由 Android 框架處理,因此您無需執行任何實作工作。本頁描述了storaged的設計(包括新介面)以及如何使用它從核心獲取 I/O 狀態。

儲存設計

為了會計和權限靈活性, storaged被實作為一個核心模組,傳回每個 uid 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 使用情況,請使用帶有-u選項的storaged命令。

命令: 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