gpt4 book ai didi

iphone - iPhone 闪存驱动器的生命周期

转载 作者:行者123 更新时间:2023-12-03 21:12:56 26 4
gpt4 key购买 nike

来自 iPhone 编程指南

When creating files or writing out file data, keep the following guidelines in mind:

  1. Minimize the amount of data you write to the disk. File operations are relatively slow and involve writing to the Flash disk, which has a limited lifespan. Some specific tips to help you minimize file-related operations include:
    1. Write only the portions of the file that changed, but aggregate changes when you can.
    2. Avoid writing out the entire file just to change a few bytes.
    3. When defining your file format, group frequently modified content together so as to minimize the overall number of blocks that need to be written to disk each time.
    4. If your data consists of structured content that is randomly accessed, store it in a Core Data persistent store or a SQLite database. This is especially important if the amount of data you are manipulating could grow to be more than a few megabytes in size.
  2. Avoid writing cache files to disk. The only exception to this rule is when your application quits and you need to write state information that can be used to put your application back into the same state when it is next launched.

我不久前读过一篇关于英特尔SSD的文章(不幸的是我现在找不到),其中提到主要的生命周期问题是由于操作系统实际上并没有删除数据,而只是标记了数据 block 为空闲 block ,当写入这些“空闲” block 时,会导致相当痛苦的速度减慢(导致读取-修改-存储,而不仅仅是存储)。这是否也适用于 iPhone,即当文件删除更频繁时,驱动器是否会更容易受到减速的影响?

我正在考虑基于重做日志的文件格式,这样我可以维护跨 session 撤消,并且我也没有随机写入(始终附加),但在某些时候我想我必须这样做合并至少一部分日志,以将文件大小保持在合理的水平。在这种情况下我的问题是,哪种方法更有效(就驱动器生命周期而言)?我考虑过几条路

  1. 覆盖同一个文件并
    1. 截断我不需要的空间
    2. 或者保留该空间(填充旧数据)并在我再次需要时覆盖它
  2. 或者写入一个新文件,并删除旧文件

但我愿意接受建议。我猜测典型的文件大小范围从几 kB 到几百 kB,但更高的值更多的是猜测。

最佳答案

您不必担心这个特定问题。与许多嵌入式设备一样,iPhone 使用类似于 SSD Controller 芯片的接口(interface)(类似于 ONFI)直接与闪存芯片通信。 iPhone 上的 FTL(闪存翻译层)是由操作系统管理的软件,操作系统完全了解正在使用的 block 。

虽然 Apple 没有记录此行为,但您可以在公共(public) xnu 源代码中间接看到它的证据,该源代码(在相当长一段时间内)在 HFS+ 中支持与 block 层通信特定 block 不再有用。没有任何开源 block 设备会对这些信息执行任何操作,但是如果您使用越狱的 iPhone 并反汇编其内核,您将看到它在 iPhone 上使用。

显然你不应该尝试依赖这种行为,我只是说你不需要担心,它做了正确的事情。

关于iphone - iPhone 闪存驱动器的生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1818934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com