Skip to content

fix MADV_COLLAPSE issue if THP settings are disabled

Baolin Wang linux-mm lkml 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 34 repliesIn review
  2. v32 patches 16 repliesSuperseded
  3. v22 patches 46 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches23 repliesSuperseded

Changes in v4 from the cover letter

- Collect reviewed tags. Thanks.
- Update the commit message, per David.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2mm: huge_memory: disallow hugepages if the system-wide THP sysfs settings are disabledinclude/linux/huge_mm.h tools/testing/selftests/mm/khugepaged.c+39 -181 reply
2/2mm: shmem: disallow hugepages if the system-wide shmem THP sysfs settings are disabledmm/shmem.c tools/testing/selftests/mm/khugepaged.c+4 -40 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchZi YanLorenzo StoakesDev Jain
1/2R-b R-b R-b
2/2A-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/2] fix MADV_COLLAPSE issue if THP settings are disabled

When invoking thp_vma_allowable_orders(), if the TVA_ENFORCE_SYSFS flag is not specified, we will ignore the THP sysfs settings. Whilst it makes sense for the callers who do not specify this flag, it creates a odd and surprising situation where a sysadmin specifying 'never' for all THP sizes still observing THP pages being allocated and used on the system. And the MADV_COLLAPSE is an example of such a case, that means it will not set TVA_ENFORCE_SYSFS when calling thp_vma_allowable_orders().

As we discussed in the previous thread [1], the MADV_COLLAPSE will ignore the system-wide anon/shmem THP sysfs settings, which means that even though we have disabled the anon/shmem THP configuration, MADV_COLLAPSE will still attempt to collapse into a anon/shmem THP. This violates the rule we have agreed upon: never means never.

For example, system administrators who disabled THP everywhere must indeed very much not want THP to be used for whatever reason - having individual programs being able to quietly override this is very surprising and likely to cause headaches for those who desire this not to happen on their systems.

This patch set will address the MADV_COLLAPSE issue.

Test
====
1. Tested the mm selftests and found no regressions.
2. With toggling different Anon mTHP settings, the allocation and madvise collapse for anonymous pages work well.
3. With toggling different shmem mTHP settings, the allocation and madvise collapse for shmem work well.
4. Tested the large order allocation for tmpfs, and works as expected.

[1] https://lore.kernel.org/all/[email protected]/

Changes from v3:
- Collect reviewed tags. Thanks.
- Update the commit message, per David.

Changes from v2:
- Update the commit message and cover letter, per Lorenzo. Thanks.
- Simplify the logic in thp_vma_allowable_orders(), per Lorenzo and David. Thanks.

Changes from v1:
- Update the commit message, per Zi.
- Add Zi's reviewed tag. Thanks.
- Update the shmem logic.

Baolin Wang (2):
mm: huge_memory: disallow hugepages if the system-wide THP sysfs
settings are disabled
mm: shmem: disallow hugepages if the system-wide shmem THP sysfs
settings are disabled

 include/linux/huge_mm.h                 | 51 ++++++++++++++++++-------
 mm/shmem.c                              |  6 +--
 tools/testing/selftests/mm/khugepaged.c |  8 +---
 3 files changed, 43 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.5