Home >Common Problem >Do SSDs have to be aligned to 4k?

Do SSDs have to be aligned to 4k?

青灯夜游
青灯夜游Original
2023-03-10 14:31:4913358browse

must. 4K alignment is an essential step in the use of solid-state drives. Through 4K alignment, the read and write size of the operating system can be consistent with the read and write block size of the hard disk, so that the data will not be split due to mismatch in size, affecting Overall reading and writing speed. Simply put, 4K alignment is to make the solid-state drive more accustomed to the computer system, thereby speeding up the efficiency of both and thereby improving the read and write performance of the hard drive. If the SSD is not aligned to 4K, the lifespan and speed will be greatly reduced.

Do SSDs have to be aligned to 4k?

The operating environment of this tutorial: Windows 7 system, DiskGenius V5.1.0.653, Dell G3 computer.

We all know that mechanical hard drives do not need 4k alignment when partitioning, so if it is a solid-state hard drive, does it have to be 4k aligned?

must. 4K alignment is an essential step in the use of solid state drives.

Reason:

  • The basic unit of the hard disk is a sector. Now the physical sector of the hard disk is 4096 bytes (previously 512, half K), that is, 4K . The basic unit of the file system is the cluster. Only when the cluster is also 4K can it correspond to the physical sectors one-to-one, so that the hard disk can achieve optimal performance and lifespan. Assume that if the physical sector is 4K and the cluster is 6K, then writing a cluster file requires two physical sectors, and the writing volume of the hard disk is doubled. This not only increases the loss of the hard disk, but also Greatly slowed down (one write action becomes two).

  • And through 4K alignment, the read and write size of the operating system can be consistent with the read and write block size of the hard disk, so that the data will not be split due to a mismatch in size. Affects the overall reading and writing speed.

  • Simply put, 4K alignment is to make the solid-state drive more accustomed to the computer system, thereby speeding up the efficiency of both and thereby improving the read and write performance of the hard drive. If the solid state is not aligned with 4K, the lifespan and speed will be greatly reduced.

Do SSDs have to be aligned to 4k?

The concept of physical sectors

Partition alignment refers to The starting position of the partition is aligned to a certain sector. We need to first understand the relationship between alignment and sectors. We know that the basic reading and writing unit of a hard disk is a "sector". For hard disk read and write operations, each read and write is performed in units of sectors, at least one sector, usually 512 bytes. Due to the limitations of the hard disk data storage structure, it is impossible to read and write 1 or several bytes individually. When reading and writing file data through the interface provided by the system, it seems that a small number of bytes can be read and written independently. In fact, this is achieved after conversion by the operating system. When the hard disk is actually executed, the entire sector is still read and written.

In recent years, as the requirements for hard disk capacity continue to increase, in order to increase the data recording density, hard disk manufacturers often use the method of increasing the sector size, so hard disks with a sector size of 4096 bytes have appeared. We call such sectors "physical sectors". However, there will be compatibility issues with such large sectors, and some systems or software cannot adapt to them. In order to solve this problem, the hard disk internally logically divides the physical sectors into multiple sector segments and reports them to the operating system and application software as ordinary sectors (generally 512 bytes in size). Such sector fragments are called "logical sectors". During actual reading and writing, the program (firmware) in the hard disk is responsible for converting between logical sectors and physical sectors. The upper-layer program does not "feel" the existence of physical sectors.

Logical sector is the smallest operating unit that the hard disk can accept read and write instructions. It is a sector that the operating system and application programs can access. In most cases, its size is 512 bytes. What we usually call sectors generally refers to logical sectors. A physical sector is a sector in the sense of the hard disk's underlying hardware and is the smallest unit that actually performs read and write operations. It is a sector that can only be directly accessed by the hard disk. Operating systems and applications generally cannot directly access physical sectors. A physical sector can contain one or more logical sectors (for example, the physical sectors of most hard disks contain 8 logical sectors). When a certain logical sector is to be read or written, the bottom layer of the hard disk will read and write the entire physical sector where the logical sector is located during actual operation.

The concepts of "hard disk" and "sector" mentioned here also apply to memory cards and solid-state drives (SSD). Next we collectively refer to them as "disks". The basic principles of their use are the same. The implementation of solid-state drives is more complex. It has the concepts of "page" and "block". For ease of understanding, we can simply regard it as a logical sector and a physical sector. In addition, the SSD must perform an erase operation before writing data. It cannot directly write to blocks that already contain data. It must be erased first and then written. Therefore, solid-state drives (SSD) have higher requirements for partition 4K alignment. Without alignment, the extra actions will add even more, causing read and write performance to degrade.

Partition and formatting

The disk must be partitioned and formatted before use. To simply understand, a partition refers to a large contiguous sector divided from the disk. Formatting is planning the use of sectors within the partition range. For example, how to arrange the storage of file data, where to store file attributes, how to store the directory structure, etc. After the partition is formatted, files can be stored. The formatter will group all sectors in the partition from beginning to end into fixed-size "clusters" and number them in sequence. Each "cluster" can contain one or more sectors, and the number of sectors is always 2 to the nth power. After formatting, the partition will be read and written in "cluster" as the smallest unit. The data, attributes and other information of the file must be saved in the "cluster".

Why partition alignment is necessary

#When partitioning a disk, it is divided in units of logical sectors. The partitions can be from any number. The logical sector starts. If the starting position of the partition is not aligned to the edge of a physical sector, all "clusters" will not be aligned to the edge of the physical sector after formatting. As shown in the figure below, each physical sector consists of 4 logical sectors. The partition starts from sector 3. After formatting, each cluster occupies 4 sectors, and these clusters are not aligned to the edges of the physical sectors, that is, each cluster spans 2 physical sectors.

Do SSDs have to be aligned to 4k?

Since the disk is always read and written in units of physical sectors, in such a partition situation, when you want to read a certain cluster, you actually always need Read one more physical sector of data. For example, if you want to read data from a total of 4 logical sectors in cluster 0, when the disk is actually executed, you must read data from a total of 8 logical sectors in physical sectors 0 and 1. In the same way, the same is true for the write operation of "cluster". Obviously, this will cause a serious decrease in read and write performance.

Let’s take a look at the alignment. As shown in the figure below, the partition starts from sector 4, which is aligned to the edge of physical sector 1. After formatting, each cluster also occupies 4 sectors, and these clusters are aligned to the edge of the physical sector.

Do SSDs have to be aligned to 4k?

With this alignment, when a cluster is to be read, the disk does not need to read any additional sectors during actual execution, and the read capacity of the disk can be fully utilized. Write performance. Apparently this is what we need.

It can be seen that for disks whose physical sector size is inconsistent with the logical sector size, only 4K partition alignment can give full play to the read and write performance of the disk. Failure to align will cause a decrease in disk read and write performance.

How to align

You can see from the two examples shown in the previous illustration that as long as the starting position of the partition is aligned to the physical sector The formatter will align each cluster to the edge of the physical sector, thus achieving partition alignment. Alignment is actually very simple.

How to detect the physical sector size

When dividing partitions, in order to achieve 4K alignment, you must first know the size of the physical sector of the disk. So how to query?

Open DiskGenius software, click on the disk to be detected, and in the disk parameter table on the right side of the software interface, you can find "Sector Size" and "Physical Sector Size". The "sector size" refers to the size of the logical sector. As shown in the figure, the physical sector size of this disk is 4096 bytes. Through calculation, it is known that it contains 8 logical sectors.

Do SSDs have to be aligned to 4k?

How many sectors must be aligned correctly?

Knowing the "sector size" and "physical sector size", Divide the "physical sector size" by the "sector size" to get the number of logical sectors contained in each physical sector. This value is the minimum number of sectors we want to align. Just align the starting position of the partition to an integer multiple of this value. For example, if the physical sector size is 4096 bytes and the logical sector size is 512 bytes, then 4096 divided by 512 is equal to 8. We only need to align the starting position of the partition to a sector that is an integer multiple of 8 to meet the partition alignment requirements. For example, align to 8, 16, 24, 32,... 1024, 2048, etc. As long as the starting sector number is divisible by 8, it's fine. It is not that the larger the divisor value, the better. The default number of aligned sectors in Windows systems is 2048. This value can basically meet the 4K alignment requirements of almost all disks.

Why do everyone say 4K alignment

Just a habit. Because when the concept of physical sectors began to appear, the physical sector size of most disks was 4096, which is 4K bytes. When used to it, it was commonly called 4K alignment. When actually partitioning, you still need to check the physical sector size, because the physical sectors of some disks may contain 4, 8, 16 or more logical sectors (always 2 to the nth power). After knowing the physical sector size, follow the calculation method just mentioned and use the number of logical sectors contained in the physical sector as a benchmark to align it to the actual physical sector size. If the physical sector size is 8192 bytes, it must be aligned according to 8192 bytes. Strictly speaking, this cannot be called 4K alignment.

How to specifically operate partition alignment when dividing partitions

Take DiskGenius software as an example. When creating a new partition, check "Align" in the "Create New Partition" dialog box to an integer multiple of the following number of sectors", then select the number of sectors that need to be aligned, and click "OK" to create a partition that is aligned. As shown in the figure below:

Do SSDs have to be aligned to 4k?

The software lists many options in the "Number of Sectors" drop-down box. Select any number of sectors that is larger than the physical sector size. All are possible and all meet the alignment requirements. The fact that the software lists so many sector number options only increases the degree of freedom of choice. It does not mean that the larger the number, the better. Using a value that is too large may waste disk space. The default settings of the software can already meet the 4K alignment requirements of almost all disks.

In addition to the "Create New Partition" dialog box, DiskGenius software also has a "Quick Partition" function, which also has the same alignment settings. As shown in the figure below:

Do SSDs have to be aligned to 4k?

How to detect alignment

As a powerful partition management software, DiskGenius also provides partitioning 4K alignment detection function. You can use it to check whether the partitions of your hard disk are aligned. The method of use is very simple. After opening the software, first select the disk to be detected on the left side of the software, and then select "Partition 4KB Sector Alignment Detection" in the "Tools" menu. The software will immediately display the detection results, as shown in the following figure:

Do SSDs have to be aligned to 4k?

The partition with "Y" in the "Alignment" column on the far right is the aligned partition, otherwise it is not aligned. Unaligned partitions are displayed in red font.

For more related knowledge, please visit the FAQ column!

The above is the detailed content of Do SSDs have to be aligned to 4k?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn