What is l1, l2 and l3 cache and how does it work?
Table of contents:
- What is the cache memory of a CPU
- Storage levels
- The third level, the fastest
- How caching works
- The memory controller comes into play
- L1, L2 and L3 cache
- L1 cache memory
- L2 cache memory
- L3 cache memory
- How to know the cache L1, L2 and L3 of my processor
- Latency, bus width and lack of cache
- Conclusion about L1, L2 and L3 cache memory
Have you ever heard of cache L1, L2, and L3 ? Surely yes, but if you are not sure what these cache levels really mean, in this article we will try to explain everything to the best of our ability. From now on you will better understand the memory characteristics of a processor.
You will already know that one of the most important components of a computer is its memory, we speak of course of RAM memory, the one where all the programs and operating system are loaded so that they are used by the processor or the need to access the disk Lasted.
RAM is much faster than a hard drive, especially than mechanical drives. But there is still a faster memory in our computer, specifically within our processor, and this is the cache memory, which is what we will see today.
Index of contents
What is the cache memory of a CPU
The first thing we will have to know is what is the cache in general. As we have already said, within a PC there are several types of memory and precisely the cache memory will be the fastest of all.
Storage levels
To begin, in the first step we will have the primary storage, which undoubtedly are hard drives. In them all the information is stored permanently, from it the operating system makes a functional PC. It's the slowest memory, from about 150MB / s on an HDD (mechanical hard drive) to the impressive 3, 500MB / s of the fastest SSDs on the market.
Second, we will have random access memory or RAM. It is a smaller solid state memory, which is not capable of storing data permanently and acts as a gateway between the hard disk and the processor. It offers a speed greater than 30, 000 MB / s in DDR4. Memory is also called DRAM (Dynamic RAM) because it needs to be constantly updated to avoid losing information.
The third level, the fastest
And finally we come to the one at the top, the cache. It is a very small memory that is installed inside its own microprocessor and of the SRAM (Static RAM) type. It is much more expensive to manufacture than normal RAM, and can hold data without constantly being updated.
The fact of being installed inside the CPU makes it the closest to the processing cores, and that is why it must be damn fast. In fact, it reaches speeds of over 200 GB / s and latencies of around 10 or 11 ns (nanoseconds). The cache memory is in charge of storing the instructions that are imminently going to be processed by the CPU, so that it can access them as quickly as possible.
In turn, the cache memory is divided into several levels, each one faster, smaller and closer to the processor. Processors currently have a total of three levels of cache memory inside. Before we get into this, let's take a quick look at how a cache works.
How caching works
You may not know it, but practically all the peripherals and elements of a computer have their own cache memory, for example, the hard drives themselves, the printer, and of course the GPUs of the graphics cards. And the function of all of them, including that of a CPU will be the same.
As we know, a computer is "smart" thanks to the operating system and its programs. Each of these programs is created from a programming language, which in turn are a set of instructions that must be executed in an orderly manner in the CPU. We say in an orderly way because it is at this point that establishing different levels of storage makes sense.
The data is stored in a fixed way in the hard drives, but since they are so slow and are "so far" from the CPU, they are loaded before in the memory RAM, a much faster storage and only used for the programs that are working.
The memory controller comes into play
But it is still not enough, because today's CPUs are so fast and capable of executing millions of operations every second on each core, the cache enters. Inside the CPU there is a memory controller, which is basically what was previously called the north bridge or north bridge and was a chip installed on the motherboard. Well, this memory controller is now inside the CPU and is responsible for taking from RAM the instructions that are going to be executed, and also for returning the results of the processing cycle.
But there are also two types of buses that are in charge of communicating the CPU with the RAM memory, they are called data bus and address bus:
- Data bus: they are basically the tracks where the data and instructions circulate. There will be a data bus that communicates the RAM, cache and cores with each other. Address bus: it is an independent channel where the CPU requests the memory address where the data is located. The instructions are stored in memory cells, which have an address, and both the RAM, cache and CPU must know it to locate the data in question.
L1, L2 and L3 cache
By now, we already understand quite roughly how storage works on a PC, and how caching works. But we must know that there is a cache L1, L2 and L3 inside the CPU, it seems incredible that something so small fits so much right? For these three levels of cache memory cater to a hierarchy of speed and of course, of capacity.
L1 cache memory
The L1 cache is the fastest configuration, the one closest to the cores. This stores the data that will immediately be used by the CPU, and that is why the speeds are around 1150 GB / s and the latency is only 0.9 ns.
The size of this cache memory is around 256 KB in total, although depending on the CPU power (and cost) it will be less or greater, in fact, Workstation processors such as the Intel Core i9-7980 XE have some 1152 KB in total.
This L1 cache is divided into two types, the L1 data cache and the L1 instruction cache, the first one is in charge of storing the data to be processed and the second one stores the information about the operation to be performed (addition, subtraction, multiplication, etc).
In addition, each core has its own L1 caches, so if we have a 6-core processor, we will have 6 L1 caches divided into L1 D and L1 I. In Intel processors each one is 32 KB, and in AMD processors are also 32 KB or 64 KB on L1 I. Of course they will vary according to quality and power, as always.
L2 cache memory
The next one we will find will be the L2 or level 2 cache. This has more storage capacity, although it will be a little slower, about 470 GB / s and 2.8 ns latency. The storage size usually varies between 256 KB and 18 MB. We already see that they are considerable capacities for the speeds that we handle.
Instructions and data are stored in it and will soon be used by the CPU, and in this case it is not divided into Instructions and data. But we do have an L2 cache for each core, at least this is the case with the most relevant processors. For each core, there are usually 256, 512, or up to 1024 KB.
L3 cache memory
Finally we will find the L3 cache, which has a dedicated space for it on the processor chip. It will be the largest and also the slowest, we are talking about more than 200 GB / s and 11 ns of latency.
Currently a worthy processor is going to have at least 4MB of L3 cache, and drives up to 64MB can be seen. The L3 is typically spread over about 2MB per core, but let's just say it's not inside each core, so there is a data bus to communicate with them. The solvency and speed of a CPU largely depend on this bus and the RAM memory itself, and this is where Intel gets its power from AMD.
How to know the cache L1, L2 and L3 of my processor
Well, one of the fastest ways to know this information is to download the CPU-Z tool, which is completely free and will provide you with very complete information about your CPU. Even the three levels and the amount of storage for each. You can download it from its official website.
You could also put the make and model in the browser and head to the manufacturer's page, although they usually only provide information about the L3 cache. Of course, in all our review of processors we give complete information about the cache of each CPU and we benchmark its performance.
Latency, bus width and lack of cache
We have understood that data flows from the hard drive to the processing core through all memory levels. Where the processor first looks for the next instruction to process, is in the cache memory, a quality system should know how to correctly locate the data based on its importance in order to minimize access times to them, which is called latency.
Latency is then the time it takes to access data from memory. The farther and slower, higher latency and longer the CPU will have to wait for its next instruction. Thus when an instruction is not located in the cache memory, the processor must look for it directly in the RAM memory, this is called lack of cache or miss cache, this is when a slower PC is experienced.
Bus width is also of great importance for speed, as it marks the ability to transfer larger blocks of data from memory to the CPU. Both CPU and RAM are 64 bits, but the Dual Channel function is capable of doubling this capacity to 128 bits so that the transfer between these elements has greater capacity.
Conclusion about L1, L2 and L3 cache memory
We always look a lot at the number of cores and the speed of a processor, it is clear that it largely determines the total speed of it. But an element that sometimes is not usually taken into account is the cache memory, and it is essential when it comes to having a powerful processor.
Having a 6-core CPU with 4 or 16 MB of L3 cache for example, will be very significant when it comes to measuring its performance, especially when we have multiple open programs. So, from now on, take a good look at this section when you decide to buy a processor, because not everything depends on the frequency.
We have more interesting tutorials on this topic, so here we leave them:
We also recommend our updated hardware guides:
We hope that all this information has been useful to you to know more about the processors and the cache memory. If you have questions you can ask us in the comment box. See you in the next tutorial!
Ip: what is it, how does it work and how to hide it
What is IP, how does it work and how can I hide my IP. Everything you need to know about IP to navigate safely and hidden on the Internet. Meaning IP.
What is it and how does a gpu or graphics card work?
We explain what it is and how a GPU or graphics card that coexists inside your computer works. History, models and their functions in your system.
Intel smart cache: what is it, how does it work and what is it for?
Here we will explain in simple words what is Intel Smart Cache and what are its main characteristics, strengths and weaknesses.