The secret of the hard drive

We are all familiar with the hard drive. It stores a lot of our learning materials, and is often "whipped" by many articles because of its slow access speed.

image

I found a website (link at the end of the article). This website shows the delay time of different media data access from 1990 to 2020.

I went through the media's own speed of the order of magnitude unchanged. The memory access latency was from 207ns to 100ns, and the hard disk was from 19ms to 2ms, but the access speed between the media was still several orders of magnitude worse.

However, what I have circled above is random access, and sequential access will not be so bad. If you want to know why, you need to understand the structure of the hard disk.

Of course, the hard drive I mentioned today refers to mechanical hard drives, and solid state drives are not covered in this article.

The reason for writing this article is because I have always had doubts about tracks, cylinders, sectors and other things, such as:

  • Why did you come up with the concept of cylinder?

  • Where does the track mean?

  • Are the sectors equally divided?

  • .....and so on

So let’s take a closer look today. According to my habit, let’s take a brief look at history first.

A brief history of hard drives

On September 14, 1956, the world's first disk storage device, IBM 305 RAMAC, was born. This device uses disks to store data and uses magnetic heads to read and write data. However, due to the technology at the time, this volume is indeed a bit large. Two refrigerators are so big, just look at the picture below.

image

I looked at the history in the middle and it didn't help us. Let's fast forward to 1973, when IBM introduced a hard drive code-named "Winchester".

The characteristic of this kind of hard disk is that the magnetic head and the magnetic disk are installed in a confined space. When the magnetic disk is auto-transmitted at high speed, the magnetic head will be suspended due to aerodynamic force, and then the magnetic head arm will operate the magnetic head to move in an arc along the disk.

This is how our current mechanical hard drives operate. After so many years, they still have a typical "Winchester" structure, also known as a warm disk.

As for why this code name was chosen, it was because the hard disk that was researched at the time had two 30MB storage units, and the caliber and charge of the "Winchester rifle" were also exactly 30, so the code name was "Warm Cut". Ster".

History we know that this step is almost the same, let's take a look at the internal structure of the hard drive.

The structure of the hard disk

Let's take a look at the real appearance of the hard disk first, and I will mark some key parts.

image

Let me briefly describe how the hard drive works.

After the power is turned on, the spindle drives the disc to start rotating. After reaching a certain speed, the magnetic head will float above the disc, and then the magnetic head arm can control the magnetic head to move in an arc. It is possible to access the disc through the rotation of the disc and the movement of the magnetic head. Data anywhere on the chip.

Some people here may have questions, why should the head float?

First of all, there will be friction when the head and the disk touch. After a long time of friction, there will be wear. After the wear, the data will disappear?

Secondly, when there is friction, the speed will definitely slow down, and the access speed of the disk will also be slow.

Therefore, the levitation is very important, and the height of the head levitation is thinner than the hair, about 0.1 micron. If dust gets in, it may cause the head and the disk to wear out, which is why the hard disk needs to be sealed.

Wasn't the head in contact with the disc when it first started up?

Yes, you are right, so people thought of a way, which is the stopping point of the head, which is the place drawn in the picture above.

When the power is turned on, the head will not move to the platter until it reaches a certain speed. After the power is off, the head will be moved to the dock by the remaining power of the capacitor, so that it will not wear out every time you start it!

Another way of docking is to make a place where no data is stored in the inner circle of the disc. The materials are different, and the head is specifically docked.

image

In order to insert the video on the official account, I also uploaded a video on Tencent Video. The video is run from the hard drive of Wikipedia. The docking of this video hard drive should be the second way.

Watch this video

 

After getting a rough idea of ​​how the hard drive works, let's take a deeper look.

I originally wanted to draw pictures by myself, but my personal level of drawing is limited, and they are so good...so I moved in, hahaha.

Let's look at the next board first.

image

A is the magnetic track. The disk surface is composed of a group of concentric circles such as the magnetic track. Note that the part marked in red is a ring with a cross section. Some reference books are marked on the line...

B is a sector, and C is a sector. Each track is divided into a set of sectors. Each sector contains an equal number of data bits, generally 512 bytes, which is the most basic unit of hard disk storage of data.

D is a cluster, which is composed of multiple sectors. For example, DOS allocates disk space for files in clusters.

From the figure, the sectors seem to be continuous. In fact, there are gaps between the sectors. These gaps are used to identify the formatting bits of the sectors and do not store data.

image

I don’t know if you’re a little confused when you see this. Each sector contains equal data bits. The concentric sector that is obviously closer to the center of the circle seems to have much smaller data than the outermost sector. Isn’t that the outer sector? Should the data bit accommodate the innermost?

image

Yes it is. In order to make each track have the same number of sectors, the interval between the sectors of the outer track is very large, but the data storage density of the previous hard disk is very low, so it is acceptable.

As the storage density of hard disks increases, this has caused great waste. Therefore, a  zoned-bit recording technology was developed to place more sectors on the outer track than the inner track. Look at this picture to understand.

image

I won’t expand on how to implement it.

The important thing is to clarify. It is not as in some books that the number of sectors of all tracks is determined rigidly according to the number of sectors in the innermost circle.

Hard disks usually consist of one or more disks.

For example, there are three discs in the figure below, and each disc has two upper and lower disc surfaces, corresponding to six magnetic heads.

image

The head number starts counting from 0 from top to bottom, and the head arm leads the head to make a circular arc movement. The track on each disk also starts counting from 0. The area composed of the tracks with the same number is called a cylinder, and it should be possible to get it with the use of imagination. I will post a picture to help.

image

Why is there the term cylinder?

Because several magnetic heads actually rely on the same magnetic head arm to move, they all rotate together at an angle.

Therefore, if you want data to be read quickly, then the data should be stored sequentially on a uniform cylinder.

For example, if the first track of the top disk cannot be written, then continue to write to the second disk on the back, so that the head arm only needs to seek once, and it only needs to seek once when reading data.

From here we can also know that if a hard disk has more platters, the faster it will be.

Hard disk access time

From the above, we already know that the hard disk is based on the sector, so the access of the hard disk is to find the corresponding sector.

The surface of the disc is magnetic. The disc rotates with the rotation of the main shaft. When a sector is to be accessed, the head arm must first be rotated to find the corresponding track. This is called seek time.

At this time, the disc is still rotating, and the head can perceive the value of the data bit below, and when it rotates to the target sector, it will know that it is time to read/write data. This time is called the rotation time.

So when we buy hard drives, we will see 7200RPM, 15000RPM and so on. The faster the rotation, the shorter the time it takes for the disk to find the sector.

The last is the transfer time of the read data.

Therefore, the hard disk data access delay is the sum of these three times, and the slowest is the seek time. I will give the data provided by CSAPP:

Total delay = seek time + rotation time + transmission time = 9ms+4ms+0.02ms=13.02ms

Of course, the total delay of different hard disks is definitely different, anyway, just know that the seek time is the slowest.

Logical disk block

From the above physical structure, we already know that we need to find the disk surface, then find the track, and finally find the sector to read the data, which is a bit complicated.

There is no need to expose such unfriendly access gestures to the operating system, so a logical disk block is created to shield the details of the underlying access and provide logical block sequences like 0, 1, 2,...n to correspond Specific physical block.

In this way, the operating system is very comfortable to access the disk, but in the end it has to find the corresponding sector, and the disk controller maintains the mapping relationship between the logical block and the actual physical sector.

The disk controller is a piece of hardware in the hard disk, which translates the logical block into: a triple of disk surface, track, and sector.

So far we usually talk about the logical block and the physical access of the hard disk.

At last

As an ordinary programmer, I feel that the understanding of hard disks is about the same, and I know everything that I should know.

If there are any errors pointed out, please correct me!

 

Shoulders of giants

https://colin-scott.github.io/personal_website/research/interactive_latency.html (websites delayed by medium)

https://en.wikipedia.org/wiki/Zone_bit_recording

https://en.wikipedia.org/wiki/Hard_disk_drive

https://zh.wikipedia.org/wiki/%E7%A1%AC%E7%9B%98

"In-depth understanding of computer systems"

Guess you like

Origin blog.csdn.net/MyySophia/article/details/113734896