有没有在C / C ++ code。使用mbind的任何例子吗? [英] Is there any example of using mbind in C/C++ code?

查看:642
本文介绍了有没有在C / C ++ code。使用mbind的任何例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 mbind()在我为了跨越4 NUMA域重新排列虚拟页C ++ code,可惜我是新来这个功能:

I am trying to use mbind() in my C++ code in order to rearrange virtual pages across 4 NUMA domains, unfortunately I am new to this function:

long mbind(void *addr, unsigned long len, int mode, const unsigned long *nodemask,   
              unsigned long maxnode, unsigned flags);

目前,我有这样的事情:

Currently, I have something like this:

mbind(0x0,4611686018424767488,MPOL_BIND,nodemask,maxnode,MPOL_MF_MOVE);

从规格目前还不清楚给我放什么,以及如何把为 nodemask maxnode

推荐答案

nodemask 是指向允许的NUMA节点的位掩码。该位掩码是与每个数组元素持有的比特数为 unsigned long int类型的大小无符号长元素的数组特定的架构允许。除非你的程序是一个非常大的NUMA系统上运行,一个无符号长变量应该足够了。

nodemask is a pointer to a bitmask of the allowed NUMA nodes. The bitmask is an array of unsigned long elements with each array element holding as many bits as the size of unsigned long int on the particular architecture allows. Unless your program is running on a really big NUMA system, a single unsigned long variable should suffice.

maxnode 给出 nodemask 显著的位数。内核轮内部尺寸为中的sizeof(无符号长),但只使用 maxnode 位的倍数。

maxnode gives the number of significant bits in nodemask. The kernel rounds internally the size to a multiple of sizeof(unsigned long) but only uses maxnode bits.

有很多例子和库周围,让您创建和方便地操作位掩码,而不必与位操作自己捣鼓。您可以利用 libnuma 。它不允许你设置 MPOL_MF_MOVE 政策,但包括nodemasks的创建和处理功能。

There are many examples and libraries around that allow you to create and conveniently manipulate bitmasks without having to fiddle with bit operations yourself. You can utilise libnuma. It doesn't allow you to set the MPOL_MF_MOVE policy but includes functions for the creation and manipulation of nodemasks.

一个可怕的,非常不可移植的Linux专业提示:与CPU的亲和力口罩,应对现有的宏即 CPU_ZERO / CPU_SET / CPU_CLR 和相关的数据结构 cpu_set_t ,也可以用于NUMA nodemasks。其原因在于,(1)两者都为无符号长(2)通常有比逻辑CPU少NUMA节点,因此 cpu_set_t 应该有足够的位能够重新present系统上的所有NUMA节点。

A terrible and very unportable Linux pro-tip: The existing macros that deal with the CPU affinity masks, namely CPU_ZERO / CPU_SET / CPU_CLR and the associated data structure cpu_set_t can also be used for NUMA nodemasks. The reason for that is that (1) both are implemented as arrays of unsigned long and (2) there are usually less NUMA nodes than logical CPUs, therefore cpu_set_t should have enough bits to be able to represent all NUMA nodes on the system.

边注: 4611686018424767488 也许应该用 LL 后缀

这篇关于有没有在C / C ++ code。使用mbind的任何例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆