cp --sparse = always有什么缺点吗?


10

是否有任何理由在每次调用时都不使用use ?--sparse=alwayscp

info cp 说:

‘--sparse=WHEN’
     A “sparse file” contains “holes”—a sequence of zero bytes that does
     not occupy any physical disk blocks; the ‘read’ system call reads
     these as zeros.  This can both save considerable disk space and
     increase speed, since many binary files contain lots of consecutive
     zero bytes.  By default, ‘cp’ detects holes in input source files
     via a crude heuristic and makes the corresponding output file
     sparse as well.  Only regular files may be sparse.

    The WHEN value can be one of the following:

...

    ‘always’
          For each sufficiently long sequence of zero bytes in the input
          file, attempt to create a corresponding hole in the output
          file, even if the input file does not appear to be sparse.
          This is useful when the input file resides on a file system
          that does not support sparse files (for example, ‘efs’ file
          systems in SGI IRIX 5.3 and earlier), but the output file is
          on a type of file system that does support them.  Holes may be
          created only in regular files, so if the destination file is
          of some other type, ‘cp’ does not even try to make it sparse.

它还说:

[...]具有以下别名,“ cp”将使用文件系统支持的最小空间量。

alias cp='cp --reflink=auto --sparse=always'

为什么没有--sparse=always默认值?


1
--reflink除了不知道以外,它与... 不兼容...
Stephen Kitt

也许仅仅是因为开发人员想要利用最少惊喜的原理,还是因为POSIX另有规定?(即使在posix中也算是cp,我忘记了)
cat

2
检查稀疏性可能会降低性能,稀疏文件可能会导致严重的文件系统碎片,并且至少存在一个使用损坏数据的实例cp --sparse
frostschutz

1
通过读/写循环复制的数据(主要是非稀疏)文件涉及到数据流入和流出的内存的DMA,而寻找暗示的零的运行总是(或汽车,其中块的数量不文件匹配大小)会将数据拖到CPU缓存中,并涉及更多的CPU带宽和周期。
meuh's

1
@StephenKitt它与--reflink兼容:info cp包含:with the following alias, ‘cp’ will use the minimum amount of space supported by the file system. alias cp='cp --reflink=auto --sparse=always'
汤姆·黑尔

Answers:


2

为什么不是默认值,有几个原因,一个是向后兼容性,性能,最后但并非最不重要的是最小惊喜原则。

我的理解是,启用此选项后,CPU开销可能不一定可以接受,此外,向后兼容也是关键。该cp命令在没有此命令的情况下可以可靠地工作,确实节省了一点空间,但是如今,这实际上可以忽略不计,至少在大多数情况下...

我认为您收到的评论还强调了其他原因。

最小惊喜原则意味着您不必不必要地进行更改,cp已经存在数十年了,更改其默认行为将使许多退伍军人不高兴。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.