问题原文
原帖链接 · LetMeSOThat4U · CC BY-SA 4.0
mkfs.xfs has two following options among others:
-b block_size_options
This option specifies the fundamental block size of the filesystem. The valid
block_size_options are: log=value or size=value and only one can be supplied. The block
size is specified either as a base two logarithm value with log=, or in bytes with size=.
The default value is 4096 bytes (4 KiB), the minimum is 512, and the maximum is 65536 (64
KiB). Although mkfs.xfs will accept any of these values and create a valid filesystem, XFS
on Linux can only mount filesystems with pagesize or smaller blocks.
-s sector_size
This option specifies the fundamental sector size of the filesystem. The sector_size is
specified either as a value in bytes with size=value or as a base two logarithm value with
log=value. The default sector_size is 512 bytes. The minimum value for sector size is 512;
the maximum is 32768 (32 KiB). The sector_size must be a power of 2 size and cannot be made
larger than the filesystem block size.
Well isn't this description redundant. The only hint that sector may be something that block internally uses is "The sector_size must be a power of 2 size and cannot be made larger than the filesystem block size". Perhaps sector here is meant as the sector size of underlying block device? Default of 512 bytes would indicate that.
Obviously, that's just a guess. I would like to know what are differences between a block and a sector here, in context of XFS and how either impacts filesystem performance.
社区高分解答
原帖链接 · shodanshok · CC BY-SA 4.0
The short answer is that block size is the minimum allocation size, while sector size is the underlying physical device sector size. However, such concise answer fails to convey the true difference between block and sector size.
The key point to understand is that sector size is the atomic write size of the underlying physical device - in other words, the unit size which is expected to completely succeed or fail, with no intermediate outcome (ie: partial writes). This concept is extremely important for XFS journal safeguards: misconfiguring the sector size means venturing into dangerous territory.
Block size is a more "mundane" unit: it describe the minimum filesystem allocation for file data. On a filesystem with 4k block size, writing a single byte of data (ie: echo -n 0 > /root/test.file) results in a file with 4K true size:
[root@localhost ~]# echo -n 0 > test.file
[root@localhost ~]# stat test.file
File: test.file
Size: 1 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 100664426 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2023-06-10 17:47:50.973092242 +0200
Modify: 2023-06-10 17:47:50.974092238 +0200
Change: 2023-06-10 17:47:50.974092238 +0200
Birth: 2023-06-10 17:47:50.973092242 +0200
[root@localhost ~]# du -hs test.file
4.0K test.file
Side note: as you can see from stat, Linux internally counts size in 512B-size "logical sector" units (on the example above, 8x 512B "linux" blocks = 1x 4K XFS block).
The short summary is that while block size is "merely" an optimization parameter, sector size should really be right (hence the autodetection) - or filesystem corruption on crash/powerloss is possible.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
