Bao*_*Bui 6 c memory-management linux-kernel numa
考虑以下场景:在 NUMA 计算机上运行的用户进程调用 mmap 在虚拟地址空间中创建新映射。然后它使用 mmap 返回的内存进行处理(存储其数据,...)。现在由于某些原因,用户进程被调度到不同的NUMA节点。用户进程是否可以告诉操作系统在保留数据的同时重新定位已映射的内存(到不同的 NUMA 节点)?
migrate_pages通过libnuma ( ) 的调用可以迁移物理内存-lnuma:http://man7.org/linux/man-pages/man2/migrate_pages.2.html
Run Code Online (Sandbox Code Playgroud)long migrate_pages(int pid, unsigned long maxnode, const unsigned long *old_nodes, const unsigned long *new_nodes); Link with -lnuma.
migrate_pages()尝试将内存节点 old_nodes 中的进程 pid 的所有页面移动到 new_nodes 中的内存节点。不位于 old_nodes 中任何节点的页面将不会被迁移。在迁移到new_nodes的过程中,内核会尽可能维护old_nodes内部的相对拓扑关系。
migratepages软件包中还有numactl用于迁移 pid 所有页面的工具:http://man7.org/linux/man-pages/man8/migratepages.8.html
您还可以使用以下命令更改内存策略set_mempolicy:http://man7.org/linux/man-pages/man2/set_mempolicy.2.html
mbind系统调用可用于将页面子集迁移到某个 NUMA 节点:
https://www.kernel.org/doc/Documentation/vm/page_migration
...允许进程通过 MF_MOVE 和 MF_MOVE_ALL 选项手动重新定位其页面所在的节点,同时通过以下方式设置新的内存策略
mbind()
http://man7.org/linux/man-pages/man2/mbind.2.html
Run Code Online (Sandbox Code Playgroud)If MPOL_MF_MOVE is specified in flags, then the kernel will attempt to move all the existing pages in the memory range so that they follow the policy. Pages that are shared with other processes will not be moved. If MPOL_MF_STRICT is also specified, then the call will fail with the error EIO if some pages could not be moved.