当前位置:网站首页>The CPU does this without the memory

The CPU does this without the memory

2020-11-07 20:15:16 The wind of Xuanyuan

Remember me? , I am Q,CPU The one in workshop one Q.

I'm having a break today , Come to the factory Address translation department around , Xiao Hei, who is in charge of this work, is sweating .

To see me coming , Xiao Hei pointed to the seat next to me to sit down .

For a long time , Xiao Hei turns around from the work station ,“ I'm really sorry Q, There's too much to live today , I didn't have time to entertain you ”

“ What have you been up to , You're sweating ”, I asked .

“ hi , Don't mention it. , Always find memory page errors , Keep telling the operating system to deal with it , I miss the past , There's not so much to worry about ”, Little black sighed .

I was interested in it ,“ Xiao Hei, tell me about your work , How about address translation , Why miss the past ?”

Xiao Hei adjusted his sitting posture , Gulu Gulu drank a few saliva and said ,“ This is a long story ”

Then Xiao Hei began to tell me a historical story ······

8086

So our ancestors were called 8086, Xiao Hei also showed me his picture

It was an age of simplicity , Although the working performance is not high , But the procedures of those days were very simple , Our ancestors became stars as soon as they came out , It's the pinnacle of that era .

See those metal pins in the picture ? That's us CPU The tentacles of dealing with the outside world , Each one has a different function .

Through these antennae ,CPU You can deal with memory , Get instructions and data , Hard work .

That s , The conditions are poor , Make do with what you can , Share what you can . see , Look at the ancestors CPU The address bus pin and the data bus pin share .

An ancestor is a 16 Bit CPU, data (Data) The bus has 16 position , It can be transmitted once 16 A bit . And address (Address) The bus is just about to be shared , So it was named AD0-AD15.

But the ancestor's address bus is more than 16 individual , There's more A16-A19 A full 4 A? ! There is 20 Address lines , Addressable 1MB The memory of the !

But the ancestor's registers are all 16 I'm sorry , Only store 16 Address of bit . But they're smart , He invented a new one called Segmented storage management Methods , Divide the memory into the largest size 64KB Small pieces , Why 64KB Well , because 16 Bit address can only address so large at most . And then I added something called a segment register , Point to the beginning of these blocks , such , By segment address + How to offset addresses within a segment , You can access more memory .

32 Time

Later on , The computing power of our ancestors is becoming more and more limited , I can't keep up with the times . The younger generation in the family is starting to pick the bridge ,80286 and 80386CPU One after another , In especial 80386, It became an epoch-making existence .

here we are 80386 Time , We have more pins to communicate with the outside world , And it became 32 Bit CPU, At that time , The living conditions are better , Address and data lines no longer share pins .

later , Human beings are becoming more and more greedy , Want to listen to music , On the other hand, I have to surf the Internet , Also edit the document , This requires running multiple programs at the same time .

This is the time , Someone found a business opportunity , Developed a project called operating system Things that are , It turns out that those programs are no longer directly related to us CPU Deal with , It's about dealing with the operating system , The operating system deals with us again , Middlemen earn the difference, and that's what they say !

The operating system is smart , Let's... Through time slices CPU To run multiple programs in turn , Let's play the music later , In a moment, let's execute the browser program , And then let's run the document editing program . We don't care , What code is given is not code , We don't choose , Just work hard . The speed of human reaction is far less than that of us , They thought these programs were actually executed at the same time .

Virtual memory

But then there was a big problem , So many programs have to run , We're all in one memory , Friction often happens , Constant conflict .

The ancestors worked hard for it , Finally came up with a good way , It has been used up to now .

They put forward a Virtual address Things that are , The address used by all programs is a virtual address , When it comes to really dealing with memory , We CPU Internal staff will translate it into the real memory address , About this , The memory guy has been kept in the dark .

thus , What every program can use is 0x00000000 To 0xffffffff in total 4GB Such a wide range of address space , Of course not really giving them so much space , The memory guy is just 4GB Well , It's about applying for distribution on demand . Units are assigned according to page To carry out ,32 Bit CPU One page is 4KB. The hard work of distribution management is left to the operating system , Middlemen can't just take advantage of the business , As for us CPU, Do a good job of address translation .

So , A new register has been added to our register CR3, An address is used to refer to a dictionary , The dictionary is divided into two categories . Let's put one 32 The address of bit is divided into 3 part , The first two parts point to the entries in the two levels of directories respectively , It is used to locate which page of the address is in physical memory , The last part is the offset to the physical memory page , This completes the translation of the address .

Each process has a different address space , When switching processes , hold CR3 Use the new process's translation dictionary for a change , Special convenience .

We call this memory management method Paging memory management .

I really admire the wisdom of our ancestors , This ingenious separation of the various procedures , Later we called this mode of work Protected mode , The previous mode of working directly with the real memory address is called Real address mode .

Paging switch

Human beings are becoming more and more greedy , More and more programs , The demand for memory is also increasing . As these programs continue to apply for memory pages , Memory space will soon run out .

We see it in our eyes , In my heart , Later, I consulted with the operating system , Let's see what to do with this problem .

The operating system guy is not bad , Come up with a good idea . The size of memory is limited , But the hard drive is awesome , Hard disk space is much larger , Draw an area on the hard disk , Change the pages that have not been used in memory for a long time to this area , And make a mark . If anyone in the back wants to visit that page , We CPU Just check if there's this sign , Send a page fault interrupt signal to the operating system to change the page back .

Through the cooperation between us , Solved the memory shortage crisis . Later we called this technology Memory paging switch .

Now?

Time passed quickly , In our generation , Memory is getting bigger ,16GB It's all small case,32GB Is also common .

Except for memory , We CPU It's also more advanced , If nothing else , If you just look at the number of pins we have now, it is not the same as those of our ancestors .

We're not only from 32 Bit becomes 64 position , And from a single core to a multi-core , Like where I am CPU There is 8 Workshops ,8 Core parallel execution , It's quite different from that of our ancestors .

Colored eggs

Chatting with Xiao hei , The old man in our workshop K Suddenly appeared at the door .

“ o Q So you're here , Let me find , Hurry back , Huzi from workshop 2 next door said we changed their data , Come to the door and make trouble ······”

Foresee the future , Please pay attention to the following highlights ······

Past hot reviews

Finished !CPU I'm just begging for something to happen !

terrible !CPU He became an accomplice of hackers !

Which hash table is better ? Several programming languages have been quarrelling !

Kernel address space adventure 4: Thread switching

shock ! The first source analysis panorama of the whole network Nginx

An integer +1 The disaster caused

The majestic ! Every programmer should know about hacking technology

I've seen countless Java GC article , this 5 You don't necessarily know !

One Java Object's memoirs : Garbage collection

Who moved your HTTPS Traffic ?

Advertising Secrets in routers

One HTTP The magic of data packets

I'm a rogue software thread

版权声明
本文为[The wind of Xuanyuan]所创,转载请带上原文链接,感谢