【发布时间】:2016-11-26 19:29:43
【问题描述】:
我正在查看fallocate 的手册页,但我不明白这两者之间的区别。一种似乎分配了块但没有写入它们,另一种似乎释放了块而不覆盖它们。无论哪种方式,从用户的角度来看,效果似乎都无法区分。请给我解释一下。
归零文件空间 指定 FALLOC_FL_ZERO_RANGE 标志(自 Linux 3.15 起可用) 在模式中,从偏移量开始的字节范围内的空间为零,并且 继续 len 个字节。在指定范围内,块是 为跨越文件中空洞的区域预先分配。后 一个成功的调用,从这个范围内的后续读取将返回 零。
Zeroing is done within the filesystem preferably by converting the range into unwritten extents. This approach means that the specified range will not be physically zeroed out on the device (except for partial blocks at the either end of the range), and I/O is (otherwise) required only to update metadata. If the FALLOC_FL_KEEP_SIZE flag is additionally specified in mode, the behavior of the call is similar, but the file size will not be changed even if offset+len is greater than the file size. This behavior is the same as when preallocating space with FALLOC_FL_KEEP_SIZE specified. Not all filesystems support FALLOC_FL_ZERO_RANGE; if a filesystem doesn't support the operation, an error is returned. The operation is supported on at least the following filesystems: * XFS (since Linux 3.15) * ext4, for extent-based files (since Linux 3.15) * SMB3 (since Linux 3.17)增加文件空间 指定 FALLOC_FL_INSERT_RANGE 标志(自 Linux 起可用 4.1) in mode 通过在文件中插入一个洞来增加文件空间 文件大小而不覆盖任何现有数据。洞会开始 在偏移处并继续 len 个字节。将孔插入内部时 文件,从偏移量开始的文件内容将被移动 向上(即到更高的文件偏移量) len 个字节。插入一个 文件中的空洞会使文件大小增加 len 个字节。
This mode has the same limitations as FALLOC_FL_COLLAPSE_RANGE regarding the granularity of the operation. If the granularity requirements are not met, fallocate() will fail with the error EINVAL. If the offset is equal to or greater than the end of file, an error is returned. For such operations (i.e., inserting a hole at the end of file), ftruncate(2) should be used. No other flags may be specified in mode in conjunction with FALLOC_FL_INSERT_RANGE. FALLOC_FL_INSERT_RANGE requires filesystem support. Filesystems that support this operation include XFS (since Linux 4.1) and ext4 (since Linux 4.2).
【问题讨论】:
标签: file filesystems fallocate