Linux内存分配 - 订单更改为1

时间:2016-11-28 10:35:15

标签: linux memory-management linux-kernel

我会尽力描述这个问题。但是,我无法发布所有相关代码。

案件如下, 我在代码中做了一些更改,所有这些都在用户空间中。我没有改变内核代码中的任何内容 在使用此版本编译和工作一段时间之后,我突然发现Ephemeral ports范围已经改变 在调查之后我遇到了这是因为顺序的大小(内存分配)发生了变化。但正如我之前所说,没有人接触过这段代码。

以下是此次更改之前和之后的linux启动的一些日志消息。你可以注意到我之前提到的订单的变化。

更改后:

[000000.000] Determined physical RAM map:
[000000.000]  memory: 0000000007000000 @ 0000000000c10000 (usable)
[000000.015] reserve bootmem for memoops 0000000000020000 @ 0000000007bf0000
[000000.019] Primary instruction cache 32kB, virtually tagged, 4 way, 64 sets, linesize 128 bytes.
[000000.019] Primary data cache 16kB, 64-way, 2 sets, linesize 128 bytes.
[000000.020] PID hash table entries: 512 (order: 9, 16384 bytes)
[000000.020] Using 500.000 MHz high precision timer.
[000000.227] Dentry cache hash table entries: 16384 (order: 5, 131072 bytes)
[000000.240] Inode-cache hash table entries: 8192 (order: 4, 65536 bytes)
[000000.266] Memory: 112408k/114688k available (2062k kernel code, 2136k reserved, 533k data, 200k init, 0k highmem)

更改之前:

[000000.000] Determined physical RAM map:
[000000.000]  memory: 0000000007400000 @ 0000000000c00000 (usable)
[000000.016] reserve bootmem for memoops 0000000000020000 @ 0000000007fe0000
[000000.020] Primary instruction cache 32kB, virtually tagged, 4 way, 64 sets, linesize 128 bytes.
[000000.020] Primary data cache 16kB, 64-way, 2 sets, linesize 128 bytes.
[000000.020] PID hash table entries: 1024 (order: 10, 32768 bytes)
[000000.228] Dentry cache hash table entries: 32768 (order: 6, 262144 bytes)
[000000.242] Inode-cache hash table entries: 16384 (order: 5, 131072 bytes)
[000000.269] Memory: 116280k/118784k available (2062k kernel code, 2344k reserved, 533k data, 200k init, 0k highmem)

注意:我已经尝试取消更改并重新编译,但由于某些原因问题仍然存在。

也许有人知道会对此产生什么影响?怎么会发生这种情况?

1 个答案:

答案 0 :(得分:1)

应用程序代码不会对内核的引导产生任何影响,因为它在内核引导后开始运行。

此问题应该由您的物理内存更改引起,您可以通过内核源代码进行验证:

mm/page_alloc.c
/* round applicable memory size up to nearest megabyte */
            numentries = nr_kernel_pages;
            numentries += (1UL << (20 - PAGE_SHIFT)) - 1;
            numentries >>= 20 - PAGE_SHIFT;
            numentries <<= 20 - PAGE_SHIFT;
....
log2qty = ilog2(numentries);
....
printk(KERN_INFO "%s hash table entries: %ld (order: %d, %lu bytes)\n",
           tablename,
           (1UL << log2qty),
           ilog2(size) - PAGE_SHIFT,
           size);

如果引导参数保持不变,您可以检查:

  • 如果硬件保持不变
  • 您是否通过不同方法启动,例如从旧版更改为UEFI模式
  • 如果您的多个目标具有相同的配置(内存大小,CPU,芯片组等),您可以在另一块主板上进行验证,以避免此主板上的硬件问题。
相关问题