L1 Cache (Level 1)

In this article, we have covered the idea of L1 Cache (Level 1) in depth and compared it with other standard caches like L2 and L3 cache.

Table of contents:

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

What is L1 cache?

L1 cache is the fastest cache is a Computing system. It is exclusive to a CPU core and is also, the smallest cache in terms of size. L1 cache is of two types:

  • Instruction Cache
  • Data Cache

Instruction Cache of L1 Cache is denoted as L1i. It is equal to or double of Data Cache of L1 Cache.

Data Cache of L1 Cache is denoted as L1d. It is either equal to or half of Instruction Cache of L1 Cache.

Total size of L1 Cache = Size of L1i + Size of L1d

L1 cache is made of Static Random Access Memory (SRAM) which is expensive and fast memory compared to DRAM.

Where is L1 cache located?

L1 cache is placed together with a CPU core within a Microprocessor Chip.

Following diagram illustrates the location of L1 cache compared to L2 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.

As L1 cache is closer to CPU core, it is the fastest cache in the system.

L1 Cache Size

Usually, the size of L1 cache range from 16KB to 64KB. Higher the L1 cache size, Higher is the System Performance in general.

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

L1 cache size per core
Size in KB (Kilo Byte)Instruction cacheData Cache
Intel IceLake32 KiB48 KiB
Intel CooperLake32 KB32 KB
Intel CascadeLake32 KB32 KB
Intel Skylake32 KB32 KB
Intel Gracemont64 KB32 KB
Ryzen Threadripper 2990WX64 KB32 KB
Ryzen 5 3600XT32 KB32 KB
AMD Ryzen 9 5980HX32 KB32 KB

Note: In few systems, the size of Instruction Cache is more than the size of Data Cache while the common practice is to keep the two types of same size only.

Check L1 Cache Size in your System

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

lscpu

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

...
L1 cache: 128KB
...

So, from the above output, the size of L1 cache is 128KB.

To know how L1 cache is organized in the system along with the placement of L2 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 L1 cache of size 16KB is exclusive to one CPU core only.

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

  • Total L1 cache size in system: 128KB (using lscpu)
  • L1 cache size per core: 16KB (using lstopo)
  • Total number of L1 caches = 128/16 = 8
  • As each CPU core has exclusive L1 cache, so number of CPU cores in system = 8.

Differences between L1 and L2, L3 cache

The Differences between L1 and L2, L3 cache are:

  • L1 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.
  • L1 cache size << L2 cache size. L2 cache is 4 to 8 times of L1 cache.
  • L1 cache size <<<<< L3 cache size. L2 cache is 16 to 32 times of L2 cache. So, L3 cache is 64 to 256 times of L1 cache.
  • L1 is placed inside CPU core while L2 is located in a processor chip but outside CPU core. 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 the complete idea of L1 cache in depth. It is the most critical cache among L1, L2 and L3 cache.