【问题标题】:mmap error : cannot allocate memory. how to allocate enough default sized huge pages as admin?mmap 错误:无法分配内存。如何以管理员身份分配足够的默认大小的大页面?
【发布时间】: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 创建了一个新区域,您可以将其视为位于heapstack 区域之间。

标签: memory memory-management mmap ubuntu-20.04 grub


【解决方案1】:

似乎有两种方法。

  1. 在 /etc/sysctrl.conf 中添加 vm.nr_hugepages = 16 并重新启动。
    我已经检查过了。

  2. (正如 Nate Eldredge 评论的那样)在 /etc/default/grub 的 GRUB_CMDLINE_LINUX="" 行(引号内)添加 'hugepages=16' 并执行 update-grub。

【讨论】:

    猜你喜欢
    • 2017-07-20
    • 2023-04-05
    • 2014-02-28
    • 2016-06-19
    • 2016-06-03
    • 1970-01-01
    • 2010-12-30
    • 1970-01-01
    • 2012-09-21
    相关资源
    最近更新 更多