Commit graph

43 commits

Author SHA1 Message Date
Daeho Jeong
b868a88c1a Correct reserved blocks to segments
Align units to a segment unit when adjusting free segment number.

Test: run the smart idle maint service.
Change-Id: I4fd74ac92adc4ae1a0ded4a7df75a690d829eb20
Signed-off-by: Daeho Jeong <daehojeong@google.com>
2023-08-31 12:54:01 -07:00
Li Chong
5b224dc337 vold: fix idlemaint abort may hold the wakelock
when the idlemaint run is working, if two or more idlemaint abort concurrency are working.
all idlemaint abort will hold the wakelock, until idlemaint run finished,
but it just nofity one idlemaint abort thread to stop and release the wakelock.
Remaining idlemaint abort threads will hold the wakelock until next idlemaint run to notify them.

Bug: 292383791
Test: see the issue Description

Change-Id: I5312be2e0e92c41483cab26e627a4ae562e5aed8
2023-07-24 15:23:30 +08:00
Daeho Jeong
dd08c52eb8 vold: fix write kbytes handling
Since Android platform codespace doesn't support exception handling, we
use strtoll() instead of stoll for direct error handling.

Bug: 274369737
Test: check smart idle maintenace service log
Change-Id: I57c709b1e329228790e0a883edb64dc023135a24
2023-03-27 18:19:18 -07:00
Daeho Jeong
69754352bb Merge "Introduce target dirty segment ratio tunable parameter" am: c3a7391c94
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2135595

Change-Id: I42b8baffdfe9bea0d66d310952aa4c8403c36ad3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-14 15:13:20 +00:00
Daeho Jeong
fc5cdcf04a Merge "Make minimum gc sleep time tunnable" am: a5d927ba6a
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2132536

Change-Id: I3fc545927eeed476f75e5a72b373d5f6e4a92829
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-07 19:01:06 +00:00
Daeho Jeong
37cf9d79ab Introduce target dirty segment ratio tunable parameter
We introduce a new parameter of target dirty segment ratio,
which can be used to set a target dirty / (dirty + free) segments
ratio. For example, if we set this as 80%, GC sleep time will be
calculated to achieve this ratio in a GC period.

Test: check smart idle maint log of StorageManagerService
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: I73f2bcf4bdb810164c174bd0d2518b15d577d5d5
2022-07-04 21:23:46 +00:00
Daeho Jeong
3fd33ece35 Make minimum gc sleep time tunnable
Test: check smart idle maint log of StorageManagerService
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: I5a70e4ec2ca895551b6446a9dfd4bb5003a3fbd0
2022-06-23 16:20:45 -07:00
Daeho Jeong
d96b2ac076 Use sysfs control for storage device GC
Sometimes, waiting for the HAL makes infinite calls to HAL and ending
up with power consuming issues. While tracking the root cause, we will
temporally turn off HAL for storage device GC.

Bug: 235470321
Test: run "sm idle-maint run"
Ignore-AOSP-First: This is a temporal fix for Android TM devices.
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: Ieb371b7fdebfe938206a45547bb24dfbf2c2e7be
2022-06-17 23:31:35 +00:00
Daeho Jeong
7667d64ab8 vold: fix the range of stopped state of idleMaint
When it is stuck in runDevGC() for an unexpected reason, now it cannot
prevent the other callers from entering into it again. Fix it.

Bug: 232297944
Test: run "sm idle-maint run" twice & check whether they are overlapped
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: I785c8aeebd8fcf58c34d9be9968d99634d0b420a
Merged-In: I785c8aeebd8fcf58c34d9be9968d99634d0b420a
2022-05-18 16:29:46 -07:00
Daeho Jeong
372b3510b5 vold: fix the range of stopped state of idleMaint
When it is stuck in runDevGC() for an unexpected reason, now it cannot
prevent the other callers from entering into it again. Fix it.

Bug: 232297944
Test: run "sm idle-maint run" twice & check whether they are overlapped
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: I785c8aeebd8fcf58c34d9be9968d99634d0b420a
2022-05-18 09:03:15 -07:00
Daeho Jeong
3ccdeb3fbb vold: remove overprovision area from free segments
overprovision space and reserved area should be subtracted when we
calculate free segments count in GC for data blocks.

Test: check Vold setGCUrgentPace log
Bug: 202283480
Bug: 181079477
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: I7b749588ff794ff0429e17a787d83bcc19af0ec1
2022-03-25 10:06:13 -07:00
Daeho Jeong
0b5f397e2b vold: do not set gc sleep time with zero dirty segments
When there is not enough dirty segments to reclaim, we don't have to set
gc sleep time.

Test: Run smart idle maint with zero dirty segments
Bug: 202283480
Bug: 181079477
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: If6a9965ecb9b1a91bf5d0dd763d5fa0af63348e0
2022-03-18 21:30:47 -07:00
Daeho Jeong
7c788fc3e9 vold: add gc period in setGCUrgentPace
To make gc period changable, added a new gcPeriod parameter to
setGCUrgentPace.

Test: adb shell device_config put storage_native_boot smart_idle_maint_period 10
Bug: 202283480
Bug: 181079477
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: I4e44a80ea5b51d9a7cde69d25e129dd0673b271f
2022-03-18 12:56:17 -07:00
Daeho Jeong
5e879421a3 vold: switch f2fs gc_urgent_high to gc_urgent_mid
We need to reduce F2FS GC intensity for smart idle maintenance service
not to interfere with other I/O activities.

Test: check smart idle maintenance log every hour
Bug: 202283480
Bug: 181079477
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: Ideb1641a1539a23828bc8b00d9739c8128a984c0
2022-03-15 21:42:55 -07:00
Daeho Jeong
999fceb07c Add interfaces required by smart idle maintenance service
Added interfaces required by smart idle maintenance service in
StorageManagerService, whose goal is to determine when to trigger
filesystem defragmentation while keeping the best user experience
as long as possible, and avoiding hurting UFS lifetime.

Test: check smart idle maintenance log every hour
Bug: 202283480
Bug: 181079477
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Change-Id: I012cfb9b01e5d21ec71700c3c52ac9c096cd1a90
2022-01-12 10:54:37 -08:00
Kalesh Singh
98062dcd89 vold: Use Wakelock::tryGet()
Acquiring a wakelock can fail if the suspend service is unavailable.
Explicitly check that wakelock was acquired before performing
operations that require the device to stay on.

Bug: b/179229598
Test: Boot test on Pixel 4 device
Change-Id: If30087223e44098801a31d1bfd239ac22e891abe
2021-02-22 17:24:51 -05:00
Yifan Hong
e1e494519e Use AIDL HAL for Dev GC
Test: run idle maint
Bug: 177470478

Change-Id: Iefddf8628e31f020b86ff56dfb4926c2c9a2a888
2021-01-15 18:27:57 -08:00
Yifan Hong
8f0d45441c Refactor HIDL HAL Dev GC invocation
Prefix all HIDL HAL types with the letter H.
Also make the invocation more generic so that we can use
the AIDL implementation in the future.

Test: TH
Bug: 177470478

Change-Id: Iee0af9727c48c532315203c138a4996a08fcaa34
2021-01-15 18:27:57 -08:00
Eric Biggers
9a3dc8c709 IdleMaint: skip swap space, bind mounts, and virtual filesystems
When the idle maintenance task runs on Cuttlefish, there are several
warnings printed to logcat after the expected messages:

    D vold    : Starting trim of /data
    I vold    : Trimmed 0 bytes on /data in 36ms
    D vold    : Starting trim of /cache
    I vold    : Trimmed 58662912 bytes on /cache in 0ms
    D vold    : Starting trim of /metadata
    I vold    : Trimmed 7725056 bytes on /metadata in 12ms
    D vold    : Starting trim of none
    W vold    : Failed to open none: No such file or directory
    D vold    : Starting trim of /sdcard
    W vold    : Failed to open /sdcard: Not a directory
    D vold    : Starting trim of /mnt/vendor/shared
    W vold    : Trim failed on /mnt/vendor/shared: Inappropriate ioctl for device

This is because vold gathers the filesystems to trim from the fstab, but
it fails to exclude some entries that aren't appropriate to trim:

    /dev/block/zram0 none swap defaults zramsize=75%
    /tmp /sdcard none defaults,bind recoveryonly
    shared /mnt/vendor/shared virtiofs nosuid,nodev,noatime nofail

These should be excluded because they are swap space, a bind mount, and
a virtual filesystem respectively.

Fix addFromFstab() to exclude the above cases.

Afterwards, the messages on Cuttlefish are:

    D vold    : Starting trim of /data
    I vold    : Trimmed 0 bytes on /data in 39ms
    D vold    : Starting trim of /cache
    I vold    : Trimmed 58662912 bytes on /cache in 0ms
    D vold    : Starting trim of /metadata
    I vold    : Trimmed 9822208 bytes on /metadata in 12ms

Change-Id: Idc575106fe6f81c737f684429d58dba4bd5478ad
2020-10-15 16:56:16 -07:00
Eric Biggers
019d5163cc IdleMaint: use fstab_default from VoldUtil
vold already reads the default fstab into memory when starting up, and
the default fstab isn't allowed to change later.  So in IdleMaint.cpp,
just use 'fstab_default' instead of reading it again.

This also has the advantage that fstab entries for "logical partitions"
now get a properly updated blk_device, which is needed in order to start
using blk_device to exclude virtual filesystems in addFromFstab().

Change-Id: Id6457a2b7972d01dde4bca0c5f2da86374d930af
2020-10-15 16:54:38 -07:00
Tri Vo
a4a04f5717 Merge "vold: use RAII wake locks" am: b585363d93
am: 99fd2a4b5a

Change-Id: I8e37d315ecb6bad994d2a9c748cfc835756e265e
2019-06-26 19:43:21 -07:00
Tri Vo
15bbe22879 vold: use RAII wake locks
Prevents wake lock leaks, e.g. b/133175847

Bug: 133175847
Test: boot blueline
Change-Id: Icda4c81e00a61adec6a12c61c329867fef284dc5
2019-06-26 10:20:30 -07:00
Ruslan Tkhakokhov
0e2317857b Merge "Merged-In Revert "vold: use RAII wake locks"" am: 2ebb5c5b96
am: fce081efa6

Change-Id: If58a55eecb04453f69e51cdc242f5ab71fb7ddc1
2019-06-21 08:27:57 -07:00
Ruslan Tkhakokhov
a37c01756f Merged-In Revert "vold: use RAII wake locks"
This reverts commit 242130f3f8.

Reason for revert: breaks the build

Change-Id: Ide809a114b2a04538f3ba4ed8af934bf326e54f3
2019-06-21 10:33:30 +00:00
Tri Vo
c3d9197784 Merge "vold: use RAII wake locks" am: 798aa303da
am: 56c6681ba8

Change-Id: I3f87e1ad31701c24fdc426c3bd562a47871e3631
2019-06-20 15:57:53 -07:00
Tri Vo
242130f3f8 vold: use RAII wake locks
Prevents wake lock leaks, e.g. b/133175847

Bug: 133175847
Test: boot blueline
Change-Id: I62fd1c6c3abbfd35aebe11343abd717a7cf4eef7
2019-06-18 15:34:12 -07:00
Jaegeuk Kim
cd1f06f6ec Merge "idle-maint: don't need to change discard_granularity" am: 444a24558d am: a970ff8448
am: 240ca70d8d

Change-Id: I249d4dd70c4f13d46d539a769e918613eea539b4
2019-04-01 07:22:06 -07:00
Jaegeuk Kim
dc7162be6f idle-maint: don't need to change discard_granularity
F2FS changes proper configurations along with gc_urgent, so idle-maint doesn't
need to set this redundantly.

Change-Id: I4a71a5d877a3bb9636e2b65132ec806edc56a8fe
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2019-03-28 06:40:12 -07:00
Tom Cherry
1464410580 Merge "Move over to the C++ Fstab class" am: b6d5cd20d7 am: 4e8e70a949
am: f61f61a6a0

Change-Id: I90f0f0e1161463cef8542a586b53274ec5a2f5ee
2019-01-31 17:23:24 -08:00
Tom Cherry
4c5bde2b92 Move over to the C++ Fstab class
Test: build and boot
Change-Id: Id3850c9c133f6644073a2439368501253a2a94a9
2019-01-31 12:34:39 -08:00
Yifan Hong
15b9656ae9 Merge "health.filesystem HAL renamed to health.storage" 2018-09-20 17:26:53 +00:00
Paul Crowley
b2efa615db Merge "clang-format many files." am: a676df01e2 am: 957b9544dd
am: 8b2b67bc1e

Change-Id: Iad04e9517cd01e2ea13281b31e7b13ae75414d7e
2018-09-19 17:43:43 -07:00
Yifan Hong
91a68dfc98 health.filesystem HAL renamed to health.storage
Bug: 111655771
Test: compiles
Change-Id: Ibfcab4d116d735ba2f80a8b0ead314138a7ba23d
Merged-In: Ibfcab4d116d735ba2f80a8b0ead314138a7ba23d
2018-09-19 13:11:50 -07:00
Yifan Hong
7a37c93825 health.filesystem HAL renamed to health.storage
Bug: 111655771
Test: compiles
Change-Id: Ibfcab4d116d735ba2f80a8b0ead314138a7ba23d
2018-09-19 10:28:16 -07:00
Paul Crowley
14c8c0765a clang-format many files.
Test: Format-only changes; treehugger suffices.
Change-Id: I23cde3f0bbcac13bef555d13514e922c79d5ad48
2018-09-18 15:41:22 -07:00
Jaegeuk Kim
1251ef0bcf vold: metadata encryption: ensure F2FS GC targets correct device.
This fixes F2FS GC failure in idle-maint.

Bug: 111953875
Change-Id: I1d10802121d5641cf9ba780fee249affd2cf6ffe
Merged-In: I1d10802121d5641cf9ba780fee249affd2cf6ffe
Test: Tested by hand
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-09-18 13:14:34 -07:00
Yifan Hong
b85bcf9fcd Merge "vold uses health filesystem HAL" am: fa96af82f3
am: def8ce02b6

Change-Id: I74bcb1519d1bc2d62bdf018a9ed7068c6dfdfbfe
2018-09-17 16:01:36 -07:00
Yifan Hong
024a1241a6 vold uses health filesystem HAL
to runDevGc(). This fixes a Treble violation.
Bug: 111655771
Test: manual

Change-Id: I53d6db6ffa99e43e281f8086442151692c1826ca
2018-09-17 10:06:57 -07:00
Jaegeuk Kim
31e962fe19 vold: meta encryption: fix /dev/block/by-name/userdata to dm-3
This fixes F2FS GC failure in idle-maint.
07-28 18:25:54.838   603 11187 D vold    : idle maintenance started
07-28 18:25:54.846   603 11187 D vold    : Start GC on /sys/fs/f2fs/sda21
07-28 18:25:54.847   603 11187 W vold    : Set discard gralunarity failed on/sys/fs/f2fs/sda21: No such file or directory
07-28 18:25:54.847   603 11187 W vold    : Start GC failed on /sys/fs/f2fs/sda21: No such file or directory

Bug: 111953875
Change-Id: I1d10802121d5641cf9ba780fee249affd2cf6ffe
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-07-29 18:22:47 -07:00
Jaegeuk Kim
eefc5eebc3 vold: Idle-maint calls device GC
This activates device GCs in idle time.

F2FS GC = 7 mins
Trim = 1 mins
Dev GC = 2 mins

Bug: 63264275
Bug: 68721792
Change-Id: I843a742ef192ebe00d77c47a216d4200bc9ccb9d
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-04-16 09:54:41 -07:00
Jaegeuk Kim
a6aae2f5a5 vold: Idle-maint issues discards fully
Change-Id: Ib20a55e8761aa740b530803f029ecb36256fe9aa
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-02-22 19:06:24 -08:00
Jin Qian
a370c14f75 Add functions to handle idle maintenance
runIdleMaint is equivalent with:

1. echo 1 > /sys/fs/f2fs/sdX/gc_urgent
2. wait until /sys/fs/f2fs/sdX/dirty_segments
     <= threshold or timeout
3. echo 0 > /sys/fs/f2fs/sdX/gc_urgent
4. fstrim

abortIdleMaint forces the wait loop above to exit and
skips fstrim. However, if fstrim is already running,
abortIdleMaint will just leave it run to completion.

Test: adb shell sm idle-maint [run|abort]
Bug: 67776637
Change-Id: I4adff8d9b6bbd63bce41368cea55dc9e9b117eb6
2017-11-14 15:12:30 -08:00
Jeff Sharkey
01a0e7fa18 Fix task memory leaks; better path validation.
We've been allocating task objects without freeing them, oops.  We
don't really need full classes for these tasks, so move them to
blocking methods, and invoke them from a detached thread.

Remove FIDTRIM support, which isn't meaningful on UFS-based flash
devices.  Modern devices require FBE/FDE which gives us better
protection against trimmed data lingering around.

Rename "Trim" to more generic "IdleMaint", since it'll soon extend
to include custom F2FS optimization logic.

Check for shady ".." when validating paths.

Test: cts-tradefed run commandAndExit cts-dev -m CtsOsTestCases -t android.os.storage.cts.StorageManagerTest
Test: cts-tradefed run commandAndExit cts-dev --abi armeabi-v7a -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AdoptableHostTest
Bug: 67041047
Change-Id: I4fb194c5d5ef13f413c02acedfbaaf79c567582b
2017-10-18 11:44:57 -06:00
Renamed from TrimTask.cpp (Browse further)