iPhone 闪存驱动器的寿命

发布于 2024-08-12 20:24:40 字数 988 浏览 13 评论 0原文

来自 iPhone 编程指南

创建文件或写出文件时 文件数据,保留以下内容 牢记指导原则:

  1. 尽量减少写入磁盘的数据量。文件操作相对较慢,并且涉及到闪存盘的写入,闪存盘的寿命有限。可帮助您最大程度地减少与文件相关的操作的一些具体提示包括:
    1. 仅写入文件中发生更改的部分,但尽可能汇总更改。
    2. 避免仅仅为了更改几个字节而写出整个文件。
    3. 定义文件格式时,将经常修改的内容分组在一起,以尽量减少每次需要写入磁盘的块总数。
    4. 如果您的数据包含随机访问的结构化内容,请将其存储在 Core Data 持久存储或 SQLite 数据库中。如果您正在处理的数据量可能会增长到超过几兆字节,这一点尤其重要。
  2. 避免将缓存文件写入磁盘。此规则的唯一例外是当您的应用程序退出时,您需要编写状态信息,以便在下次启动时将应用程序恢复到相同的状态。

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

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

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

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

From the iPhone Programming Guide

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.

I read an article a while back regarding intel SSDs (which I unfortunately can't find right now), which mentioned that the primary longevity concern was due to the fact that the OS didn't actually delete data, but just marked blocks as free, causing a rather painful slowdown when those 'free' blocks where written to (causing a read-modify-store, rather than just store). Does this hold for the iPhone as well, i.e. will the drive be more susceptible to slowdowns when files are deleted more frequently?

I'm considering a file format based on a redo-log, this way I can maintain a cross-session undo and I also have no random writes (always append), but at some point I suppose I'll have to consolidate at least a part of the log, to keep the file size at a reasonable level. My question in this case, which would be more efficient (in terms of drive longevity)? I have a couple of paths I've considered

  1. Overwrite the same file and
    1. truncate the space I don't need
    2. or leave that space (filled with old data) and overwrite it when I need it again
  2. or write a new file, and delete the old one

but I'm open to suggestions. I'm guessing the typical file size would range from a couple of kB to a couple of hundred kB, but the higher value is more speculation than anything else.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不美如何 2024-08-19 20:24:40

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

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

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

You don't have to worry about that particular issue. Like many embedded devices, the iPhone talks directly to the flash chips, using an interface similiar to what an SSD controller chip uses (something like ONFI). The FTL (flash translation layer) on the iPhone is software managed by the OS, which has full knowledge of what blocks are in use.

While Apple doesn't document this behavior, you can indirectly see evidence of it in the public xnu source code which (for quite some time) has has support in HFS+ to communicate to the block layer that particular blocks are no longer useful. No open source block device does anything with that info, but if you take a jailbroken iPhone and disassemble its kernel you will see it is used on the iPhone.

Obviously you should not try to depend on this behaviour, I'm just saying you don't need to worry, it does the right thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文