【发布时间】:2021-09-24 08:22:48
【问题描述】:
我正在编译和运行this 程序,但收到“mmap 错误:无法分配内存”。 顶部的评论是
/*
* Example of using hugepage memory in a user application using the mmap
* system call with MAP_HUGETLB flag. Before running this program make
* sure the administrator has allocated enough default sized huge pages
* to cover the 256 MB allocation.
*
* For ia64 architecture, Linux kernel reserves Region number 4 for hugepages.
* That means the addresses starting with 0x800000... will need to be
* specified. Specifying a fixed address is not required on ppc64, i386
* or x86_64.
*/
我想查看if the administrator has allocated enough default sized huge pages to cover the 256 MB allocation,但我是系统管理员。我该怎么办?我在 ubuntu 20.04 x86_64 机器上。 (附带问题:mmap 是否使用堆区域?)
添加:请看我的评论(我添加了一个引导命令参数并且代码有效。我暂时在 grub 菜单中添加了引导参数。)但我希望我可以添加一个初始化脚本,以便每次计算机都能生效靴子。
【问题讨论】:
-
@JosephSible-ReinstateMonica 嗨,谢谢!我已经阅读了文档(没有读到最后)并在引导命令中添加了“hugepages=16”。我和我已将代码中的 LENGTH 更改为 2M。 (256M 太大了)。并且代码有效!谢谢!
-
内核命令行参数可以添加到
/etc/default/grub。 -
@NateEldredge 嗨,谢谢!我在答案中添加了您的方法。
-
至于你的问题“mmap 是否使用堆区域?”。不,
mmap创建了一个新区域,您可以将其视为位于heap和stack区域之间。
标签: memory memory-management mmap ubuntu-20.04 grub