mm: enable MADV_DONTNEED for hugetlb mappings
Patch series "Add hugetlb MADV_DONTNEED support", v3. Userfaultfd selftests for hugetlb does not perform UFFD_EVENT_REMAP testing. However, mremap support was recently added in commit 550a7d60 ("mm, hugepages: add mremap() support for hugepage backed vma"). While attempting to enable mremap support in the test, it was discovered that the mremap test indirectly depends on MADV_DONTNEED. madvise does not allow MADV_DONTNEED for hugetlb mappings. However, that is primarily due to the check in can_madv_lru_vma(). By simply removing the check and adding huge page alignment, MADV_DONTNEED can be made to work for hugetlb mappings. Do note that there is no compelling use case for adding this support. This was discussed in the RFC [1]. However, adding support makes sense as it is fairly trivial and brings hugetlb functionality more in line with 'normal' memory. After enabling support, add selftest for MADV_DONTNEED as well as MADV_REMOVE. Then update userfaultfd selftest. If new functionality is accepted, then madvise man page will be updated to indicate hugetlb is supported. It will also be updated to clarify what happens to the passed length argument. This patch (of 3): MADV_DONTNEED is currently disabled for hugetlb mappings. This certainly makes sense in shared file mappings as the pagecache maintains a reference to the page and it will never be freed. However, it could be useful to unmap and free pages in private mappings. In addition, userfaultfd minor fault users may be able to simplify code by using MADV_DONTNEED. The primary thing preventing MADV_DONTNEED from working on hugetlb mappings is a check in can_madv_lru_vma(). To allow support for hugetlb mappings create and use a new routine madvise_dontneed_free_valid_vma() that allows hugetlb mappings in this specific case. For normal mappings, madvise requires the start address be PAGE aligned and rounds up length to the next multiple of PAGE_SIZE. Do similarly for hugetlb mappings: require start address be huge page size aligned and round up length to the next multiple of huge page size. Use the new madvise_dontneed_free_valid_vma routine to check alignment and round up length/end. zap_page_range requires this alignment for hugetlb vmas otherwise we will hit BUGs. Link: https://lkml.kernel.org/r/20220215002348.128823-1-mike.kravetz@oracle.com Link: https://lkml.kernel.org/r/20220215002348.128823-2-mike.kravetz@oracle.com Signed-off-by:Mike Kravetz <mike.kravetz@oracle.com> Cc: Naoya Horiguchi <naoya.horiguchi@linux.dev> Cc: David Hildenbrand <david@redhat.com> Cc: Axel Rasmussen <axelrasmussen@google.com> Cc: Mina Almasry <almasrymina@google.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Peter Xu <peterx@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Shuah Khan <skhan@linuxfoundation.org> Cc: Mike Rapoport <rppt@kernel.org> Signed-off-by:
Andrew Morton <akpm@linux-foundation.org> Signed-off-by:
Linus Torvalds <torvalds@linux-foundation.org>
-
mentioned in commit e0255a7f
-
mentioned in commit 59f91d68
-
mentioned in commit 35b403ae
-
mentioned in commit f19ec9e6
-
mentioned in commit 8ebe0a5e
-
mentioned in commit 847e90d3
-
mentioned in commit 0efd772c
-
mentioned in commit 7621b518
-
mentioned in commit e10e698a
-
mentioned in commit 3ebf7dde
-
mentioned in commit 809e522e
-
mentioned in commit 62106ea4
-
mentioned in commit 9f766e7b
-
mentioned in commit fb99dcaa
-
mentioned in commit 09a0d762
-
mentioned in commit ffc1c558
-
mentioned in commit 0babe53e
-
mentioned in commit c674421b
-
mentioned in commit 32c0e76c
-
mentioned in commit b5fe3d8a
-
mentioned in commit 1cc1713d
-
mentioned in commit 8a5dbbdc
-
mentioned in commit 2bf30cac
-
mentioned in commit 2b529cf5
-
mentioned in commit b0e93d61
-
mentioned in commit e7092bd7
-
mentioned in commit bd9f753e
-
mentioned in commit 8036be00
-
mentioned in commit f48808c6
-
mentioned in commit 7cc482dc
-
mentioned in commit 44e38a14
-
mentioned in commit 094f7113
-
mentioned in commit 04ada095
-
mentioned in commit 21b85b09