Does userfaultfd now support file backed map?

 ̄綄美尐妖づ 提交于 2021-01-01 03:56:36

问题


I saw from the documentation of userfaultfd

https://manpages.debian.org/testing/manpages-dev/userfaultfd.2.en.html http://man7.org/linux/man-pages/man2/ioctl_userfaultfd.2.html

that userfaultfd will start supporting shared map since kernel 4.11. However, the documentation still looks very ambiguous in the sense that I'm still wondering will these include supporting file-backed mmap (which can also be MAP_SHARED)?


回答1:


To answer definitively, since the information is not in the manual page(s), we can see the source.

Attempting to register a userfaultfd object with an address range must check whether that range is "compatible":

…
/* check not compatible vmas */
ret = -EINVAL;
if (!vma_can_userfault(cur))
    goto out_unlock;

and the definition of compatibility is:

static inline bool vma_can_userfault(struct vm_area_struct *vma)
{
    return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) || vma_is_shmem(vma);
}

Thus, only anonymous mappings (vma_is_anonymous), or mappings in:

  • tmpfs-backed, aka shared memory virtual filesystem (tmpfs, shmget) mappings are compatible
  • when CONFIG_SHMEM is disabled, file-backed ranges which have been remapped (with generic_file_mmap) as shared are also compatible


来源:https://stackoverflow.com/questions/48863423/does-userfaultfd-now-support-file-backed-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!