is normal memory on aarch64 on linux outer shareable by default
- User
is normal memory on aarch64 on linux outer shareable by default
- Assistant
Okay, let's check the default shareability settings for normal memory on AArch64 Linux.
Based on the search results, particularly Linux kernel source code references and ARM documentation:
No, normal memory on AArch64 Linux is not Outer Shareable (OS) by default.
The default configuration for normal, cacheable Write-Back memory (like typical DRAM used for kernel and user space) in the Linux kernel for AArch64 is Inner Shareable (IS).
Here's a breakdown:
-
Shareability Domains: The ARM architecture defines shareability domains to manage cache coherency.
- Inner Shareable (IS): Ensures coherency among a group of processing elements (PEs), typically cores within a single processor cluster or those managed by the same OS instance.
- Outer Shareable (OS): Ensures coherency over a wider domain, potentially including multiple clusters, GPUs, or other system-level agents outside the main processor complex.
- Non-Shareable (NS): No coherency is guaranteed with other agents.
-
Linux Default (MAIR_EL1 Configuration): Linux configures the Memory Attribute Indirection Register (MAIR_EL1) to define memory types.
- Kernel source code (
proc.S,memory.h) shows that the attributeMT_NORMAL(used for standard RAM) is typically configured as Normal Write-Back Write-Allocate Cacheable, Inner Shareable. - The
TCR_EL1register, which controls translation table walks, is also configured with Inner Shareable attributes (TCR_SHAREDdefined asTCR_SH0_INNER | TCR_SH1_INNER).
- Kernel source code (
-
Why Inner Shareable? For standard operating system memory (kernel code/data, user processes running on multiple cores), coherency is primarily needed within the set of CPUs managed by that OS instance. Inner Shareable is sufficient for this and is generally expected by the architecture specifications for this use case. Using Outer Shareable unnecessarily widens the coherency domain, which can have performance implications.
-
Outer Shareable Use Cases: Outer Shareable might be used for specific memory regions, such as memory shared with external accelerators (like GPUs or DMA engines) or in certain complex multi-cluster systems, but it's not the default for general-purpose RAM. Device memory mappings might also use Outer Shareable attributes depending on the device type.
In summary, the standard Linux kernel for AArch64 defaults to Inner Shareable for normal Write-Back cacheable memory to ensure coherency between CPU cores within the typical OS-managed domain.
-
- User
where is it definied in linux?
- Assistant
Okay, the default shareability for normal memory in the Linux kernel for AArch64 is primarily established during the early boot process through the configuration of specific system registers. Here's where you can find the relevant definitions:
-
MAIR_EL1 Initialization (Primary Definition):
- File:
arch/arm64/kernel/head.Sorarch/arm64/mm/proc.S(The exact file can vary slightly depending on the kernel version and configuration, butproc.Sis common for MMU setup). - Function: Look for early assembly functions like
__cpu_setupor similar code executed very early during boot before the C environment is fully set up. - Mechanism: This code explicitly writes a value into the
MAIR_EL1(Memory Attribute Indirection Register). This register defines up to 8 memory attribute "slots". Page table entries then use a 3-bit index to select one of these slots. - Example Code Snippet (Conceptual): You'll find assembly code similar to this (macros may vary):
// Define the attributes for different memory type indices #define MAIR_ATTR_NORMAL 0xff // Normal, Inner/Outer WB, Read/Write-Allocate (implies Inner Shareable) #define MAIR_ATTR_NORMAL_NC 0x44 // Normal, Non-Cacheable #define MAIR_ATTR_DEVICE_nGnRE 0x04 // Device nGnRE // ... other attributes // Construct the MAIR_EL1 value using macros defined elsewhere (e.g., memory.h) // MAIR_ATTRIDX combines the attribute with its index (MT_*) #define MAIR_EL1_SET \ (MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL) | \ MAIR_ATTRIDX(MAIR_ATTR_NORMAL_NC, MT_NORMAL_NC) | \ MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRE, MT_DEVICE_nGnRE) | \ // ... other entries ...) __cpu_setup: // ... other setup ... mov x5, MAIR_EL1_SET msr mair_el1, x5 // Write the constructed value to MAIR_EL1 isb // ... continue setup ... - The Value
0xff: This value commonly used forMAIR_ATTR_NORMALencodes Normal Memory, Write-Back cacheable for both Inner and Outer domains, and Read-Allocate/Write-Allocate policies for both Inner and Outer domains. Crucially, for cacheable memory, the architecture implies Inner Shareable by default unless explicitly specified otherwise in the page tables themselves, and Linux relies on this default forMT_NORMAL.
- File:
-
Memory Type Index Definitions:
- File:
arch/arm64/include/asm/memory.h[[1]][[2]][[3]] - Mechanism: This header file defines symbolic names (macros) for the indices into the
MAIR_EL1register. - Example:
#define MT_NORMAL 0 // Index for Normal WB memory #define MT_NORMAL_TAGGED 1 // Index for Tagged Normal memory (MTE) #define MT_NORMAL_NC 2 // Index for Normal Non-Cacheable #define MT_DEVICE_nGnRnE 3 // Index for Device nGnRnE #define MT_DEVICE_nGnRE 4 // Index for Device nGnRE // ... (Indices might vary slightly across kernel versions) - Note that
memory.hdefines the index, while the actual attributes (including shareability) for that index are programmed intoMAIR_EL1via the assembly code mentioned above.
- File:
-
Page Table Entry Definitions:
- File:
arch/arm64/include/asm/pgtable-prot.handarch/arm64/include/asm/pgtable-hwdef.h - Mechanism: These files define the structure and bit meanings within page table entries (PTEs). Standard page protection macros (
PAGE_KERNEL, etc.) are built using these definitions. - Shareability Bit: While
MAIR_EL1sets the potential attributes, the page table entry itself contains shareability bits (SH[1:0]). For standard kernel mappings (PAGE_KERNEL), the default attributes derived fromMAIR_EL1(usingMT_NORMAL) are used, and the PTE's SH bits are typically set toPTE_SHAREDwhich is defined as Inner Shareable (PTE_ATTRVAL(3, PTE_ATTR_SH)where 3 means Inner Shareable).// From pgtable-hwdef.h (conceptual) #define PTE_ATTR_SH_SHIFT 8 #define PTE_ATTR_SH_MASK (_AT(pteval_t, 3) << PTE_ATTR_SH_SHIFT) #define PTE_ATTR_SH(x) (_AT(pteval_t, x) << PTE_ATTR_SH_SHIFT) #define PTE_ATTR_INNER_SHAREABLE PTE_ATTR_SH(3) // Value 0b11 for Inner Shareable // From pgtable-prot.h (conceptual) #define PTE_SHARED PTE_ATTR_INNER_SHAREABLE // Default for shared mappings #define PAGE_KERNEL __pgprot(_PAGE_DEFAULT | PTE_SHARED | PTE_UXN | PTE_PXN | PTE_FLAGS_DEVKMAP)
- File:
-
Translation Control Register (TCR_EL1) Configuration:
- File: Usually also in
arch/arm64/mm/proc.Sorarch/arm64/kernel/head.S. - Mechanism: The
TCR_EL1register controls aspects of the MMU translation process itself, including the shareability attribute applied during translation table walks. Linux configures this also for Inner Shareable (TCR_SH0_INNER,TCR_SH1_INNER). This ensures coherency when the MMU is reading page tables, consistent with the main memory being Inner Shareable. - Example:
// Define TCR flags (often in a header included by proc.S/head.S) #define TCR_SH0_INNER (UL(3) << TCR_SH0_SHIFT) // Inner Shareable for TTBR0 walks #define TCR_SH1_INNER (UL(3) << TCR_SH1_SHIFT) // Inner Shareable for TTBR1 walks #define TCR_SMP_FLAGS (TCR_SH0_INNER | TCR_SH1_INNER) // Combine shareability flags // In __cpu_setup or similar ldr x10, =<calculated_tcr_value_including_tcr_smp_flags> msr tcr_el1, x10 isb ```[[4]]
- File: Usually also in
In summary, the default Inner Shareable attribute for normal memory originates from the value programmed into
MAIR_EL1for theMT_NORMALindex slot during early boot (inhead.Sorproc.S), reinforced by the default page table entry flags (PTE_SHARED) defined in headers and the configuration ofTCR_EL1for table walks. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.