Skip to content

Commit 4ce7ec9

Browse files
davidhildenbrandmehmetb0
authored andcommitted
selftests/mm: fix charge_reserved_hugetlb.sh test
BugLink: https://bugs.launchpad.net/bugs/2086242 [ Upstream commit c41a701 ] Currently, running the charge_reserved_hugetlb.sh selftest we can sometimes observe something like: $ ./charge_reserved_hugetlb.sh -cgroup-v2 ... write_result is 0 After write: hugetlb_usage=0 reserved_usage=10485760 killing write_to_hugetlbfs Received 2. Deleting the memory Detach failure: Invalid argument umount: /mnt/huge: target is busy. Both cases are issues in the test. While the unmount error seems to be racy, it will make the test fail: $ ./run_vmtests.sh -t hugetlb ... # [FAIL] not ok 10 charge_reserved_hugetlb.sh -cgroup-v2 # exit=32 The issue is that we are not waiting for the write_to_hugetlbfs process to quit. So it might still have a hugetlbfs file open, about which umount is not happy. Fix that by making "killall" wait for the process to quit. The other error ("Detach failure: Invalid argument") does not seem to result in a test error, but is misleading. Turns out write_to_hugetlbfs.c unconditionally tries to cleanup using shmdt(), even when we only mmap()'ed a hugetlb file. Even worse, shmaddr is never even set for the SHM case. Fix that as well. With this change it seems to work as expected. Link: https://lkml.kernel.org/r/20240821123115.2068812-1-david@redhat.com Fixes: 29750f7 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests") Signed-off-by: David Hildenbrand <david@redhat.com> Reported-by: Mario Casquero <mcasquer@redhat.com> Reviewed-by: Mina Almasry <almasrymina@google.com> Tested-by: Mario Casquero <mcasquer@redhat.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Muchun Song <muchun.song@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Koichiro Den <koichiro.den@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
1 parent 1b139f5 commit 4ce7ec9

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

tools/testing/selftests/vm/charge_reserved_hugetlb.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function cleanup_hugetlb_memory() {
252252
local cgroup="$1"
253253
if [[ "$(pgrep -f write_to_hugetlbfs)" != "" ]]; then
254254
echo killing write_to_hugetlbfs
255-
killall -2 write_to_hugetlbfs
255+
killall -2 --wait write_to_hugetlbfs
256256
wait_for_hugetlb_memory_to_get_depleted $cgroup
257257
fi
258258
set -e

tools/testing/selftests/vm/write_to_hugetlbfs.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum method {
2828

2929
/* Global variables. */
3030
static const char *self;
31-
static char *shmaddr;
31+
static int *shmaddr;
3232
static int shmid;
3333

3434
/*
@@ -47,15 +47,17 @@ void sig_handler(int signo)
4747
{
4848
printf("Received %d.\n", signo);
4949
if (signo == SIGINT) {
50-
printf("Deleting the memory\n");
51-
if (shmdt((const void *)shmaddr) != 0) {
52-
perror("Detach failure");
50+
if (shmaddr) {
51+
printf("Deleting the memory\n");
52+
if (shmdt((const void *)shmaddr) != 0) {
53+
perror("Detach failure");
54+
shmctl(shmid, IPC_RMID, NULL);
55+
exit(4);
56+
}
57+
5358
shmctl(shmid, IPC_RMID, NULL);
54-
exit(4);
59+
printf("Done deleting the memory\n");
5560
}
56-
57-
shmctl(shmid, IPC_RMID, NULL);
58-
printf("Done deleting the memory\n");
5961
}
6062
exit(2);
6163
}
@@ -211,7 +213,8 @@ int main(int argc, char **argv)
211213
shmctl(shmid, IPC_RMID, NULL);
212214
exit(2);
213215
}
214-
printf("shmaddr: %p\n", ptr);
216+
shmaddr = ptr;
217+
printf("shmaddr: %p\n", shmaddr);
215218

216219
break;
217220
default:

0 commit comments

Comments
 (0)