什么时候应该fstrim运行? -- cyanogenmod 领域 和 file-system 领域 和 lagging 领域 和 maintenance 领域 android 相关 的问题

When should fstrim run?



基于这个 cyanogenmod论坛线程,我尝试过通过手动运行FSTIM运行FSTIM,解决CyanogenMod运行CyanogenMod的Galaxy Nexus的应用程序之间的延迟。
  root@maguro:/ # fstrim -v /data                                                           /data: 11649122304 bytes trimmed                                                          root@maguro:/ # fstrim -v /cache                                                          /cache: 436121600 bytes trimmed                                                           root@maguro:/ # fstrim -v /system                                                         /system: 80490496 bytes trimmed root@maguro:/ # exit   




Based on this cyanogenmod forum thread, I tried to address the delay in running applications and switching between applications on my Galaxy Nexus running cyanogenmod with Android 4.4.4 by running fstrim manually.

root@maguro:/ # fstrim -v /data                                                           /data: 11649122304 bytes trimmed                                                          root@maguro:/ # fstrim -v /cache                                                          /cache: 436121600 bytes trimmed                                                           root@maguro:/ # fstrim -v /system                                                         /system: 80490496 bytes trimmed root@maguro:/ # exit 

This has largely fixed the delay issues. The delay to return to the home screen, for example, has reduced from about 4 seconds to less than 1 second. Based on this performance boost, I expect the delay was caused by the filesystem running inefficiently.

Isn't the Android OS supposed to run fstrim on its own? When is this supposed to happen?




文章< / a>在@ mattm 答案有点过时。 IdleMaintenanceService 在棒棒糖中删除,事情已更改。在馅饼上,计划 fstrim 是从 StorageManagerService ( 1 ) MountService ( 2 )

如果设备在 午夜+空闲 ,Fstrim会在下一个可用的 充电+空闲 时间

*( 3 )
挂载服务 StorageManager ,又调用 Vold fstrim

如果未遗漏计划,因为条件不符合,而 fstrim 尚未运行最后 3 days ( 4 ),如果重新启动设备,将在设备启动期间强制。 SystemServer ( 5 ) fstrim0 ( 6 ) fstrim1 ( 7 ) fstrim2 ( 8 )涉及

在每种情况下,文件 fstrim3 ( 9 )(自棒棒糖)得到更新(<一个href ="https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-9.0.0_r42/services/core/java/com/android/server/storagemanagerservice.java#581" rel ="nofollow noreferrer" > 10 ),因此您可以检查其时间戳(需要root ),以查找 fstrim4 最后运行时。

如果要做 abcdefghijklmn15 手动,请使用Android的Commandline工具 fstrim6 (需要root或 fstrim7 ) 。此前这是 fstrim8 ,但添加到oreo 的Storage Manager( 11 )并从 fstrim9 中删除饼( 12 。

要将 StorageManagerService0 发送到所选文件系统,请使用 StorageManagerService1 工具(需要root ); 一个BusyBox applet。

并且您怀疑预定的 StorageManagerService2 被遗漏了3天,重新启动de 冰, StorageManagerService3 将被强制(自洛根脂5.1 ( 13 ))。简单。



闪存(包括SSD,EMMC,SD卡,USB棒等)在它之前具有有限数量的程序/擦除周期。但与HDD不同,数据不能刚刚在闪存上覆盖,必须首先删除,这通过 StorageManagerService4 实现。

现在如果我们做太多 StorageManagerService5 ,这将导致频繁的gc在后台消耗珍贵 StorageManagerService6 周期,因此减少了生命。如果我们不做 StorageManagerService7 完全,可能有不必要的gc(已经删除的数据),加上写操作将与时间太慢,因为 StorageManagerService8 将有要在覆盖数据之前执行,与 StorageManagerService9 操作相比具有非常高延迟的延迟。


还有其他因素例如。 emmc控制器是否支持 MountService0 ,它在后台GC调度,磨损调平和管理写入放大等有效性如何。

所以除非您的手机emmc的数据表而且您确信您正在进行的内容,更好就是将 MountService1 留给操作系统。在PC上的( 14 )

频繁地运行fstrim,甚至使用 MountService2 ,可能会对劣质SSD设备的寿命产生负面影响。对于大多数桌面和服务器系统,足够的修剪频率为<强> 每周一次



  • SSDS的编码
  • 为什么不支持加密的"/ data" 分区?


The article referenced in @mattm's answer is a bit outdated. IdleMaintenanceService was removed in Lollipop, things have changed. On Pie, scheduled fstrim is triggered from StorageManagerService (1) to MountService (2):

if the device is alive at midnight + idle, fstrim gets run at the next available charging + idle time

* (3)
Mount service calls StorageManager which in turn calls Vold to do fstrim.

If the schedule is being missed because the conditions don't meet and fstrim has not run for last 3 days (4), it will be forced during device startup if the device is restarted. SystemServer (5), PackageManager (6), StorageManager (7) and Vold (8) are involved.

In each case, the file /data/system/last-fstrim (9) (since Lollipop) gets updated (10), so you can check its timestamp (requires root) to find out when fstrim was last run.

If you want to do TRIM manually, use Android's commandline tool sm fstrim (requires root or adb shell). Previously this was vdc fstrim dotrim but added to Storage Manager in Oreo (11) and removed from vold in Pie (12).

In order to send FITRIM ioctl to selected filesystem(s) only, use fstrim tool (requires root); a busybox applet.

What if you don't have root?
And you suspect that the scheduled fstrim is being missed for 3+ days, restart device, fstrim will be forced (since Lollipop 5.1 (13)). Simple.

Apps can't TRIM without root; see this answer.


Flash memory (including SSDs, eMMCs, SD Cards, USB sticks etc.) has limited number of Program/Erase cycles before it dies. But unlike HDDs, data can't be just overwritten on flash memory, it has to be Erased first, which is achieved through Garbage Collection.

Now if we do too much fstrim, this will cause frequent GC in background consuming precious P/E cycles and hence reducing life. If we don't do fstrim at all, there could be unnecessary GC (of already deleted data), plus the write operations will get too slow with time because Erase will have to be performed before overwriting data, which has very higher latency as compared to Program operation.

So we need a balance between both.

Also there are other factors e.g. whether eMMC controller supports over provisioning, how effective it is in background GC scheduling, wear-leveling and managing write amplification etc.

So unless you have the data sheet of your phone's eMMC and you are sure what you are doing, better is to leave the fstrim to OS. On PCs' (14):

Running fstrim frequently, or even using mount -o discard, might negatively affect the lifetime of poor-quality SSD devices. For most desktop and server systems a sufficient trimming frequency is once a week.

But this may vary with situations.


  • Coding for SSDs
  • Why is TRIM not supported on encrypted xe2x80x9c/dataxe2x80x9d partition?

unforgettableId的注释包括一个 Anandtech文章描述了FSTRIM应该运行的条件:

我在Android 4.3将修剪文件系统的底层时,我学习了更多的条件,因为之前没有完全清除。 Android框架将发送"启动空闲维护窗口" 事件,即MountService侦听,然后在满足一些条件时调用VOLD到FSTRIM文件系统 - 设备尚未触及一小时,没有空闲维护窗口事件已在24小时内发送,该设备是带有80%电池或带30%电池的充电器的卸载机。如果您养成每晚充电的习惯,目标是每24小时大致每24小时运行Fstrim。


Unforgettableid's comment included an AnandTech article that describes the conditions under which fstrim is supposed to run:

Ixe2x80x99ve learned a bit more on the conditions underlying when Android 4.3 will TRIM filesystems, as it wasnxe2x80x99t completely clear before. The Android framework will send out a xe2x80x9cstart idle maintenance windowxe2x80x9d event that the MountService listens for, and then invokes vold to fstrim filesystems when a few conditions have been met xe2x80x93 the device hasnxe2x80x99t been touched for over an hour, no idle maintenance window event has been sent in 24 hours, and the device is either off-charger with 80% battery or on-charger with 30% battery. The goal is to have fstrim run roughly once every 24 hours if youxe2x80x99re in the habit of plugging the device in to charge every night.


通过mattm答案表示条件下, fstrim 应该运行。我不知道该行为是否在随后的Android版本中发生了变化,但我遇到了一个应用程序,该应用程序会在Reboot 上的需求中执行 fstrim 。根必需。分享此信息,因为它可能对那些不是Linux Savvy的人有用(如我:)

ssd boost

Android 4.3+支持修剪此原理,这意味着删除文件后的操作系统将向NAND控制器发送Trim命令通知Witch块使用的文件使用,控制器将在空闲时删除它们,因此它可以在不擦除下次时写入。


'ssd boost'可帮助您手动在您的设备上运行修剪,如果您觉得它已成为滞后,无论如何它都会在每次重新启动时为您修剪。



Answer by mattm indicates conditions under which, fstrim should run. I am not aware if the behaviour has changed in subsequent Android versions, but I came across an app that does fstrim on demand as also on reboot . Root needed. Sharing this information as it may be useful to those who are not Linux savvy ( like me :)

SSD Boost

Android 4.3+ supports trim natively, it means that operating system after deleting a file will sends a trim command to nand controller notifying witch blocks the file used, the controller will erase them when idle so it can write fast without erasing next time.

But users have no control over this process and Android doesn't trim the storage for a very long time.

'SSD Boost' helps you to run trim on your device manually if you feel it has become laggy and anyway it does trim for you on every reboot.

I know this directly doesn't answer the question, but felt this was the best question on site to share this



4  我应该在我的可移动microSD卡上运行一致性检查吗?  ( When should i run a consistency check on my removable microsd card ) 
我拥有一个带有可移动MicroSD卡的Android设备。该卡使用FAT32或EXFAT技术。这些是"非日记文件系统" 技术,因此在某些情况下,卡上的数据可能会损坏。 也许我应该经常运行一致性检查(例如 abcdefghijklmnfsck / chkdsk / scandisk)。 a)我应该多久在MicroS...

1  这个应用程序承诺在没有root的情况下运行“fstrim”,但我不确定它是否有效  ( This app promises to run fstrim without root but i am not sure if it works ) 
我不确定是否这个app 作品。有人可以帮帮我吗?我的手机是新的,并在其保修期内,所以我无法授予它。我尝试了这个应用,但我不确定它真的做了什么。与 fstrim 的其他着名应用程序不同,它不需要root访问它非常令人难以置信。 ...

2  为什么加密“/ data”分区不支持修剪?  ( Why is trim not supported on encrypted data partition ) 
我有一个rooted Lenovo A369i 。我使用 LagFix (fstrim) 来修剪分区。以前,它与 /data 相处很好,但我加密了我的手机后它没有。通过格式化,我解密了手机。但现在在应用程序中,它显示 /data 分区具有内核或硬件问题。它不是硬件,因为在加密之前它运作良好。 ...

1  如何强迫Android设备上的修剪?  ( How to force trim on android device ) 
使用4.3启用TRIM的支持(虽然我读取自第一个jb以来存在它)。我想知道是否有办法让我强迫我的设备上修剪?有一个应用程序我可以侧行,并解决它吗?我有一个植根于4.2.2果冻发布的中国平板电脑。 只是为了添加,它是一个pipo m1 max平板电脑。 ...

1  定期文件系统一致性检查可能是一个好主意。当前的Android设备是否曾经做过?  ( Periodic filesystem consistency checks are probably a good idea do current andr ) 
让我首先给你一些一般的背景信息。我的实际问题位于这篇文章的底部。 背景,第1部分:期刊重播与一致性检查。 请假设您的Android设备使用ext4文件系统进行其内部存储,以及用于其可移动MicroSD存储的FAT32文件系统(如果存在)。 在ext4上,"Journal Replay" 是一个部分文件系统检查操作,...

3  如何修改我的Android设备?  ( How do i defrag my android device ) 
我在网上看到了一些应用程序,但他们似乎没有合法。从我所看到的,他们似乎并不展示驱动器碎片整理的时候发生了什么。所以我决定远离Google Play商店的碎片整理者。 如何为我的手机的SD卡和内部存储换句话是一种有效的方法? ...

4  什么时候应该fstrim运行?  ( When should fstrim run ) 
基于这个 cyanogenmod论坛线程,我尝试过通过手动运行FSTIM运行FSTIM,解决CyanogenMod运行CyanogenMod的Galaxy Nexus的应用程序之间的延迟。 root@maguro:/ # fstrim -v /data ...

5  如何删除应用程序创建的未使用的文件夹?  ( How to remove unused folders created by apps ) 
当我开始使用一个新鲜的SD卡时,它只有很少的文件夹。随着时间的推移,当我尝试了许多应用程序时,我可以看到我的SD卡中的文件夹列表似乎成长。 是可以理解的,而在卸载应用程序时,它将在其文件夹后面留下,其中它将保持少量文件,这可能是设置文件或游戏分数等。 是否有任何方法我可以在批量或短期操作中删除所有这些孤立文件夹?我...

3  如何清除先前ROM的旧应用文件夹?  ( How to clean up old application folders from prior rom ) 
我在gs2上安装了cm10,在此过程中我没有格式化文件系统,因为我想要在设备上保留我的照片和音乐。我知道一个名为"SD MAI" 的应用程序,它是支持的能够能够清除所有这些旧的应用文件夹,但它似乎没有工作。有谁知道如何清理所有这些文件夹,或者一个人必须进入并手动删除它们的所有文件夹吗? (对于一个应用程序来做这件事,...

3  您是否需要在Android上运行卸载程序/清洁器以维护Windows上的性能水平?  ( Do you need to run uninstallers cleaners on android to maintain performance leve ) 
你必须原谅我,因为我并不像Android / Linux的内部工作一样熟悉我的Windows。 我很奇怪关于在没有更好的术语,维护的情况下对Android设备进行性能下降。当我尝试一堆应用程序然后卸载它们时,我是否需要运行任何类型的清理?我知道Android没有像Windows这样的注册表,但它有没有的操作系​​统的...

© 2022 it.wenda123.org All Rights Reserved. 问答之家 版权所有