[PATCH v2 40/46] docs: hugetlb: update hugetlb and userfaultfd admin-guides with HGM info

From: James Houghton
Date: Fri Feb 17 2023 - 19:31:52 EST


Include information about how MADV_SPLIT should be used to enable
high-granularity UFFDIO_CONTINUE operations, and include information
about how MADV_COLLAPSE should be used to collapse the mappings at the
end.

Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>

diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst
index a969a2c742b2..c6eaef785609 100644
--- a/Documentation/admin-guide/mm/hugetlbpage.rst
+++ b/Documentation/admin-guide/mm/hugetlbpage.rst
@@ -454,6 +454,10 @@ errno set to EINVAL or exclude hugetlb pages that extend beyond the length if
not hugepage aligned. For example, munmap(2) will fail if memory is backed by
a hugetlb page and the length is smaller than the hugepage size.

+It is possible for users to map HugeTLB pages at a higher granularity than
+normal using HugeTLB high-granularity mapping (HGM). For example, when using 1G
+pages on x86, a user could map that page with 4K PTEs, 2M PMDs, a combination of
+the two. See Documentation/admin-guide/mm/userfaultfd.rst.

Examples
========
diff --git a/Documentation/admin-guide/mm/userfaultfd.rst b/Documentation/admin-guide/mm/userfaultfd.rst
index 83f31919ebb3..cc496a307ea2 100644
--- a/Documentation/admin-guide/mm/userfaultfd.rst
+++ b/Documentation/admin-guide/mm/userfaultfd.rst
@@ -169,7 +169,13 @@ like to do to resolve it:
the page cache). Userspace has the option of modifying the page's
contents before resolving the fault. Once the contents are correct
(modified or not), userspace asks the kernel to map the page and let the
- faulting thread continue with ``UFFDIO_CONTINUE``.
+ faulting thread continue with ``UFFDIO_CONTINUE``. If this is done at the
+ base-page size in a transparent-hugepage-eligible VMA or in a HugeTLB VMA
+ (requires ``MADV_SPLIT``), then userspace may want to use
+ ``MADV_COLLAPSE`` when a hugepage is fully populated to inform the kernel
+ that it may be able to collapse the mapping. ``MADV_COLLAPSE`` will undo
+ the effect of any ``UFFDIO_WRITEPROTECT`` calls on the collapsed address
+ range.

Notes:

--
2.39.2.637.g21b0678d19-goog