ntfs-3g `big_writes` 挂载选项的缺点

Tom*_*ale 8 linux ntfs ntfs-3g

man ntfs-3g使big_writes挂载选项看起来像是一件好事:

   big_writes
          This option prevents fuse from splitting write buffers into 4K
          chunks, enabling big write buffers to be transferred from the
          application in a single step (up to some system limit, generally
          128K bytes).
Run Code Online (Sandbox Code Playgroud)

没有列出缺点......我什么时候想避免安装 big_writes

Min*_*ang 7

这是个好问题,真的。从我在这里看到的情况来看,它可能没有缺点。

早在 2008big_writes首次添加到 FUSE 时, Miklos 说:

在 2.6.26 之前,fuse 仅支持单页写入请求。理论上,所有熔断器文件系统都应该能够支持大于 4k 的写入,因为 API 中没有任何内容可以阻止它。 不幸的是,NTFS-3G 中有一个已知的案例,其中大量写入会导致文件系统损坏。 也可能存在其他文件系统,如果缺少对大写请求的测试会导致错误。

为了防止内核升级时出现此类问题,默认情况下禁用大写,但让文件系统设置一个标志以将其打开。

具体问题在 NTFS-3G 中记录param.h为:

/*
 *        Use of big write buffers
 *
 *    With small volumes, the cluster allocator may fail to allocate
 *    enough clusters when the volume is nearly full. At most a run
 *    can be allocated per bitmap chunk. So, there is a danger when the
 *    number of chunks (capacity/(32768*clsiz)) is less than the number
 *    of clusters in the biggest write buffer (131072/clsiz). Hence
 *    a safe minimal capacity is 4GB
 */

#define SAFE_CAPACITY_FOR_BIG_WRITES 0x100000000LL
Run Code Online (Sandbox Code Playgroud)

目前它确实通过在请求 big_writes 之前验证 fs 容量至少为 4GB 来抵御此限制。所以它是安全的。

事实上,如果 NTFS-3G 占用您的 CPU ,Tuxera建议将其打开

解决方法:使用挂载选项“big_writes”通常会降低 CPU 使用率,前提是请求写入的软件支持大块。

未来

由于libfuse 3.0.0 (2016)big_writes始终处于开启状态:

-o big_writes安装选项已被删除。它现在始终处于活动状态。想要限制写入请求大小的文件系统应该使用该-o max_write=<N>选项。犯罪

但是,libfuse3 是全新的一代,ntfs-3g 根本不支持针对它进行构建。我无意中将新的 1MiB 写入缓冲区(libfuse 3.6.0)反向移植到 ntfs-3g 的内部 mini libfuse2,所以如果你想使用它,你可以从这里获取它:

  1. https://github.com/AOSC-Dev/ntfs-3g/commit/96f6fbedaf7aad70b4a4c39d8dd4a637a63beec1
  2. https://github.com/AOSC-Dev/ntfs-3g/commit/6aa576ae2a13fb636bff65bcb2701e731d2f5a94

是的,我确实记得重构写入大小/卷大小限制。是的,即使在现代 Ryzen 上写入大文件也更快。

PS:我计划为 ntfs-3g 添加 libfuse3 支持,但它没有真正的截止日期。Tuxera 显然对这种变化不感兴趣,想出一个 fork 的名字对我来说有点太多了。