All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [RFC PATCH v1 1/1] overcommit_memory: Disable optimization for malloc to prevent false positives
@ 2025-05-20 15:25 Jan Polensky
  2025-05-21 19:47 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Polensky @ 2025-05-20 15:25 UTC (permalink / raw)
  To: ltp

When compiling with GCC 15.1.1+, the default-enabled -fmalloc-dce=2 and
-fallocation-dce under -O2 can eliminate the entire malloc block because its
result is only compared to NULL and/or passed to free().

This leads to false positives in tests that expect malloc() to fail under memory
pressure, as the allocation is optimized away.

Disable this optimization for the affected function to preserve the intended
test behavior.

References: https://gcc.gnu.org/onlinedocs/gcc-15.1.0/gcc/Optimize-Options.html
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
---
 testcases/kernel/mem/tunable/overcommit_memory.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/testcases/kernel/mem/tunable/overcommit_memory.c b/testcases/kernel/mem/tunable/overcommit_memory.c
index b5beebbcd3c4..fb42dbb75a00 100644
--- a/testcases/kernel/mem/tunable/overcommit_memory.c
+++ b/testcases/kernel/mem/tunable/overcommit_memory.c
@@ -151,6 +151,7 @@ static void overcommit_memory_test(void)

 }

+__attribute__((optimize("O0")))
 static int heavy_malloc(long size)
 {
 	char *p;
--
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [RFC PATCH v1 1/1] overcommit_memory: Disable optimization for malloc to prevent false positives
  2025-05-20 15:25 [LTP] [RFC PATCH v1 1/1] overcommit_memory: Disable optimization for malloc to prevent false positives Jan Polensky
@ 2025-05-21 19:47 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2025-05-21 19:47 UTC (permalink / raw)
  To: Jan Polensky; +Cc: ltp

Hi!
We already have a macro for this usecase introduced in the commit:

commit 5bb0c6bc553a3393627b371275b2e34b0099de19
Author: Jan Stancek <jstancek@redhat.com>
Date:   Thu Feb 6 10:42:31 2025 +0100

    syscalls/mallinfo02: introduce LTP_VAR_USED to avoid optimization


Can you please use the LTP_VAR_USED() instead?

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-21 19:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-20 15:25 [LTP] [RFC PATCH v1 1/1] overcommit_memory: Disable optimization for malloc to prevent false positives Jan Polensky
2025-05-21 19:47 ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.