7

I have a laptop with an Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz processor. I'm on Ubuntu 12.04 (x86_64) and I'm trying to find some info about my processor.

I was able to find most of the information I was looking for using

cat /proc/cpuinfo

and

lscpu

What I want to also find out is the cache policy that is used on each cache level. Is it write back or write through?

Is there any tool that I can use to find out such info?

Thanks in advance.

feugatos
  • 663
  • 6
  • 15
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jun 04 '18 at 20:02
  • You can often look up your CPU specs on [Intel ARK](https://ark.intel.com/). It is Intel's website for product specifications. – jww Jun 04 '18 at 20:03
  • Also it's called memory type not cache policy. Cache policy is whether reads/writes are cached, whether they are allocated and how lines are evicted (replacement policy) and whether writes update memory and the placement policy (direct-mapped, fully associative, and set-associative etc.). The cache coherence protocol is MESI(F) etc. – Lewis Kelsey Apr 28 '21 at 18:25

2 Answers2

9

This is not something you can query from CPUID or such, nor can you configure your CPU to do one or the other, thus there exists no tool for querying. What you can query is the cache associativity, the cache line size, and the cache size, for example via /proc/cpuinfo.

All Intel-compatible CPUs during the last one/two decades used a write-back strategy for caches (which presumes fetching a cache line first to allow partial writes). Of course that's the theory, reality is slighly more complex than that.

Virtually all processors (your model included) have one or several forms of write combining (or fill buffers as Intel calls it since Merom), and all but the most antique Intel-compatible CPUs support uncached writes from SSE registers (which again uses a form of write-combining). And then of course, there are things like on-chip cache coherence protocols and snoop filtering and other mechanisms to ensure cache coherency both between cores of one processor and between different processors in a multi-processor system.
Nevertheless -- the general cache policy is still write-back.

Damon
  • 67,688
  • 20
  • 135
  • 185
  • Thanks for you answer Damon. I'm running some tests on MATLAB and the professor asked us to find the cache policy of the CPU we will be running the tests on, if we could. I did some searching but I wasn't able to find anything, that's why I asked. – feugatos Oct 08 '12 at 21:34
  • 2
    AMD Bulldozer-family CPUs *don't* use write-back caches. see my answer. – Peter Cordes Dec 07 '15 at 21:31
  • @PeterCordes: Thank you for pointing this out. I was about to buy a new notebook, incidentially with an AMD Bulldozer processor. What you say is a compelling reason to abstain from doing so. – Damon Dec 08 '15 at 10:42
  • 2
    Update on that: Bulldozer-family L2 is write-back. It's only L1D that's write-through with a small write-combining buffer. In Ryzen, all the caches are write-back, but each cluster of 4 cores has a separate L3. (I just updated my answer with some links, and to point out that there's more to a cache hierarchy than write-back vs. write-through, especially for multi-threaded code.) – Peter Cordes Jul 03 '17 at 02:51
8

David Kanter's very nice Intel Sandybridge writeup covers the memory subsystem and cache architecture: L1D is the usual-for-Intel write-back, and the per-core L2 is also write-back. So is L3 (which is a large inclusive cache shared by all cores on the chip).

See also Which cache mapping technique is used in intel core i7 processor? for lots more detail about various generations of Intel CPUs.


AMD takes a very different approach: Their L1 cache is write-through, but with a tiny 4k write-combining-cache. Constantly rewriting a buffer larger than 4k on AMD will bottleneck on the (slow) L2 instead of L1.

One of the posters in that thread on Agner's blog claims that BD's L2 is also write-through, but Paul Clayton's comments on this answer disagrees. (I'm inclined to believe Paul.)

AMD Ryzen fortunately uses a normal write-back 32kiB 8-way L1D, with private write-back 512kiB L2. L3 is a shared 8MB victim cache. It's write-back, but victim-cache means data only enters it when evicted from L1/L2, not directly for loads / prefetches. Each core-cluster (CCX module) of 4 cores has its own 8MB L3, and latency/bandwidth between cores in different clusters is bad.

There's much more to say about a cache hierarchy than just write-back vs. write-through, although most of the differences don't matter for single-threaded programs. (Unless the OS's process scheduler moves them between clusters on Ryzen, in which case it's bad.)


On my SnB system:

sudo dmidecode

produces output which includes:

Handle 0x0005, DMI type 7, 19 bytes
Cache Information
        Socket Designation: L1-Cache
        Configuration: Enabled, Not Socketed, Level 1
        Operational Mode: Write Back
        Location: Internal
        Installed Size: 32 kB
        Maximum Size: 32 kB
        Supported SRAM Types:
                Other
        Installed SRAM Type: Other
        Speed: Unknown
        Error Correction Type: None
        System Type: Unified
        Associativity: 8-way Set-associative

So the fact that the cache is Write-Back is at least in the BIOS, if that's trustworthy. I'm curious what it shows on an AMD CPU, or if BIOS writers tend to just "make something up" and sometimes put the wrong value there.

As this question points out, info for L2 is kinda bogus: it totals the private 256k-per-core L2:

Handle 0x0006, DMI type 7, 19 bytes
Cache Information
        Socket Designation: L2-Cache
        Configuration: Enabled, Not Socketed, Level 2
        Operational Mode: Varies With Memory Address
        Location: Internal
        Installed Size: 1024 kB
        Maximum Size: 1024 kB
        Supported SRAM Types:
                Other
        Installed SRAM Type: Other
        Speed: Unknown
        Error Correction Type: None
        System Type: Unified
        Associativity: 8-way Set-associative

Handle 0x0007, DMI type 7, 19 bytes
Cache Information
        Socket Designation: L3-Cache
        Configuration: Enabled, Not Socketed, Level 3
        Operational Mode: Unknown
        Location: Internal
        Installed Size: 6144 kB
        Maximum Size: 6144 kB
        Supported SRAM Types:
                Other
        Installed SRAM Type: Other
        Speed: Unknown
        Error Correction Type: None
        System Type: Unified
        Associativity: Other

This is on an i5-2500k (quad core SnB with 6MiB of L3)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    Bulldozer L2 is **not** write-through but write-back. IBM's zSeries — not that there are laptops using such processors! — (such as the [z196 described by David Kanter](http://www.realworldtech.com/z196-mainframe/7/), which does have a write-through L2) tend to use write-through aggressively. –  Dec 08 '15 at 13:25
  • update on that: Bulldozer's L1d (not L2) is write-through, with a small 4k write-combining buffer. – Peter Cordes Oct 03 '21 at 10:26