I understand that caches are the smallest and fastest memory that is integrated into the CPU. However, what I am confused about is the information that it holds. From what I know, the capabilities of cache are:

L1 cache - 64KB L2 cache - 256KB L3 cache - 4-12 MB Ram - 4-74 GB

For example: If I open up a page on the browser, what sort of data goes into the L1, L2, and L3 cache and maybe the RAM too. Does the L1 cache try to fill in as much reusable data as possible and if it's full then the remaining goes to the L2 cache and so on? Is the data that it holds like images or words ?

I can't seem to understand so any help would be much appreciated.

  • $\begingroup$ Interpretation of data is up to a program. Convenient about (data) caches is a program/coder does not need to do anything special to profit from caching. Explicit interaction of a program with what gets cached is limited, if that, and architecture dependent. Annoyingly, "data layout"&usage patterns interact with the memory hierarchy. A program can strive to be cache oblivious. $\endgroup$
    – greybeard
    Jun 23, 2022 at 5:22
  • $\begingroup$ It's the most recently accessed data. Don't overthink it. The program does not know what is in the cache (smart programmers can try to optimize it but they don't have direct control). The program acts the exact same no matter what is in the cache. It can't say "put the webpage in L1". It's just faster if the right things get cached. $\endgroup$
    – user253751
    Jun 23, 2022 at 9:02

2 Answers 2


L1 cache: Every time you access any data, either it is in L1 cache already, or one cache line worth of data (often 32 or 64 byte) is read from the next level, and stored into L1 cache. If necessary, the data that was stored in that cache line is removed, and if it was modified, it is first written to the next level of data.

Same with L2 cache; if data is not in L1 cache, then either it is already in the L2 cache, or it is read from the next level in exactly the same way. Same with L3 cache. On processors where CPUs and GPUs access the same memory, there is often another cache level between CPU / GPU and memory. So what exactly is in the various caches changes all the time.

Sometimes the programmer knows that putting data into cache is not worth it. For example, if I need to process one GB of data sequentially, which is much more than any cache, it is pointless to store the data into any higher level caches, because it will never be reused. For this reason, some processors have instructions to read data but not putting it into L2 or L3 cache.

And some processors have "streaming" instructions: If you know that you are accessing sequential data, once you read data at location x, the processor guesses that you will read data at the following cache line after this, so it starts reading data from memory and putting it into the cache before it is used. Sometimes it isn't used at all.

  • $\begingroup$ from a question, it seems he isn't a programmer, so he just needs to learn what cache is (he thinks that this memory is manually managed) $\endgroup$
    – Bulat
    Jun 22, 2022 at 21:22
  • $\begingroup$ This answer answer exactly the question. $\endgroup$
    – gnasher729
    Jun 23, 2022 at 16:15

The answer is that almost all the data that the CPU works on ends up in various levels of the cache. It's not like text goes into L4, and images go into L3, audio into L2 and video into L1.

The memory controller in the CPU will manage the data in the cache, moving it between levels according to various rules of thumb that the CPU designers have decided seem to work well.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.