1. Hardware block size, "sector size"
2. Filesystem block size, "block size"
3. Kernel buffer cache block size, "block size"
4. Partition table block size, "cylinder size"
To differentiate between the filesystem block size and the buffer cache block size, I will follow FAT terminology and use "cluster size" for the filesystem block size.
The sector size is the units that the hardware deals with. This ranges between different hardware types, but most PC-style. hardware (floppies, IDE disks, etc.) use 512 byte sectors.
The cluster size is the allocation unit that the filesystem uses, and is what causes fragmentation - I'm sure you know about that. On a moderately sized ext3 filesystem, this is usually 4096 bytes, but you can check that with dumpe2fs. Remember that these are also usually called "blocks", only that I refer to them as clusters here.
The cluster size is what gets returned in st_blksize in the stat buffer, in order for programs to be able to calculate the actual disk usage of a file.
The block size is the size of the buffers that the kernel uses internally when it caches sectors that have been read from storage devices (hence the name "block device"). Since this is the most primitive form. of storage in the kernel, all filesystem cluster sizes must be multiples of this. This block size is also what is almost always referred to by userspace programs. For example, when you run "du" without the -h or -H options, it will return how many of these blocks a file takes up. df will also report sizes in these blocks, the "Blocks" column in the fdisk -l output is of this type, and so on. It is what is most commonly referred to as a "block". Two disk sectors fit into each block.
The cylinder size is only used in the partition table and by the BIOS (and the BIOS isn't used by Linux).
"df" only operates on filesystems, so, no, it can't be used without a filesystem - without a filesystem, the data that it would return doesn't exist. "du" operates on individual files.
自从开始Linux 软件平台开发,经常遇到“Block Size”。但经常发现此block size非彼block size。意义不一样,大小值也不一样。Open Source的东东有时候也挺烦的。下面是自己的总结。
通常Linux的“block size”指的是1024 bytes,Linux用1024-byte blocks 作为buffer cache的基本单位。但linux的文件系统的block确不一样。例如ext3系统,block size是4096。使用tune2fs可以查看带文件系统的磁盘分区的相关信息,包括block size。
例如:
tune2fs -l /dev/hda1 |grep "Block size"
Block size: 4096
另一个工具dumpe2fs也可以。
其实本来这几个概念不是很难,主要是NND他们的名字都一样,都叫“Block Size”。
1. 硬件上的 block size, 应该是"sector size",linux的扇区大小是512byte
2. 有文件系统的分区的block size, 是"block size",大小不一,可以用工具查看
3. 没有文件系统的分区的block size,也叫“block size”,大小指的是1024 byte
4. Kernel buffer cache 的block size, 就是"block size",大部分PC是1024
5. 磁盘分区的"cylinder size",用fdisk 可以查看。
我们来看看fdisk显示的不同的信息,理解一下这几个概念:
Disk /dev/hda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 1305 10482381 83 Linux
/dev/hda2 1306 1566 2096482+ 82 Linux swap
/dev/hda3 1567 30401 231617137+ 83 Linux
8225280就是cylinder size。一共有30401个cylinder。Start和End分别标记的是各个分区的起始cylinder。 第4列显示的就是以1024为单位的block(这一列最容易把人搞晕)。为什么“2096482+”有个“+”号呢?因为啊,总size除1024除不尽,是个约数,表示2096482强!哈哈。搞笑吧,只有opensource的人想得出来这么表示。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22161612/viewspace-670306/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22161612/viewspace-670306/