gpt4 book ai didi

c - 用户进程是否可以告诉操作系统将 mmap 完成的映射重新定位到其他 NUMA 节点?

转载 作者:行者123 更新时间:2023-12-04 15:52:11 25 4
gpt4 key购买 nike

考虑这种情况:运行在 NUMA 机器上的用户进程调用 mmap 在虚拟地址空间中创建一个新映射。然后它使用 mmap 返回的内存进行处理(存储其数据,...)。现在由于某些原因,用户进程被调度到不同的 NUMA 节点。用户进程是否可以在保留数据的同时告诉操作系统重新定位已映射的内存(到不同的 NUMA 节点)?

最佳答案

使用 migrate_pages 可以迁移物理内存来自 libnuma ( -lnuma ) 的调用: http://man7.org/linux/man-pages/man2/migrate_pages.2.html

 long migrate_pages(int pid, unsigned long maxnode,
const unsigned long *old_nodes,
const unsigned long *new_nodes);

Link with -lnuma.

migrate_pages() attempts to move all pages of the process pid that are in memory nodes old_nodes to the memory nodes in new_nodes. Pages not located in any node in old_nodes will not be migrated. As far as possible, the kernel maintains the relative topology relationship inside old_nodes during the migration to new_nodes.



还有工具 migratepagesnumactl用于迁移 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 syscall可用于将页面子集迁移到某个 NUMA 节点:

https://www.kernel.org/doc/Documentation/vm/page_migration

...allows a process to manually relocate the node on which its pages are located through the MF_MOVE and MF_MOVE_ALL options while setting a new memory policy via mbind()



http://man7.org/linux/man-pages/man2/mbind.2.html

  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.

关于c - 用户进程是否可以告诉操作系统将 mmap 完成的映射重新定位到其他 NUMA 节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47097181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com