• Axel Rasmussen's avatar
    userfaultfd/shmem: modify shmem_mfill_atomic_pte to use install_pte() · 7d64ae3a
    Axel Rasmussen authored
    In a previous commit, we added the mfill_atomic_install_pte() helper.
    This helper does the job of setting up PTEs for an existing page, to map
    it into a given VMA.  It deals with both the anon and shmem cases, as well
    as the shared and private cases.
    
    In other words, shmem_mfill_atomic_pte() duplicates a case it already
    handles.  So, expose it, and let shmem_mfill_atomic_pte() use it directly,
    to reduce code duplication.
    
    This requires that we refactor shmem_mfill_atomic_pte() a bit:
    
    Instead of doing accounting (shmem_recalc_inode() et al) part-way through
    the PTE setup, do it afterward.  This frees up mfill_atomic_install_pte()
    from having to care about this accounting, and means we don't need to e.g.
    shmem_uncharge() in the error path.
    
    A side effect is this switches shmem_mfill_atomic_pte() to use
    lru_cache_add_inactive_or_unevictable() instead of just lru_cache_add().
    This wrapper does some extra accounting in an exceptional case, if
    appropriate, so it's actually the more correct thing to use.
    
    Link: https://lkml.kernel.org/r/20210503180737.2487560-7-axelrasmussen@google.comSigned-off-by: default avatarAxel Rasmussen <axelrasmussen@google.com>
    Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
    Acked-by: default avatarHugh Dickins <hughd@google.com>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: Brian Geffon <bgeffon@google.com>
    Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>
    Cc: Jerome Glisse <jglisse@redhat.com>
    Cc: Joe Perches <joe@perches.com>
    Cc: Kirill A. Shutemov <kirill@shutemov.name>
    Cc: Lokesh Gidra <lokeshgidra@google.com>
    Cc: Mike Kravetz <mike.kravetz@oracle.com>
    Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
    Cc: Mina Almasry <almasrymina@google.com>
    Cc: Oliver Upton <oupton@google.com>
    Cc: Shaohua Li <shli@fb.com>
    Cc: Shuah Khan <shuah@kernel.org>
    Cc: Stephen Rothwell <sfr@canb.auug.org.au>
    Cc: Wang Qing <wangqing@vivo.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    7d64ae3a
shmem.c 109 KB