Hola, I’m yes.
Hard disk this thing presumably we are quite familiar with, it stored a lot of our learning materials, but also often because of slow access to many articles out of the “lash”.
I went to a website (link at the end of the article) that shows the latency of data access on different media from 1990 to 2020. I looked through the order of magnitude of the speed of the media itself. Memory latency went from 207ns to 100ns, hard disk latency went from 19ms to 2ms. But the speed of access between media is still several orders of magnitude different.
But what I’ve circled above is random access, sequential access is not that bad, and to understand why, you need to understand the structure of the hard drive.
Of course, the hard drives I’m referring to today are mechanical hard drives; solid-state drives are not covered in this article.
The reason for writing this article is that I have been wondering about tracks, cylinders, sectors, etc., for example:
- Why was the idea of a cylinder invented?
- What exactly does a track refer to?
- Sectors are equally divided, right?
- . Etc.
So let’s get things straight today, and as is my custom we’ll start with a brief history.
Hard drive a brief history of
On September 14, 1956, the IBM 305 RAMAC, the world’s first disk-storage device, was introduced. The device used a disk to store data and a magnetic head to read and write data. However, due to the technology of the time, it was a bit large, about the size of two refrigerators.
The history in between doesn’t help us, so let’s fast forward to 1973, when IBM introduced a hard drive code-named Winchester.
The features of the hard disk are that the head and disk are enclosed in a confined space. When the disk rotates at high speed, the head is aerodynamically levitated. The head arm then moves the head along the disk in an arc.
This is how our modern mechanical hard disks work. After all these years, they still have a typical “Winchester” structure, also known as a warm disk.
The reason for the code name was that the hard drive developed at the time had two 30MB storage units, and the Winchester Rifle was both 30 caliber and charge, so the code name was “Winchester”.
That’s about it. Let’s take a look at the internal structure of the hard drive.
Hard Disk Structure
Let’s take a look at what the hard drive really looks like, and I’ve labeled some key parts.
Let me give you a quick overview of how hard drives work.
The spindle drives the disk to rotate, and when it reaches a certain speed, the head will float above the disk. Then the head arm can control the head to move in a circular arc. By rotating the disk and moving the head, data can be accessed anywhere on the disk.
Some of you might be wondering, why do you float the heads?
First, if the head touches the disk, there will be friction. After a long time of friction, there will be wear and tear. After wear, the data will be lost.
Secondly, there is friction after the speed will be slow, the disk access speed will be slow.
So levitation is key, and the head levitation is thinner than a human hair, about 0.1 micron. If dust gets in, it can cause wear and tear to the head and the disk, which is why the hard drive needs to be sealed.
Didn’t the head make contact with the disk when it started?
Yeah, you’re right, so they came up with a way to do it, and that’s where the head stops, which is the picture above.
When the power is turned on, the head will not move to the disk until it reaches a certain speed. When the power is turned off, the remaining charge of the capacitor will move the head to the dock, so that it will not wear out every time it is started.
Another way to dock is to make a non-data storage space in the inner ring of the disk, which is made of different materials, specifically for the magnetic head to dock.
In order to insert the video in the public account, I also uploaded a video on Tencent Video, which was run by the hard disk from Wikipedia. The docking of the video hard disk should be the second way.
Take a look at this video
V.qq.com/x/page/w322…
Once we have a rough idea of how hard drives work, let’s dig a little deeper.
Here I wanted to draw by myself, but my drawing skills are limited, they are too good… So I moved here, hahaha.
Let’s take a look at the surface.
A is the track, the disk is composed of A group of concentric circles such as the track, note is marked in red, is A ring, there is A cross section, some reference books marked to the line….
B is a sector, and C is a sector. Each track is divided into a group of sectors. Each sector contains the same number of data bits, usually 512 bytes, which is the basic unit for storing data on a disk.
D is a cluster, which is composed of multiple sectors. For example, DOS allocates disk space for files by cluster.
From the diagram, it looks like the sectors are contiguous, but in fact there are gaps between the sectors. These gaps are used to identify the formatting bits of the sector and do not store data.
Each sector contains the same amount of data bits. The concentric sector that is obviously closer to the center of the circle seems to hold much less data than the outermost sector. Isn’t the outermost sector having to accommodate the outermost data bits?
Yes. In order to have the same number of sectors for each track, the outer track has a wide space between sectors, but in the past hard drives had low data storage density, so it was acceptable.
With the increase of disk storage density, this caused a great waste, so we developed a zoned bit recording technology, the purpose is to place more sectors on the outer track than the inner track, see this figure.
I won’t expand on how to do that, it doesn’t matter.
The important thing is to clarify the confusion, and not, as some books say, to determine the number of sectors of all tracks by the number of sectors in the innermost loop.
A hard disk usually consists of one or more disks.
For example, there are three platters in the picture below. Each platter has two upper and lower platters, corresponding to six magnetic heads.
The head number starts with 0 from top to bottom, and the head arm leads the head to make circular motion. Tracks on each disk surface are also counted from 0, and the area composed of tracks with the same number is called cylinder. It should be possible to get it by using your imagination. Let me paste another picture to help.
Why do we have the term cylinder?
Since several heads are actually moving on the same head arm, they all turn together and at the same Angle.
Therefore, to read data quickly, the data should be stored sequentially on a unified cylinder. For example, if the first track on the top disk fails to write, the data should be written to the second disk on the back, so that the head arm only needs to find once and read data only needs to find once.
From this we also know that the more disks a hard drive has, the faster it will be.
Disk access time
As we know from the above, hard disks are based on sectors, so access to hard disks is to find the corresponding sector.
The surface of the disk is magnetic, and the disk rotates with the rotation of the main axis. When accessing a sector, the first step is to turn the magnetic head arm to find the corresponding track, which is called seek time.
At this point, the disk is still spinning, the magnetic head can sense the value of the data bit below, and when the disk rotates to the target sector, it will know the time to read/write data. This time is called the spin time, so when we buy a hard disk, we will see 7200RPM, 15000RPM, etc. The faster the disk rotates, the shorter the time to find the sector.
Finally, it’s time to read the data.
So the hard disk data access delay is the sum of these three times, and the slowest is the seek time. I provide CSAPP with the following data:
Total delay = Seek time + rotation time + transmission time =9ms+4ms+0.02ms=13.02ms
Of course, the total latency varies from hard drive to hard drive, but it’s good to know that the seek time is the slowest.
Logical disk block
We already know from the physical structure above that we need to find the disk, find the track, and finally find the sector to read the data, which is a bit complicated.
There was no need to expose such unfriendly access posture to the operating system, so a logical disk block was created that masked the details of the underlying access and provided numbers 0, 1, 2….. N such a sequence of logical blocks to correspond to a specific physical block.
This makes it easy for the operating system to access the disk, but eventually it has to find the corresponding sector, and the disk controller maintains the mapping between the logical block and the actual physical sector.
A disk controller is a piece of hardware inside a hard disk that translates a logical block into a triad of disk, track, and sector.
At this point, the physical access to the logical block and the hard disk is also corresponding.
The last
As an ordinary programmer I think the hard disk understanding to this point is almost, the know all know.
If there is any mistake to point out, welcome to correct!
The article continues to update, wechat search a search “yes training guide” for the first time to read, pay attention to the reply “algorithm” can get a selected 20W word algorithm notes, the article has been included: github.com/yessimida/y… Welcome to star!
I am yes, from a little bit to a billion little bit, welcome to see, forward, leave a message, we will see you next.
Shoulders of giants
Colin – Scott. Making. IO/personal_we…
En.wikipedia.org/wiki/Zone_b…
En.wikipedia.org/wiki/Hard_d…
Zh.wikipedia.org/wiki/%E7%A1…
Understanding Computer Systems in Depth