از 27 مارس 2025، توصیه می کنیم از android-latest-release
به جای aosp-main
برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
آمار ذخیره سازی سریعتر
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
در نسخههای قبلی اندروید، سیستم از تمام فایلهای متعلق به یک برنامه خاص برای اندازهگیری میزان مصرف دیسک عبور میکرد. محاسبه این اندازه گیری دستی قبل از نمایش نتایج به کاربران در تنظیمات ممکن است چند دقیقه طول بکشد.
علاوه بر این، الگوریتم داخلی برای پاک کردن فایلهای داده ذخیرهشده تنها در زمان تغییر یافته در همه برنامهها بررسی میشود. این به برنامههای مخرب اجازه میدهد تا با تنظیم زمانهای اصلاحشده در آینده بهطور ناعادلانه نسبت به سایر برنامهها، تجربه کلی کاربر را کاهش دهند.
برای بهبود این تجربیات، Android 8.0 پیشنهاد میکند از پشتیبانی «سهمیه» سیستم فایل ext4 برای بازگرداندن آمار استفاده از دیسک تقریباً فوری استفاده کند. این ویژگی سهمیه همچنین با جلوگیری از استفاده هر اپلیکیشنی از بیش از 90 درصد فضای دیسک یا 50 درصد اینودها، ثبات سیستم را بهبود می بخشد.
پیاده سازی
ویژگی سهمیه بخشی از اجرای پیش فرض installd
است. installd
به طور خودکار از ویژگی سهمیه زمانی که در یک فایل سیستم خاص فعال است استفاده می کند. هنگامی که ویژگی سهمیه در دستگاه بلوک در حال اندازه گیری فعال یا پشتیبانی نمی شود، سیستم به طور خودکار و شفاف محاسبه دستی را از سر می گیرد.
برای فعال کردن پشتیبانی سهمیه در یک دستگاه بلوک خاص:
- گزینه های
CONFIG_QUOTA
، CONFIG_QFMT_V2
، و CONFIG_QUOTACTL
هسته را فعال کنید. - گزینه
quota
به پارتیشن userdata خود در فایل fstab خود اضافه کنید:
/dev/block/platform/soc/624000.ufshc/by-name/userdata /data
ext4 noatime,nosuid,nodev,barrier=1,noauto_da_alloc
latemount,wait,check,formattable,fileencryption=ice,quota
گزینه fstab
را می توان با خیال راحت در دستگاه های موجود فعال یا غیرفعال کرد. در طول اولین بوت پس از تغییر گزینه fstab
، fsmgr
یک پاس fsck
را مجبور می کند تا تمام ساختارهای داده سهمیه را به روز کند، که ممکن است باعث شود که بوت اول کمی بیشتر طول بکشد. چکمه های بعدی تحت تأثیر قرار نمی گیرند.
پشتیبانی Quota فقط روی ext4 و Linux 3.18 یا بالاتر تست شده است. در صورت فعال کردن در سیستم های فایل دیگر یا نسخه های هسته قدیمی تر، تولیدکنندگان دستگاه مسئول آزمایش و بررسی صحت آمار هستند.
هیچ پشتیبانی سخت افزاری خاصی مورد نیاز نیست.
اعتبار سنجی
تستهای CTS تحت StorageHostTest
وجود دارد که APIهای عمومی را برای اندازهگیری استفاده از دیسک اعمال میکنند. انتظار می رود این APIها بدون توجه به فعال یا غیرفعال شدن پشتیبانی سهمیه، مقادیر صحیح را برگردانند.
اشکال زدایی
برنامه آزمایشی به دقت مناطق فضای دیسک را با استفاده از اعداد اول منحصر به فرد برای اندازه اختصاص می دهد. هنگام اشکالزدایی این تستها، از آن برای تعیین علت هر گونه اختلاف استفاده کنید. به عنوان مثال، اگر آزمایشی با دلتای 11 مگابایتی شکست خورد، روش Utils.useSpace()
را بررسی کنید تا ببینید که حباب 11 مگابایتی در getExternalCacheDir()
ذخیره شده است.
همچنین برخی از آزمایشهای داخلی وجود دارد که ممکن است برای اشکالزدایی مفید باشد، اما ممکن است برای انجام بررسیهای امنیتی غیرفعال شود:
runtest -x frameworks/base/services/tests/servicestests/ \
src/com/android/server/pm/InstallerTest.java
adb shell /data/nativetest64/installd_utils_test/installd_utils_test
adb shell /data/nativetest64/installd_cache_test/installd_cache_test
adb shell /data/nativetest64/installd_service_test/installd_service_test
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Faster storage statistics\n\nIn earlier versions of Android, the system traversed all files owned by a\nparticular app to measure disk usage. This manual measurement could take minutes\nto compute before displaying the results to users in Settings.\n\n\nIn addition, the internal algorithm to clear cached data files only looked at\nmodified time across all apps. This allowed malicious apps to degrade the\noverall user experience by setting modified times far in the future to unfairly\nfavor themselves over other apps.\n\n\nTo improve these experiences, Android 8.0 offers to leverage the ext4 filesystem's\n\"quota\" support to return disk usage statistics almost instantly. This quota\nfeature also improves system stability by preventing any single app from using\nmore than 90% of disk space or 50% of inodes.\n\nImplementation\n--------------\n\n\nThe quota feature is part of the default implementation of `installd`.\n`installd` automatically uses the quota feature when enabled on a\nparticular filesystem. The system automatically and transparently resumes\nmanual calculation when the quota feature isn't enabled or supported on the\nblock device being measured.\n\n\nTo enable quota support on a particular block device:\n\n1. Enable the `CONFIG_QUOTA`, `CONFIG_QFMT_V2`, and `CONFIG_QUOTACTL` kernel options.\n2. Add the `quota` option to your userdata partition in your fstab file: \n\n ```\n /dev/block/platform/soc/624000.ufshc/by-name/userdata /data\n ext4 noatime,nosuid,nodev,barrier=1,noauto_da_alloc\n latemount,wait,check,formattable,fileencryption=ice,quota\n ```\n\n\nThe `fstab` option can safely be enabled or disabled on existing\ndevices. During the first boot after changing the `fstab` option,\n`fsmgr` forces an `fsck` pass to update all quota data\nstructures, which may cause that first boot to take slightly longer. Subsequent\nboots will not be affected.\n\n\nQuota support has only been tested on ext4 and Linux 3.18 or higher. If enabling\non other filesystems, or on older kernel versions, device manufacturers are\nresponsible for testing and vetting for statistics correctness.\n\n\nNo special hardware support is required.\n\nValidation\n----------\n\n\nThere are CTS tests under `StorageHostTest`, which exercise public\nAPIs for measuring disk usage. These APIs are expected to return correct values\nregardless of quota support being enabled or disabled.\n\n### Debugging\n\n\nThe test app carefully allocates disk space regions using unique prime numbers\nfor the size. When debugging these tests, use this to determine the cause of any\ndiscrepancies. For example, if a test fails with a delta of 11MB, examine the\n`Utils.useSpace()` method to see that the 11MB blob was stored in\n`getExternalCacheDir()`.\n\n\nThere are also some internal tests that may be useful for debugging, but they\nmay require disabling security checks to pass: \n\n runtest -x frameworks/base/services/tests/servicestests/ \\\n src/com/android/server/pm/InstallerTest.java\n adb shell /data/nativetest64/installd_utils_test/installd_utils_test\n adb shell /data/nativetest64/installd_cache_test/installd_cache_test\n adb shell /data/nativetest64/installd_service_test/installd_service_test"]]