In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >
Share
Shulou(Shulou.com)11/24 Report--
This article comes from the official account of Wechat: programming Technology Universe (ID:xuanyuancoding), author: Xuanyuan Wind O
Hi, this is Ah Q from workshop one of CPU. Do you remember me? long time no see.
The CPU I work in is an eight-core CPU with eight workshops that run with speed levers.
Early in the morning, Xiaohei from the MMU (memory Management Unit) department of our No. 1 workshop came to the leader's office, and I happened to be there.
"Leader, I heard that you agreed to Ah Q's plan and allocated a cache construction budget for each workshop?"
"you boy, you are well informed. Yes, the memory guy is too slow. After adding the cache, we don't have to read data from memory every time, which can improve our performance a lot," the leader said.
"then our MMU department also has to apply for a sum of money," Xiao Hei said.
The leader frowned and asked, "what are you going to do with the funds?"
"We also need to build caches."
"when your MMU department does the address translation work, what do you want to do with the cache? I'm afraid it's not because the leader has allocated money to us that you are jealous, right?" Well, I said to one side.
Blackie turned around, looked at me and said, "say I'm jealous, but let me ask you, do you know the process of virtual address translation?"
It doesn't bother me. I've heard him say before, "Why don't you know?" Take a 32-bit virtual address as an example, a 32-bit virtual address is divided into three parts, namely, page catalog index, page table index, and intra-page offset. When translating, take out the page directory address from the CR3 register, find the page table according to the page catalog index, then find the physical memory page according to the page table index, and finally complete the addressing according to the intra-page offset. Am I right? "
"Hey, you're a good boy with a good memory." Blackie couldn't believe it, and then asked, "since you know, I'll ask you again, how many times do you need to access memory to read the data?"
I thought about it for a moment and began to calculate. Read once from the page catalog table, read again from the page table, and finally access the data on the page to read again, a total of three times.
"memory needs to be accessed three times!" Well, I replied.
Blackie nodded and said, "Yes, you know, the memory guy is slow. Every time he reads or writes data, he has to access memory three times. Who can withstand that?"
That's right. I know the memory guy is slow, but it takes three times to read and write at a time. I didn't think about it.
"in the case of a 32-bit address, I haven't counted that the 64-bit page table has become a 4-level page table, so the number of times to access memory is even more!"
"fortunately, we are about to build a cache facility, and we don't have to read data from memory every time. If the cache can be found, we don't have to read memory!"
"but you still have to check the page catalogue and page table twice," said Xiao Hei.
"if only I could cache the results of the address translation, I wouldn't have to look it up in memory every time," I thought.
"you see, you and I have been thinking about it for a while, so I applied to the leader, and our MMU department also added a cache, so that the address translation became faster, and our whole workshop was more efficient!"
At this time, the leader stood up and said, "Oh, the pattern has to be opened. You can't improve your No.1 workshop. You have to start the eight workshops of the factory together. Xiao Hei, don't worry about the funding. It's up to you to take the lead. Call together the heads of the MMU department of the other workshops for a meeting and put your plan to the ground."
"No problem!" When the leader said this, Xiao Hei was overjoyed.
On the way back to the address translation cache, I couldn't help but wonder and asked Xiao Hei, "what are you going to do with the cache you use to translate the address?"
"I haven't thought about it very mature yet. I only have a general plan."
"tell me something."
"well, it wouldn't hurt to tell you! let me give you an example. Suppose the virtual address to be translated is 0x12345678, which is a 32-bit address, and the first 20 bits are 0x12345000. After looking up the table twice, navigate to the real physical page 0x00abc000, and finally add the intra-page offset, and the translation result is 0x00abc678."
"after the address translation is completed, record the mapping relationship between the virtual page number 0x12345 and the physical page number 0x00abc and put it in the cache."
"when doing address translation, first take a look in this cache to see if there is any record. If so, use the previous record directly. If you can't find it, look for it in the memory page table. Similar to the locality principle, the translated address is very likely to be used again in the next period of time, so this cache is very necessary!" Blackie said with great confidence.
"that sounds great. I'm looking forward to getting on the horse early!"
After a few days of TLB, I'm going to visit the MMU department to see how their cache is doing.
As soon as I entered the door, I saw Xiao Hei and the head of the MMU department in several other workshops were discussing nervously, drawing a lot of pictures on the drawing board on one side.
"Brother Black, what are you doing?"
"We are studying how to store this translation record cache item! you're just in time. We haven't had any good ideas after discussing it for a long time. Come and give me some advice."
I was a little curious and asked, "what question baffled you all?"
"it's the result of virtual address translation, and we don't know how to save it!"
"what is there to struggle with? the cache space is so large that a translation result is a record, one entry at a time."
The person in charge of MMU in No.2 workshop waved again and again, "it's not as simple as you think. According to your storage method, how to find it when translating the address? do you have to scan it all?"
I was stupefied for a moment. "Ah, I didn't think so much, but the cache space is not big, and I can't save too many translation results. Is all the scanning all right?"
"I can't do that. The goal of our CPU is to optimize the performance to the extreme. With this kind of solution, the leader can't scold me to death," Xiao Hei said.
I thought, "well, if you take a module for the numbering of a virtual page, the translation record of each virtual page can only be stored in a fixed location in the cache, so that it can be located at once without all scanning, isn't it great?"
Blackie shook his head: "We have just discussed this scheme. The limited cache space will cause a large number of virtual pages to be mapped to the same storage location, which will often conflict with each other, which is not a good idea!"
"it seems to be a bit of trouble," I also unconsciously frowned and fell into thinking.
"that's right. That's why we have a headache."
The air was suddenly quiet and everyone was bowing their heads and meditating.
"Oh, there it is!" An idea flashed through my mind.
"what way? tell me about it."
"packet connection!"
"packet connection?" Everyone asked.
"that's right! combine the previous two schemes. You can divide the cache storage space into many groups, all of which are too slow to traverse, and direct modular mapping is easy to conflict, so what if the result of the mapping is not a fixed location, but a grouping?"
"it sounds good. This not only reduces the conflict, but also only needs to be carried out in the grouping interval, and the workload is greatly reduced, which is really a good way."
Blackie and everyone agreed with me.
"then how are you divided into groups? how many items are divided into one group?" Well, someone asked.
"well, I don't know about this. I have to do experimental verification. 2, 4, 8, and 16 can all try it. Real knowledge comes from practice."
"OK, no problem. Let's come down and test it."
"I have one more question: when will your cache item be updated? we are in protection mode, different processes, the same virtual page after translation of the corresponding physical page is different, you do not use the wrong cache, that will be a big trouble!"
"Hey, needless to say, everyone here has been doing this job for a long time, which we know better than you. When the process is switched, the base address of the page directory table of the new process will be written to the CR3 register, and then we will erase all the data in the cache!" Xiao Hei said with confidence.
"you don't have to clear it all. For example, some kernel pages are shared by all processes, so you can keep them."
Blackie nodded. "that makes sense. It seems that we have to add a mark to the address translation record to mark whether it is globally valid."
A month later, the cache of the MMU department of the eight workshops was all built and put into use on the same day. The operational efficiency of our CPU has improved by leaps and bounds, and the power of this cache is really too great.
In order to distinguish them from our first-and second-tier cache, Blackie also gave their address translation cache a loud name: TLB-- translation backup buffer.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.