L2 Cache (Level 2)

In this article, we have explained the idea of L2 Cache (Level 2) in depth along with location, size and how to check L2 cache size and compared it with other standard caches like L1 and L3 cache.

Table of contents:

  1. What is L2 cache?
  2. Where is L2 cache located?
  3. L2 Cache Size
  4. Check L2 Cache Size in your System
  5. L2 vs L1, L3 cache
  6. Conclusion

What is L2 cache?

L2 cache stands for Level 2 cache in a computer system. It is the cache that is placed on the processor chip but outside the CPU core. It is the second fastest cache in a system and is also, the second smallest cache in terms of size. L2 cache is significantly larger (at least 4 times) than L1 cache.

L2 cache is rarely shared among CPU cores in modern mainstream systems. Though there exists niche systems where L2 cache is shared between two CPU cores.

L2 cache is made up of Static Random Access Memory (SRAM) which is an expensive but efficient memory storage and is an alternative to DRAM. All caches are made up of SRAM.

The main points about L2 cache are:

  • L2 is the larger than L1 cache by 4 to 16 times while it is significantly smaller than L3 cache.
  • L2 cache is slower than L1 cache but is significantly faster than L3 cache.
  • L2 cache is placed in the processor chip but outside CPU core.
  • L2 cache is linked with L1 cache which is on the CPU core.
  • L2 cache is not shared among CPU cores. It is exclusive.

Where is L2 cache located?

L2 cache is placed in the same Microprocessor Chip. In early computers around 1980s, L2 cache was placed in the motherboard which was a performance bottleneck.

Following diagram illustrates the location of L2 cache compared to L1 cache:

l2_cache

This is the case with modern computers.

In early computers, L2 cache was placed in the motherboard which is a separate component from the processor chip. The processor chip used to connect with the L2 cache while L2 cache was connected with the Main Memory (DRAM). The design of modern computer provide better performance as access time of L2 cache is significantly reduced by placing it on-chip.

L2 Cache Size

Usually, the size of L2 cache range from 8KB to 512KB. Higher the L2 cache size, Higher is the System Performance in general.

Following table lists the L2 cache size of different production systems:

L2 cache size per core
Size in KB (Kilo Byte)
Intel IceLake524 KB
Intel CooperLake1 MB
Intel CascadeLake1 MB
Intel Skylake256 KB
Intel Gracemont0.5 MB
Ryzen Threadripper 1950X512 KB
AMD Ryzen 5 Pro 3400G512 KB
AMD Ryzen 9 3950X512 KB

Check L2 Cache Size in your System

To find the total L2 Cache available in your system, use the following command in terminal:

lscpu

It will provide several information including the L2 cache size. A part of the output:

...
L2 cache: 512KB
...

So, from the above output, the size of L2 cache is 512KB.

To know how L2 cache is organized in the system along with the placement of L1 and L3 cache, use the following commands:

lstopo

OR

lstopo-no-graphics

This will give the complete Cache Infrastructure/ topology of the system. A part of the output will be like:

L3 L#1 (4MB)
    L2 L#12 (64KB) + L1d L#12 (16KB) + L1i L#12 (16KB) + Core L#12
        PU L#12 (P#12)
    L2 L#13 (64KB) + L1d L#13 (16KB) + L1i L#13 (16KB) + Core L#13
        PU L#12 (P#13)
    L2 L#14 (64KB) + L1d L#14 (16KB) + L1i L#14 (16KB) + Core L#14
        PU L#12 (P#14)
    L2 L#15 (64KB) + L1d L#15 (16KB) + L1i L#15 (16KB) + Core L#15
        PU L#12 (P#15)

So, from the above information, we see that in this particular system, a single L2 cache of size 64KB is exclusive to one CPU core only.

So, there are two L2 cache size that can be reported:

  • Total L2 cache size in system: 512KB
  • L2 cache size per core: 64KB
  • Total number of L2 caches = 512/64 = 8
  • As each CPU core has exclusive L2 cache, so number of CPU cores in system = 8.

Differences between L2 and L1, L3 cache

The Differences between L2 and L1, L3 cache are:

  • L2 cache is exclusive to a CPU core while L3 cache is shared among multiple CPU cores. L2 cache is similar to L1 cache in this aspect.
  • L2 cache size >> L1 cache size.
  • L2 cache size <<< L3 cache size.
  • L2 is located in a processor chip but outside CPU core while L1 is placed inside CPU core and L3 cache is outside processor chip.
  • L1 cache is divided into two parts: Instruction and Data. On the other hand, L2 and L3 cache are used for Data only.

Following table summarizes the differences between L1, L2 and L3 cache:

L1 vs L2 vs L3 cache
Differences between L1, L2 and L3 cache
SpeedL1 > L2 > L3
SizeL3 > L2 > L1
SharingL3 is shared among CPU cores
L1, L2 is not shared.
Data, Instruction cacheL1 is both data and instruction.
L2, L3 is only data cache
LocationL1 is in CPU core
L2: in chip, outside CPU core
L3 outside chip

Conclusion

With this article at OpenGenus, you must have a strong idea of L2 cache and how it compares to other standard cache in the system like L1 and L3 cache.

L2 cache is critical for the overall performance of system and there is constant improvement in L2 cache as Computing Devices mature.