我想在启动 Linux 时保留一部分物理内存。在 Zedboard 上运行默认 RISC-V 内核时,我看到物理内存的大小为 254MB(0xfe00000 字节,260096K):
INSTRUCTION SETS WANT TO BE FREE
[ 0.000000] Linux version 3.14.33-g043bb5d (guanglin@guanglin-a11-linux) (gcc version 5.2.5
[ 0.000000] Detected 0xfe00000 bytes of physical memory
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x00200000-0x0fffffff]
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x00200000-0x0fffffff]
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 64135
[ 0.000000] Kernel command line: root=/dev/htifblk0
[ 0.000000] PID hash table entries: 1024 (order: 1, 8192 bytes)
[ 0.000000] Dentry cache hash table entries: 32768 (order: 6, 262144 bytes)
[ 0.000000] Inode-cache hash table entries: 16384 (order: 5, 131072 bytes)
[ 0.000000] Sorting __ex_table...
[ 0.000000] Memory: 253568K/260096K available (1722K kernel code, 124K rwdata, 356K rodata)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] NR_IRQS:2
[ 0.150000] Calibrating delay using timer specific routine.. 20.01 BogoMIPS (lpj=100072)
[ 0.150000] pid_max: default: 32768 minimum: 301
[ 0.150000] Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
[ 0.150000] Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes)
[ 0.150000] devtmpfs: initialized
[ 0.150000] NET: Registered protocol family 16
[ 0.150000] bio: create slab <bio-0> at 0
[ 0.150000] Switched to clocksource riscv_clocksource
[ 0.150000] NET: Registered protocol family 2
[ 0.150000] TCP established hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.150000] TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.150000] TCP: Hash tables configured (established 2048 bind 2048)
[ 0.150000] TCP: reno registered
[ 0.150000] UDP hash table entries: 256 (order: 1, 8192 bytes)
[ 0.150000] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[ 0.150000] NET: Registered protocol family 1
[ 0.150000] futex hash table entries: 256 (order: 0, 6144 bytes)
[ 0.150000] io scheduler noop registered
[ 0.150000] io scheduler cfq registered (default)
[ 0.170000] htifcon htif1: detected console
[ 0.170000] console [htifcon0] enabled
[ 0.170000] htifblk htif2: detected disk
[ 0.170000] htifblk htif2: added htifblk0
[ 0.170000] TCP: cubic registered
[ 0.180000] VFS: Mounted root (ext2 filesystem) readonly on device 254:0.
[ 0.180000] devtmpfs: mounted
[ 0.180000] Freeing unused kernel memory: 68K (ffffffff80000000 - ffffffff80011000)
所以我尝试通过提供内核参数“mem=128M memmap=126M$128M”来预留126MB的物理内存,但是Linux看到的物理内存大小还是一样的。
INSTRUCTION SETS WANT TO BE FREE
[ 0.000000] Linux version 3.14.33-g043bb5d (guanglin@guanglin-a11-linux) (gcc version 5.2.5
[ 0.000000] Detected 0xfe00000 bytes of physical memory
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x00200000-0x0fffffff]
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x00200000-0x0fffffff]
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 64135
[ 0.000000] Kernel command line: root=/dev/htifblk0 mem=128M memmap=126M$128M
[ 0.000000] PID hash table entries: 1024 (order: 1, 8192 bytes)
[ 0.000000] Dentry cache hash table entries: 32768 (order: 6, 262144 bytes)
[ 0.000000] Inode-cache hash table entries: 16384 (order: 5, 131072 bytes)
[ 0.000000] Sorting __ex_table...
[ 0.000000] Memory: 253568K/260096K available (1722K kernel code, 124K rwdata, 356K rodata)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] NR_IRQS:2
[ 0.150000] Calibrating delay using timer specific routine.. 20.01 BogoMIPS (lpj=100068)
[ 0.150000] pid_max: default: 32768 minimum: 301
[ 0.150000] Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
[ 0.150000] Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes)
[ 0.150000] devtmpfs: initialized
[ 0.150000] NET: Registered protocol family 16
[ 0.150000] bio: create slab <bio-0> at 0
[ 0.150000] Switched to clocksource riscv_clocksource
[ 0.150000] NET: Registered protocol family 2
[ 0.150000] TCP established hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.150000] TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.150000] TCP: Hash tables configured (established 2048 bind 2048)
[ 0.150000] TCP: reno registered
[ 0.150000] UDP hash table entries: 256 (order: 1, 8192 bytes)
[ 0.150000] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[ 0.150000] NET: Registered protocol family 1
[ 0.150000] futex hash table entries: 256 (order: 0, 6144 bytes)
[ 0.150000] io scheduler noop registered
[ 0.150000] io scheduler cfq registered (default)
[ 0.170000] htifcon htif1: detected console
[ 0.170000] console [htifcon0] enabled
[ 0.170000] htifblk htif2: detected disk
[ 0.170000] htifblk htif2: added htifblk0
[ 0.170000] TCP: cubic registered
[ 0.180000] VFS: Mounted root (ext2 filesystem) readonly on device 254:0.
[ 0.180000] devtmpfs: mounted
[ 0.180000] Freeing unused kernel memory: 68K (ffffffff80000000 - ffffffff80011000)
/ #