Search code examples
linuxcachingmemorymemory-managementoperating-system

Page cache vs L1 cache?


I was reading: https://en.wikipedia.org/wiki/Page_cache

In computing, a page cache, sometimes also called disk cache,[1] is a transparent cache for the pages originating from a secondary storage device such as a hard disk drive (HDD) or a solid-state drive (SSD). The operating system keeps a page cache in otherwise unused portions of the main memory (RAM), resulting in quicker access to the contents of cached pages and overall performance improvements.

Isn't there a similar technique for portions of RAM that are accessed frequently to be saved in L1, L2 and L3 caches to improve performance?

I don't get what kind of information in saved there, what cache?


Solution

  • Yes, those are known as hardware/CPU caches. They store "cache lines" which are usually 64 bytes and are pieces of memory pulled from RAM and stored for closer/faster access for the CPU. This is usually behind the scenes, since its handled in hardware, you generally can't modify it nor does the OS have direct access to its contents. However, you can flush the contents using flush_cache_ family of functions.

    The purpose of the page cache is similar: to speed up future accesses by storing memory that might be used soon. It deals with memory pages of size 4KB, normally, and holds memory loaded in from disk onto RAM. It is an OS-level cache. The Linux kernel has complete control over how the page cache works, which you can modify yourself in the source code. Take a look at this discussion if you want to know more about what is stored in the page cache.