Skip to content
The Chat Archive
gemini-2.5-pro-exp-03-25-grounding· Google LMArena Search Arena 24K

is normal memory on aarch64 on linux outer shareable by default

  1. User

    is normal memory on aarch64 on linux outer shareable by default

  2. 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:

    1. 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.
    2. 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 attribute MT_NORMAL (used for standard RAM) is typically configured as Normal Write-Back Write-Allocate Cacheable, Inner Shareable.
      • The TCR_EL1 register, which controls translation table walks, is also configured with Inner Shareable attributes (TCR_SHARED defined as TCR_SH0_INNER | TCR_SH1_INNER).
    3. 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.

    4. 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.

  3. User

    where is it definied in linux?

  4. 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:

    1. MAIR_EL1 Initialization (Primary Definition):

      • File: arch/arm64/kernel/head.S or arch/arm64/mm/proc.S (The exact file can vary slightly depending on the kernel version and configuration, but proc.S is common for MMU setup).
      • Function: Look for early assembly functions like __cpu_setup or 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 for MAIR_ATTR_NORMAL encodes 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 for MT_NORMAL.
    2. 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_EL1 register.
      • 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.h defines the index, while the actual attributes (including shareability) for that index are programmed into MAIR_EL1 via the assembly code mentioned above.
    3. Page Table Entry Definitions:

      • File: arch/arm64/include/asm/pgtable-prot.h and arch/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_EL1 sets the potential attributes, the page table entry itself contains shareability bits (SH[1:0]). For standard kernel mappings (PAGE_KERNEL), the default attributes derived from MAIR_EL1 (using MT_NORMAL) are used, and the PTE's SH bits are typically set to PTE_SHARED which 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)
        
    4. Translation Control Register (TCR_EL1) Configuration:

      • File: Usually also in arch/arm64/mm/proc.S or arch/arm64/kernel/head.S.
      • Mechanism: The TCR_EL1 register 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]]
        

    In summary, the default Inner Shareable attribute for normal memory originates from the value programmed into MAIR_EL1 for the MT_NORMAL index slot during early boot (in head.S or proc.S), reinforced by the default page table entry flags (PTE_SHARED) defined in headers and the configuration of TCR_EL1 for table walks.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.