[RFC PATCH v2 41/47] docs: hugetlb: update hugetlb and userfaultfd admin-guides with HGM info
From: James Houghton
Date: Fri Oct 21 2022 - 12:41:42 EST
This includes information about how UFFD_FEATURE_MINOR_HUGETLBFS_HGM
should be used and when MADV_COLLAPSE should be used with it.
Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>
---
Documentation/admin-guide/mm/hugetlbpage.rst | 4 ++++
Documentation/admin-guide/mm/userfaultfd.rst | 16 +++++++++++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/mm/hugetlbpage.rst b/Documentation/admin-guide/mm/hugetlbpage.rst
index 19f27c0d92e0..ca7db15ae768 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..19877aaad61b 100644
--- a/Documentation/admin-guide/mm/userfaultfd.rst
+++ b/Documentation/admin-guide/mm/userfaultfd.rst
@@ -115,6 +115,14 @@ events, except page fault notifications, may be generated:
areas. ``UFFD_FEATURE_MINOR_SHMEM`` is the analogous feature indicating
support for shmem virtual memory areas.
+- ``UFFD_FEATURE_MINOR_HUGETLBFS_HGM`` indicates that the kernel supports
+ small-page-aligned regions for ``UFFDIO_CONTINUE`` in HugeTLB-backed
+ virtual memory areas. ``UFFD_FEATURE_MINOR_HUGETLBFS_HGM`` and
+ ``UFFD_FEATURE_EXACT_ADDRESS`` must both be specified explicitly to enable
+ this behavior. If ``UFFD_FEATURE_MINOR_HUGETLBFS_HGM`` is specified but
+ ``UFFD_FEATURE_EXACT_ADDRESS`` is not, then ``UFFDIO_API`` will fail with
+ ``EINVAL``.
+
The userland application should set the feature flags it intends to use
when invoking the ``UFFDIO_API`` ioctl, to request that those features be
enabled if supported.
@@ -169,7 +177,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 ``UFFD_FEATURE_MINOR_HUGETLBFS_HGM``), 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 may undo
+ the effect of any ``UFFDIO_WRITEPROTECT`` calls on the collapsed address
+ range.
Notes:
--
2.38.0.135.g90850a2211-goog