Linux mbind呼叫在Hugetlb内存上失败

发布于 2025-02-12 05:03:12 字数 837 浏览 1 评论 0原文

我正在尝试使用MBIND将内存绑定到特定的NUMA节点。我注意到,如果使用map_hugetlb分配了我的内存,则失败,但是如果我不尝试映射augeTlb,mbind会成功。

我绝对想要大型页面,并将内存映射到特定的NUMA节点。 Ami做错了什么,还是不支持?

在CentOS7编辑上运行

//mbind fails on this
void * buf = mmap( NULL, sz, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB, 0, 0 );
//works on this
void * buf2 = mmap( NULL, sz, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0 );

int numaNode = 1;
unsigned long nodemask = 0;
nodemask |= 1 << numaNode;
if( mbind( buf, sz, MPOL_BIND, &nodemask, sizeof(nodemask) * 8, 0 ) < 0 )
    printf( "mbind buf failed: %s\n", strerror(errno) );

if( mbind( buf2, sz, MPOL_BIND, &nodemask, sizeof(nodemask) * 8, 0 ) < 0 )
    printf( "mbind buf2 failed: %s\n", strerror(errno) );

:要清楚,MMAP工作正常,我的机器配置了大型页面。我没有在此处检查MMAP返回代码是否简洁

I'm trying to use mbind to bind my memory to a specific NUMA node. I noticed it fails if my memory is allocated with mmap using MAP_HUGETLB, but mbind succeeds if I dont try to MAP_HUGETLB.

I definitely want both HUGE pages and to map the memory to a specific NUMA node.
AmI doing something wrong, or is this not supported?

Running on CentOS7

//mbind fails on this
void * buf = mmap( NULL, sz, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB, 0, 0 );
//works on this
void * buf2 = mmap( NULL, sz, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0 );

int numaNode = 1;
unsigned long nodemask = 0;
nodemask |= 1 << numaNode;
if( mbind( buf, sz, MPOL_BIND, &nodemask, sizeof(nodemask) * 8, 0 ) < 0 )
    printf( "mbind buf failed: %s\n", strerror(errno) );

if( mbind( buf2, sz, MPOL_BIND, &nodemask, sizeof(nodemask) * 8, 0 ) < 0 )
    printf( "mbind buf2 failed: %s\n", strerror(errno) );

Edit: to be clear the mmap works fine and my machine is configured with huge pages. I didn’t check the mmap return code here for brevity

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忱杏 2025-02-19 05:03:13

您不检查MMAP返回错误值。除非您首先保留它们,否则它无法分配大型页面。

保留 hugeadm ,例如:

sudo hugeadm --pool-pages-min 2MB:4 --pool-pages-max 2MB:8 # 4-8 2MB pages
sudo hugeadm --pool-pages-min 1GB:2 --pool-pages-max 1GB:4 # 2-4 1GB pages

另一个选项是使用透明的巨大页面,而无需将任何额外标志传递给mmap。参见 nofollow noreferrer“> transparrent巨大页面支持 提供全部详细信息。

You don't check mmap return value for error. It fails to allocate huge pages unless you reserve them first.

Reserve huge pages with hugeadm, for example:

sudo hugeadm --pool-pages-min 2MB:4 --pool-pages-max 2MB:8 # 4-8 2MB pages
sudo hugeadm --pool-pages-min 1GB:2 --pool-pages-max 1GB:4 # 2-4 1GB pages

Another option is to use transparent huge pages without having to pass any extra flags to mmap. See Transparent Hugepage Support for full details.

撞了怀 2025-02-19 05:03:13

我认为这种Arlreadre已经解决了,请检查一下。

link

I think this artilcle arlready solved under, please check for it.

link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文