dmesg 中的 BIOS-e820 - 如何从地址计算内存范围

dmesg 中的 BIOS-e820 - 如何从地址计算内存范围
kp@localhost ~]$ sudo dmesg | grep -i "e820"

产生以下输出:

[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000000a0000-0x00000000000fffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x0000000009d7ffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000009d80000-0x0000000009ffffff] reserved
[    0.000000] BIOS-e820: [mem 0x000000000a000000-0x000000000a1fffff] usable
[    0.000000] BIOS-e820: [mem 0x000000000a200000-0x000000000a209fff] ACPI NVS
[    0.000000] BIOS-e820: [mem 0x000000000a20a000-0x000000000affffff] usable
[    0.000000] BIOS-e820: [mem 0x000000000b000000-0x000000000b01ffff] reserved
[    0.000000] BIOS-e820: [mem 0x000000000b020000-0x00000000dd082fff] usable
[    0.000000] BIOS-e820: [mem 0x00000000dd083000-0x00000000dd1ebfff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000dd1ec000-0x00000000dd36dfff] usable
[    0.000000] BIOS-e820: [mem 0x00000000dd36e000-0x00000000dd781fff] ACPI NVS
[    0.000000] BIOS-e820: [mem 0x00000000dd782000-0x00000000de65afff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000de65b000-0x00000000deffffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000df000000-0x00000000dfffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000f8000000-0x00000000fbffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fd100000-0x00000000fdffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fea00000-0x00000000fea0ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000feb80000-0x00000000fec01fff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fec10000-0x00000000fec10fff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fec30000-0x00000000fec30fff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fed00000-0x00000000fed00fff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fed40000-0x00000000fed44fff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fed80000-0x00000000fed8ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fedc2000-0x00000000fedcffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fedd4000-0x00000000fedd5fff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000feefffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000ff000000-0x00000000ffffffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000021f37ffff] usable

例如,我想了解计算 [mem 0x0000000100000000-0x000000021f37ffff] 表示的实际内存范围的技术。

我在一些教程中发现 0x100000000 代表 4GiB,0x3ffffffff 代表 16GiB。但我无法推导出它的工作方式!

答案1

这些是十六进制值。您可以使用程序员的计算器甚至 Bash 将它们转换为十进制:

echo $((0x100000000))

要转换为兆字节或千兆字节,请相应地除以:

$ echo $((0x100000000/1024/1024))
4096
$ echo $((0x21f37ffff/1024/1024))
8691

因此0x100000000确实是4GiB,而0x21f37ffff接近8.5GiB(8704MiB),所以0x0000000100000000-0x000000021f37ffff是从4GiB到接近8.5GiB的范围。

相关内容