Computer storage terminology: sector, disk block, page

sector

The basic unit of reading and writing on the hard disk is sectors. Each track on the disk is divided into several arc segments, which are called sectors. The physical reading and writing of hard disks are based on sectors. Normally the size of each sector is 512 bytes. Under Linux, you can use  fdisk -l :

$ sudo /sbin/fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7d9f5643

Among them, Sector size is the sector size, which is 512 bytes in this example.

Note that sectors are a concept at the physical level of the disk. The operating system does not interact directly with sectors, but with disk blocks composed of multiple consecutive sectors. Since sectors are a physical concept, the size cannot be changed in the system.

Disk block, IO Block

The smallest unit for reading and writing data in a file system, also called a disk cluster. A sector is the smallest physical storage unit of a disk. The operating system combines adjacent sectors to form a block and manages the block. Each disk block can consist of 2, 4, 8, 16, 32, or 64 sectors. Disk blocks are a logical concept used by the operating system, not a physical concept of the disk. The size of the disk block can  stat /boot be viewed with the command:

$ sudo stat /boot
  File: /boot
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 801h/2049d  Inode: 655361      Links: 3
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-07-06 20:19:45.487160301 +0800
Modify: 2019-07-06 20:19:44.835160301 +0800
Change: 2019-07-06 20:19:44.835160301 +0800
 Birth: -

Among them, IO Block is the disk block size. In this example, it is 4096 Bytes, which is generally 4K.

In order to better manage disk space and read data from the hard disk more efficiently, the operating system stipulates that only one file can be placed in a disk block, so the space occupied by a file can only be an integral multiple of the disk block, which means It may happen that the actual size of the file is less than the disk space it occupies.

test2.txt is a text document containing only one letter. Its theoretical size is one byte, but since the system's disk block size is 4KB (the minimum storage size unit of files), the actual disk space occupied by test2.txt is 4KB

The operating system cannot directly address and write disk sectors. The main reason is that the number of sectors is huge, so multiple consecutive sectors are combined and operated together. The size of disk blocks can be changed through the blockdev command.

page, page

The smallest storage unit of memory. The page size is usually 2^n times the disk block size. You can  getconf PAGE_SIZE get the page size through the command:

$sudo getconf PAGE_SIZE
4096

In this example, it is 4096 Bytes, which is consistent with the disk block size.

Summarize two logical units:

  • Page, the basic unit of memory operations
  • Disk block, the basic unit of disk operations

The operating system often communicates with two storage devices, memory and hard disk, similar to the concept of "block", both of which require a virtual basic unit. Therefore, with memory operations, the concept of a virtual page is used as the smallest unit. When dealing with hard disks, blocks are the smallest unit.

command index

  • sector size,fdisk -l
  • disk block size,stat /boot
  • memory page size,getconf PAGE_SIZE

Guess you like

Origin blog.csdn.net/h363659487/article/details/135141587