Friday, June 20, 2025

How MMU and Cache Work Together ?


  1. MMU Translates Virtual Address → Physical Address

    • Every memory access from the CPU (in virtual address space) goes through the MMU.

    • It uses page tables to resolve Virtual Address (VA) → Physical Address (PA).

  2. MMU Provides Memory Attributes

    • In addition to translation, the MMU tells the CPU:

      • Is this region cacheable?

      • Should it be write-back, write-through, or non-cacheable?

      • Is it device memory or normal memory?

  3. Cache Uses MMU Info to Decide Behavior

    • If a region is cacheable, cache stores/fetches data for that region.

    • If non-cacheable, all accesses go directly to RAM (or MMIO).

    • MMU attributes control whether cache is used at all.



Example Flow (ARM Cortex-A CPU):

Load [VA = 0xFFFF0000] ↓ MMU: - Translates to PA = 0x10000000 - Checks page tables → memory type = normal, inner-cacheable, write-back ↓ Cache: - Checks if PA = 0x10000000 is in L1/L2 - If hit → return cached data - If miss → fetch from RAM, store in cache











This is why bootloaders and OS kernels carefully configure MMU
and cache together.




No comments:

Post a Comment