linuxmemory-managementlinux-kernelshared-memorymemory-mapped-files

Does userfaultfd now support file backed map?


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)?


Solution

  • 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:

    if ((vm_flags & VM_UFFD_MINOR) &&
        (!is_vm_hugetlb_page(vma) && !vma_is_shmem(vma)))
        return false;
    #ifndef CONFIG_PTE_MARKER_UFFD_WP
    /*
     * If user requested uffd-wp but not enabled pte markers for
     * uffd-wp, then shmem & hugetlbfs are not supported but only
     * anonymous.
     */
    if ((vm_flags & VM_UFFD_WP) && !vma_is_anonymous(vma))
        return false;
    #endif
    return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) ||
        vma_is_shmem(vma);
    

    Thus, anonymous mappings or mappings in:

    The meaning of VM_UFFD_MINOR is support for notifications on minor page faults.