Linux

dmesg 中的 BIOS-e820 - 如何根據地址計算記憶體範圍

  • December 15, 2019
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。但我無法推導出它的工作方式!

這些是十六進制值。您可以使用程序員的計算器甚至 Bash 將它們轉換為十進制:

echo $((0x100000000))

要轉換為兆字節或千兆字節,請相應地劃分:

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

因此 0x100000000 確實是 4GiB,而 0x21f37ffff 接近 8.5GiB(8704MiB),所以 0x0000000100000000-0x000000021f37ffff 是從 4GiB 到接近 8.5GiB 的範圍。

引用自:https://unix.stackexchange.com/questions/557368