Expand description
Parsing of the physical memory map provided by /proc/iomem
.
The /proc/iomem
file exposes the kernel’s resource tree and thus a map of
physical memory to user space, making it very useful for gracefully reading
specific regions of memory from /dev/mem
.
§Background
The Linux kernel maintains a resource tree with the memory address ranges allocated to every resource (RAM, devices, and so on).
The first additions to this tree are made during early boot when the system
firmware supplies its initial memory map to the kernel via E820 (BIOS) or
GetMemoryMap() (UEFI). The kernel will practically always modify this map
further (based on known quirks or custom memmap
overrides, for instance)
before registering its specified memory regions in the tree.
Additional address ranges are allocated for device MMIO, so the tree will
contain not just entries for the above memory map (with ACPI Address Range
Types such as Reserved
) but also more arbitrarily named devices (such as
IOAPIC 0
or PCI Bus <ID>
).
§Excerpt of /proc/iomem
Notice how the address range names include both human-readable ACPI types and MMIO devices.
00000000-00000fff : Reserved // Real-Mode Address Space (< 1 MiB)
00001000-0009efff : System RAM
0009f000-0009ffff : Reserved
000e0000-000fffff : Reserved
000a0000-000effff : PCI Bus 0000:00
000f0000-000fffff : System ROM
00100000-09bfffff : System RAM // Extended Memory (> 1 MiB)
[~]
cad7e000-cbd7dfff : ACPI Non-volatile Storage
cbc37000-cbc37fff : USBC000:00
cbd7e000-cbdfdfff : ACPI Tables
[~]
fc000000-fdffffff : PCI Bus 0000:00
[~ Other devices on the PCIe bus ~]
fd900000-fd9fffff : PCI Bus 0000:01
fd900000-fd903fff : 0000:01:00.0
fd900000-fd903fff : nvme
fdf00000-fdf7ffff : amd_iommu
feb00000-feb00007 : SB800 TCO
fec00000-fec003ff : IOAPIC 0
[~]
100000000-72e2fffff : System RAM
38a400000-38b7fffff : Kernel code
38b800000-38c532fff : Kernel rodata
38c600000-38c88cf7f : Kernel data
38d20e000-38d5fffff : Kernel bss
Structs§
- Memory
Region - A region in physical memory as indicated in the memory map.
Enums§
- Memory
Region Type - The types of memory address ranges distinguished by the kernel.
- Parse
Error
Functions§
- parse_
iomem_ map - Parse the given
iomem
-style memory map to a vector ofMemoryRegion
s. - parse_
proc_ iomem - Directly read and parse
/proc/iomem
to a vector ofMemoryRegion
s.