我有以下代码创建一个命名的共享内存段,然后尝试找到其numa节点ID:
const auto handle = shm_open("/myshm", O_RDWR | O_CREAT, 0666);
if (-1 == handle) {
std::cout << "failed to open named shared memory" << std::endl;
throw;
}
constexpr auto size = 32;
ftruncate(handle, size);
auto myshm = (void*) mmap(nullptr, size, PROT_READ | PROT_WRITE,
MAP_SHARED, handle, 0);
if (MAP_FAILED == myshm) {
std::cout << errno << std::endl;
throw;
}
// for some reason 0666 does not take effect, chmod it again
const auto rc = fchmod(handle, 0666);
if (rc == -1) {
std::cerr << "Can't change permissions to 0666 on shared mem segment\n" << std::end;
}
constexpr uint32_t nPages = std::ceil(size / 4096.0);
int32_t status[nPages];
if (0 != move_pages(0, nPages, &myshm, nullptr, status, MPOL_MF_MOVE_ALL)) {
std::cout << "failed to inquiry SHM: " << strerror(errno) << std::endl;
}
else {
for (uint32_t i = 0; i < nPages; i++) {
std::cout << "page " << i << " locate at numa node " << status[i] << std::endl;
}
}
奇怪的是我得到failed to inquiry SHM: Operation not permitted
我确实在可执行文件tho上运行sudo setcap 'cap_sys_nice=eip'
。
有什么主意吗?