- Management of physical pages in the memory
- Buddy system to assign memory in large chunks
- Slab, slub, and slob allocators to assign smaller chunks of memory
- vmalloc mechanism to assign noncontiguous blocks of memory
- Address space of the processes
/proc file system
The/proc file system provides the following files:
/proc/meminfo
This file provides information about distribution and usage of memory.- To view the contents of this file, run the following command:
Sample output:
/proc/vmstat
This file shows detailed virtual memory statistics from the kernel. Most of the statistics are available only if you enable theCONFIG_VM_EVENT_COUNTERS option in the init/Kconfig file.
- To view the contents of this file, run the following command:
Sample output:
/proc/iomem
This file shows the memory map of the system for its various device drivers.- To view the contents of this file, run the following command:
Sample output:
/proc/vmallocinfo
This file shows detailed information about virtual address allocation throughvmalloc or ioremap.
- To view the contents of this file, run the following command:
Sample output:
memblock interface
Thememblock interface on the debugfs file system provides details about the available and reserved memory regions in the system. This interface provides the following files:
/sys/kernel/debug/memblock/memory
This file provides information about all the available memory regions (HLOS and non-HLOS) visible to the Linux kernel. To determine the overall memory accessible to the kernel, calculate the difference between the start and end addresses of each of the region and sum these values to get the total occupied RAM. The remaining memory, which is the difference between the RAM size of the device and the occupied RAM, is the non-HLOS memory or the memory occupied by other subsystems.-
To view the contents of this file, run the following command:
Sample output:
/sys/kernel/debug/memblock/reserved
This file provides information about all the reserved memory regions in the system.- To view the contents of this file, run the following command:
Sample output:
Debug memory leak issues
To debug kernel memory leak issues, enable the following configuration options:CONFIG_DEBUG_KMEMLEAK=yCONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=4000CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=y
KMEMLEAK option at boot time by passing KMEMLEAK=off on the kernel command line.
For more information about the kmemleak.txt file, see kernel documentation.
The following extra kernel configuration options are available to track the allocator of each page of memory:
CONFIG_PAGE_OWNERCONFIG_PAGE_OWNER_ENABLE_DEFAULTCONFIG_PAGE_EXTENSION
Identify memory corruption issues
Enable the following kernel configuration options to identify memory corruption issues:CONFIG_PAGE_POISONINGCONFIG_SLUB_DEBUG_ONCONFIG_DEBUG_LISTCONFIG_SLUB_DEBUG
Documentation/vm/slub.txt file available in the kernel documentation.
Out of memory
When the system fails to assign a page, the kernel logs display a message such as the following:- order: Indicates the size of the page. In this example, 2 2 x PAGE_SIZE (4 K) = 16 K
- Linux uses a buddy allocator that allocates pages in powers of 2.
- The maximum size of the buddy allocator is the order of 10 = 2 10 x 4 kB = 4 MB.
- For allocation > 4 MB, use an alternate allocation method such as the contiguous memory allocator (CMA).
- For failure of higher-order allocations, examine whether the memory can be virtually contiguous, instead of being physically contiguous.
- Linux uses a buddy allocator that allocates pages in powers of 2.
- mode: Indicates the type of page requested
modeprovides information about get free pages (GFP) flags. In this example,modeis0x10d2.modeis the result of OR operation on all the GFP flags in the allocation.
- Pages available in the system A page allocation failure message prints details about the size of pages that were available in the system.
IOMMU page fault
Input-output memory management unit (IOMMU), also known as the system memory management unit (SMMU), performs memory management functions on behalf of subsystems that don’t have their own MMU. The IOMMU hardware block allows physically noncontiguous pages to support virtually contiguous memory. The memory translation logic in the IOMMU is the same as the logic in the CPU MMU. The IOMMU page fault is the most common IOMMU issue. The fault occurs when the requested page is mapped in the page table but isn’t found in the memory. The fault handler receives the context bank instance of the IOMMU and dumps the registers for this context. The following log indicates an IOMMU page fault.| Item | Description |
|---|---|
name | Name of the hardware block that caused the fault. |
FAR | Fault address register (FAR) indicates the address at which the fault occurred. |
FSR | Fault status register (FSR) indicates the following: |
The FSR is one of the most important registers in IOMMU debugging. This register has read/write-clear access. The read operation on this register reads the value in the register while the write operation clears the bits corresponding to 1s in the written data and leaves the bits corresponding to 0s unchanged. This process prevents inadvertent clearing of new faults when writing the register to clear an old fault. Some useful bits in this register are: Table: Bits in fault status register
- Translation fault (TF)
- Access permission fault (APF)
- Stalled status (SS)
| Bit | Description |
|---|---|
[Bit 1]: TF | Translation fault (invalid page table entry) |
[Bit 2]: AFF | Access fault |
[Bit 3]: APF | Permission fault (write to read only region) |
[Bit 4]: TLBMF | TLB miss fault |
[Bit 5]: HTWDEEF | Hardware table walk decode error external fault |
[Bit 6]: HTWSEEF | Hardware table walk subordinate error external fault |
[Bit 7]: MHF | Many hits in TLB |
[Bit 16]: SL | Second-level fault (fault occurred in second level of page table) |
[Bit 30]: SS | Stalled status |
[Bit 31]: MULTI | Multiple faults |
TF, APF, and SL flags indicate normal operation, whereas the TLBMF, HTWDEEF, HTWSEEF, and MHF flags indicate that there is an issue.
IOMMU page table
The IOMMU page table dump provides a faulting address from the FAR and the register dump in the kernel log. This faulting address represents the virtual address, and you can acquire the corresponding physical address from the page table. From the page table dump, you can identify whether the requested address is mapped or not mapped. Each IOMMU domain has a page table, and the dump includes page tables for each of the domains. Currently, there are six domains. The following is the sample dump of theDomain: 2 page table.
Memory map
For more information about the memory map, see the latest Release Notes.Stack corruption
Wrong coding logic accesses memory locations in the stack, leading to changes in values at those memory locations, causing stack corruption. Stack corruption can occur in the following ways:- Due to bad code logic, the program consumes all the stack memory and writes memory beyond the stack boundaries, resulting in a stack overflow.
- Accessing an array that’s out of bounds.
- An undefined or freed pointer that points at a stack address.
- Corrupted return address of a caller function.
CONFIG_STACKPROTECTORCONFIG_STACKPROTECTOR_STRONG

