</>EmbeddedInterview

What are memory types and shareability domains in the Arm architecture?

HardMicrocontrollers & ARM Cortex-M

Short answer: Arm classifies memory into Normal memory (RAM, ROM: accesses may be cached, merged, reordered and speculated) and Device memory (peripherals: accesses must not be speculated or merged and keep order, with sub-types nGnRnE, nGnRE, nGRE, GRE describing what is allowed). Shareability describes which observers (cores, DMA masters) must see a coherent view of a Normal memory location: Non-shareable (one core only), Inner Shareable (typically all cores in the cluster/system that run the same OS), and Outer Shareable (also other masters such as GPUs or DMA on a coherent interconnect). Barriers and cache maintenance instructions take a shareability domain argument.

Memory types

Type Caching Reordering / merging / speculation Use
Normal, write-back cacheable yes allowed RAM for code and data
Normal, non-cacheable no reordering and merging allowed DMA buffers without coherency, frame buffers
Device-nGnRnE no none (no Gathering, no Reordering, no Early write ack) strongly ordered registers
Device-nGnRE no early write acknowledgement allowed most peripheral registers (Linux ioremap())
Device-GRE no gathering and reordering allowed rarely: e.g. some write-combining buffers

Attributes are set in page-table entries via MAIR_ELx indexes (Cortex-A) or MPU attributes (Cortex-M/R).

Shareability domains in practice

  • On a 4-core Cortex-A53 cluster running Linux, all normal memory is mapped Inner Shareable, and the SCU keeps the cores' caches coherent automatically.
  • A barrier such as DMB ISH orders accesses as seen by all cores in the inner shareable domain; DMB OSH extends to the outer domain (e.g. for coherent DMA masters); DMB SY is the full system.
  • TLB invalidation TLBI ...IS broadcasts to all cores in the inner shareable domain.
  • Linux maps its smp_mb() to DMB ISH, while mb()/dma_mb() use DMB SY/OSH variants because they must also order accesses with devices.

Why it exists: making every operation globally coherent and ordered would be slow. Shareability lets software request coherency and ordering only as far as needed: a core-private variable needs nothing, shared data between cores needs inner shareable, and data shared with devices needs outer or full-system scope.

Interview angle: "Why does your DMA buffer work only with dma_alloc_coherent?" Because that maps it non-cacheable (or uses hardware coherency), while a normal cacheable mapping requires explicit maintenance before the device sees it.