Monitoring internal flash storage allocation on Android is vital for application performance, storage quota enforcement, and system stability. When a device begins running low on disk space, the operating system executes aggressive cache eviction algorithms to prevent critical system services from halting. Historically, calculating the disk footprint of an installed package required recursively walking directory trees in user data partitions—a slow, I/O-intensive process that caused user interface stutters. Modern Android platforms implement the Storage Statistics subsystem, backed by the Linux kernel ext4/f2fs project quota feature. Using Android Debug Bridge (ADB), systems engineers and developers can query dumpsys storagestats to audit app code size, data footprints, and cache quotas in real time without filesystem crawling.
Architecture of the Storage Statistics Subsystem
The Android storage accounting architecture is anchored by the StorageStatsService and the StorageStatsManager system API. Instead of reading directory contents file-by-file, Android assigns unique Linux GIDs (Group IDs) and project quotas to each installed application UID upon package installation:
- Project Quotas: Supported on modern Linux filesystems (such as ext4 and f2fs with
PRJQUOTAenabled), project IDs track file sizes instantly in the filesystem superblock. When an app writes data to its private sandbox, the kernel increments the project quota counter automatically. - Categorised Footprints:
StorageStatsServiceseparates an application’s physical storage footprint into discrete buckets:App Bytes(APK binary, split APKs, and native libraries),Data Bytes(databases, SharedPreferences, and private internal files), andCache Bytes(temporary files and HTTP response caches). - Cache Quotas: Android assigns dynamic cache quotas to packages based on usage frequency. When the system faces low storage pressure, packages exceeding their allotted cache quota are prioritised for automated cache trimming.
Verifying ADB Connectivity and Service Registration
Connect your Android device to your computer via USB or wireless debugging and confirm authorization from your workstation terminal:
adb devices
Once the device reports an authorized status, verify that the storagestats system service is active and registered in the Service Manager:
adb shell service check storagestats
The system will return: Service storagestats: found. To confirm whether your device’s filesystem supports accelerated hardware project quotas, inspect the mount flags for the /data partition:
adb shell mount | grep " /data "
If the mount options include prjquota, Android utilizes fast kernel ioctl queries (FS_IOC_FSGETXATTR) rather than recursive directory traversal.
Dumping Complete Storage Statistics Diagnostics
To inspect the entire diagnostic state of the Storage Statistics service, invoke dumpsys targeting the service identifier:
adb shell dumpsys storagestats
The diagnostic output displays global storage volume metrics, per-user allocations, and recent cache calculation histories:
STORAGE STATS SERVICE (dumpsys storagestats)
Volume: /data (UUID: private)
Total Space: 114.8 GB
Free Space: 42.1 GB
User 0 Storage Overview:
Apps Code Size: 14.2 GB
Apps Data Size: 18.6 GB
Apps Cache Size: 4.1 GB
Recent Storage Queries:
Package: com.google.android.youtube (UID: 10182)
App Bytes: 128.4 MB
Data Bytes: 842.1 MB
Cache Bytes: 310.5 MB
Package: com.android.chrome (UID: 10094)
App Bytes: 210.8 MB
Data Bytes: 1.2 GB
Cache Bytes: 540.2 MB
Cache Quota Allocations:
Package: com.google.android.youtube: Quota=512.0 MB, Reserved=64.0 MB
Package: com.android.chrome: Quota=1024.0 MB, Reserved=128.0 MB
Querying Storage Footprints for Specific Packages
When profiling an application during development, examining its exact disk allocation allows developers to determine whether large footprints stem from uncompressed native libraries (App Bytes) or bloated SQLite/Room databases (Data Bytes).
To inspect storage metrics for an individual package, query dumpsys storagestats filtered by package name:
adb shell dumpsys storagestats | grep -A 8 "Package: com.example.targetapp"
Alternatively, invoke the package-specific storage query via cmd storagestats:
adb shell cmd storagestats query-stats package com.example.targetapp 0
Where 0 specifies the target User ID. The command returns the raw byte breakdown across code, data, and cache categories.
Auditing Dynamic Cache Quotas and Low Storage Trimming
Android dynamically allocates cache quotas to prevent background apps from consuming unlimited disk space with temporary data. Apps that are opened daily receive generous cache quotas, while infrequently used apps receive minimal allowances.
To inspect the allocated cache quota and reserved space for your application, execute:
adb shell cmd storagestats query-quota com.example.targetapp 0
If your application exceeds its allocated cache quota, the Android system server marks its cache directory (/data/data/com.example.targetapp/cache) as eligible for immediate automatic deletion as soon as system storage reaches the low_storage threshold.
Simulating Storage Pressure and Cache Eviction
To test whether your application gracefully handles automated cache clearing, you can simulate low storage conditions using ADB without having to fill the device with large files:
adb shell cmd devicestoragemonitor force-low-storage
While low storage is forced, monitor the storagestats dump to observe how the operating system trims excess cache bytes across over-quota applications:
adb shell dumpsys storagestats | grep -A 4 "Apps Cache Size"
Once testing is complete, restore the storage monitor to its normal automatic state:
adb shell cmd devicestoragemonitor reset-low-storage
Auditing storage statistics ensures that applications maintain clean data hygiene, prevent sudden storage exhaustion, and adhere to Android’s modern filesystem quota policies.