WSL2-Linux-Kernel/tools/testing/selftests/vm
Dev Jain fdba4fbe5e selftests/mm: compaction_test: fix bogus test success on Aarch64
[ Upstream commit d4202e66a4b1fe6968f17f9f09bbc30d08f028a1 ]

Patch series "Fixes for compaction_test", v2.

The compaction_test memory selftest introduces fragmentation in memory
and then tries to allocate as many hugepages as possible. This series
addresses some problems.

On Aarch64, if nr_hugepages == 0, then the test trivially succeeds since
compaction_index becomes 0, which is less than 3, due to no division by
zero exception being raised. We fix that by checking for division by
zero.

Secondly, correctly set the number of hugepages to zero before trying
to set a large number of them.

Now, consider a situation in which, at the start of the test, a non-zero
number of hugepages have been already set (while running the entire
selftests/mm suite, or manually by the admin). The test operates on 80%
of memory to avoid OOM-killer invocation, and because some memory is
already blocked by hugepages, it would increase the chance of OOM-killing.
Also, since mem_free used in check_compaction() is the value before we
set nr_hugepages to zero, the chance that the compaction_index will
be small is very high if the preset nr_hugepages was high, leading to a
bogus test success.

This patch (of 3):

Currently, if at runtime we are not able to allocate a huge page, the test
will trivially pass on Aarch64 due to no exception being raised on
division by zero while computing compaction_index.  Fix that by checking
for nr_hugepages == 0.  Anyways, in general, avoid a division by zero by
exiting the program beforehand.  While at it, fix a typo, and handle the
case where the number of hugepages may overflow an integer.

Link: https://lkml.kernel.org/r/20240521074358.675031-1-dev.jain@arm.com
Link: https://lkml.kernel.org/r/20240521074358.675031-2-dev.jain@arm.com
Fixes: bd67d5c15c ("Test compaction of mlocked memory")
Signed-off-by: Dev Jain <dev.jain@arm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Sri Jayaramappa <sjayaram@akamai.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-07-05 09:14:13 +02:00
..
.gitignore selftests: vm: add KSM merge test 2021-09-03 09:58:18 -07:00
Makefile selftests: vm: Makefile: rename TARGETS to VMTARGETS 2022-05-18 10:26:50 +02:00
charge_reserved_hugetlb.sh selftests/mm: switch to bash from sh 2024-03-15 10:48:20 -04:00
check_config.sh selftests/vm: hmm-tests: remove the libhugetlbfs dependency 2020-12-15 12:13:38 -08:00
compaction_test.c selftests/mm: compaction_test: fix bogus test success on Aarch64 2024-07-05 09:14:13 +02:00
config mm/gup_benchmark: rename to mm/gup_test 2020-12-15 12:13:38 -08:00
gup_test.c mm/gup_benchmark: support threading 2021-06-29 10:53:48 -07:00
hmm-tests.c mm/hmm.c: allow VM_MIXEDMAP to work with hmm_range_fault 2022-01-27 11:05:43 +01:00
hugepage-mmap.c
hugepage-shm.c
hugetlb_reparenting_test.sh selftests/mm: fix awk usage in charge_reserved_hugetlb.sh and hugetlb_reparenting_test.sh that may cause error 2023-10-25 11:58:58 +02:00
khugepaged.c khugepaged: selftests: remove debug_cow 2021-06-30 20:47:26 -07:00
ksm_tests.c selftests: vm: add COW time test for KSM pages 2021-09-03 09:58:18 -07:00
madv_populate.c selftests/vm: add test for MADV_POPULATE_(READ|WRITE) 2021-06-30 20:47:31 -07:00
map_fixed_noreplace.c selftest/vm: fix map_fixed_noreplace test failure 2022-03-16 14:23:42 +01:00
map_hugetlb.c Revert "selftests: mm: fix map_hugetlb failure on 64K page size systems" 2024-05-25 16:20:16 +02:00
map_populate.c tools/testing/selftests/vm/: add MAP_POPULATE test 2018-08-22 10:52:45 -07:00
memfd_secret.c selftests: secretmem: floor the memory size to the multiple of page_size 2024-01-15 18:51:21 +01:00
mlock-random-test.c selftests: Fix spelling mistake "cann't" -> "cannot" 2021-09-03 09:58:13 -07:00
mlock2-tests.c selftests: vm: drop dependencies on page flags from mlock2 tests 2020-04-02 09:35:31 -07:00
mlock2.h
mremap_dontunmap.c selftests: add a MREMAP_DONTUNMAP selftest for shmem 2021-04-30 11:20:39 -07:00
mremap_test.c selftests/vm: remove ARRAY_SIZE define from individual tests 2023-02-06 07:59:01 +01:00
on-fault-limit.c
pkey-helpers.h selftests/vm: remove ARRAY_SIZE define from individual tests 2023-02-06 07:59:01 +01:00
pkey-powerpc.h selftests: vm: pkeys: use the correct page size on powerpc 2020-06-04 19:06:27 -07:00
pkey-x86.h selftests/vm/pkeys: Add a regression test for setting PKRU through ptrace 2023-01-14 10:23:28 +01:00
protection_keys.c selftests/vm/pkeys: Add a regression test for setting PKRU through ptrace 2023-01-14 10:23:28 +01:00
run_vmtests.sh selftests: vm: add KSM merging across nodes test 2021-09-03 09:58:18 -07:00
split_huge_page_test.c tools/testing/selftests/vm/split_huge_page_test.c: fix application of sizeof to pointer 2021-10-28 17:18:55 -07:00
test_hmm.sh mm/hmm/test: add selftests for HMM 2020-05-19 16:48:31 -03:00
test_vmalloc.sh vm/test_vmalloc.sh: adapt for updated driver interface 2021-04-30 11:20:40 -07:00
thuge-gen.c
transhuge-stress.c
userfaultfd.c kselftest/vm: fix tests build with old libc 2022-03-19 13:47:50 +01:00
va_128TBswitch.c selftests/vm: remove ARRAY_SIZE define from individual tests 2023-02-06 07:59:01 +01:00
virtual_address_range.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 191 2019-05-30 11:29:21 -07:00
write_hugetlb_memory.sh selftests/mm: switch to bash from sh 2024-03-15 10:48:20 -04:00
write_to_hugetlbfs.c selftests/vm/write_to_hugetlbfs.c: fix unused variable warning 2020-05-23 10:26:31 -07:00