CPU cache
The CPU caches are built into the CPU. You can not upgrade it.
- Level 1: 16kB instruction, 16kB Data.
- Level 2: 512kB shared.
- Level 3: None (some architectures have this external)
Other caches
There are other caches
Disk/ssd cache.
- The drive will have some sort of built in cache. You don't care about this, only what its spec is.
- The OS will implement a disk cache using RAM. It usually knows what is best, so leave it alone. The only time I have had to mess with it. Is when copying large files, I tell it to not cache, as I am not going to read the files any time soon. You can do this by doing
nocache command …
. There are also kernel parameters that you can tune, but you better know how to measure your changes, or you will probably make it worse.
Network cache.
- The OS will use disk/ssd to cache web access.
- You can cache dns lookup, but not installed by default.
What is cpu cache
A program will run from RAM, however RAM is slower than the CPU. Therefore a cache is added. It is the same speed as the CPU. It remembers recent RAM accesses and will give the CPU the data quicker that the RAM can. Because the cache is expensive, it is small. Therefore the cache will forget stuff, when it does, the CPU has to get the data from the RAM (this is slower). Everything in cache is a copy of what is in RAM. The caches job is to make RAM seem faster. It succeeds most of the time (≈80%), because in most programs the same data is access more than once, and usually clustered in time and space.
A note on swap
Cache is NOT swap. It is very different.
(Modern OSs use paging, not swap. However the differences are inconsequential for the purpose of this discussion.)
While RAM is slower than cache and the CPU. It is faster than SSD and Disk. And while RAM is much bigger than cache, it is much smaller than SSD and Disk.
It get around the smallness of RAM, the OS will swap/page the content of parts of the RAM into the swap area of disk. Now that the disk knows the content, it can be erased from RAM, and this bit of RAM used for something else.
Key differences between cache and swap/paging
- Cache is smaller that the thing it is caching, a cache is used to allow faster running. A CPU cache makes RAM appear faster (It does not make the RAM appear smaller).
- Swap/paging is slow, it is used to make RAM appear bigger (but slower, but not by much, if the data is not being swapped in and out, and in and out and …).
htop
to see your actual RAM layout? If so, a screenshot showing the cituation would help attract answers.