Architectures may need to configure the system at boot depending on whether HVO is enabled. For example, arm64 needs all CPUs to support hardware updates of the access flag to safely update the vmemmap in place, and may want to refuse to online CPUs that lack it, but only if HVO may be used. Such configuration is only valid if HVO cannot be enabled later at runtime through the vm.hugetlb_optimize_vmemmap sysctl. Add CONFIG_ARCH_HUGETLB_VMEMMAP_OPTIMIZATION_SYSCTL_RO for architectures to select. When selected, the vm.hugetlb_optimize_vmemmap sysctl is read-only, so HVO can only be enabled or disabled with the hugetlb_free_vmemmap= kernel command line parameter. Signed-off-by: James Houghton Reviewed-by: Muchun Song (ByteDance) --- Documentation/admin-guide/sysctl/vm.rst | 3 +++ fs/Kconfig | 3 ++- mm/Kconfig | 7 +++++++ mm/hugetlb_vmemmap.c | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index 3cb0138e850c..f29da7a35289 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -699,6 +699,9 @@ pages. So, those surplus pages are still optimized until they are no longer in use. You would need to wait for those surplus pages to be released before there are no optimized pages in the system. +On some architectures, this knob is read-only, and HVO can only be enabled or +disabled with the hugetlb_free_vmemmap= kernel command line parameter. + nr_hugepages_mempolicy ====================== diff --git a/fs/Kconfig b/fs/Kconfig index 70a1d0760d28..0c1a436280f8 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -267,7 +267,8 @@ config HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON help The HugeTLB Vmemmap Optimization (HVO) defaults to off. Say Y here to enable HVO by default. It can be disabled via hugetlb_free_vmemmap=off - (boot command line) or hugetlb_optimize_vmemmap (sysctl). + (boot command line) or hugetlb_optimize_vmemmap (sysctl, if the + architecture allows changing it at runtime). endif # HUGETLBFS config HUGETLB_PAGE diff --git a/mm/Kconfig b/mm/Kconfig index 18925ccb4adc..eeab97e84ed9 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -466,6 +466,13 @@ config ARCH_WANT_OPTIMIZE_DAX_VMEMMAP config ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP bool +# +# Select this from the architecture Kconfig if the hugetlb_optimize_vmemmap +# sysctl must be read-only. +# +config ARCH_HUGETLB_VMEMMAP_OPTIMIZATION_SYSCTL_RO + bool + config HAVE_MEMBLOCK_PHYS_MAP bool diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index df145776aa6b..1cc503a22699 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -685,7 +685,8 @@ static const struct ctl_table hugetlb_vmemmap_sysctls[] = { .procname = "hugetlb_optimize_vmemmap", .data = &vmemmap_optimize_enabled, .maxlen = sizeof(vmemmap_optimize_enabled), - .mode = 0644, + .mode = IS_ENABLED(CONFIG_ARCH_HUGETLB_VMEMMAP_OPTIMIZATION_SYSCTL_RO) ? + 0444 : 0644, .proc_handler = proc_dobool, }, }; -- 2.56.1.839.g22a8290db9-goog