Skip to contentSkip to conversation

lib: fix MemAvailable parsing

PATCH In review Ralph Siemsen 3 participants 4 messages Sep 28, 2021 – Sep 29, 2021 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: fix MemAvailable parsing

The amount of available memory was not being returned correctly, which resulted in tests being executed when they should have been skipped.

Fixes 8759f4 ("lib: adjust the tmpfs size according to .dev_min_size and MemAvailable")
---
 lib/tst_memutils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/tst_memutils.c +2 -2
index 69077861f..90911da56 100644
@@ -65,9 +65,9 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
 
 long long tst_available_mem(void)
 {
-	long long mem_available;
+	long long mem_available = 0;
 
-	if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %ld",
+	if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %lld",
 		&mem_available)) {
 		mem_available = SAFE_READ_MEMINFO("MemFree:")
 			+ SAFE_READ_MEMINFO("Cached:");
Signature · 5 lines
2.25.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

lib/tst_memutils.c void tst_pollute_memory(size_t maxsize, int fillchar) · line 69

Quoted 7 lines
lib/tst_memutils.c +1 -1
@@ -65,9 +65,9 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
 
 long long tst_available_mem(void)
 {
-       long long mem_available;
+       long long mem_available = 0;
 

---> unsigned long long

lib/tst_memutils.c void tst_pollute_memory(size_t maxsize, int fillchar)

Quoted 3 lines
lib/tst_memutils.c +1 -1
-       if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %ld",
+       if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %lld",
 

I modified it to use '%llu' and pushed.

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ralph Siemsen

Hello Ralph,

Quoted 27 lines · Ralph Siemsen

The amount of available memory was not being returned correctly, which resulted in tests being executed when they should have been skipped.

Fixes 8759f4 ("lib: adjust the tmpfs size according to .dev_min_size and MemAvailable")
---
 lib/tst_memutils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/tst_memutils.c +2 -2
index 69077861f..90911da56 100644
@@ -65,9 +65,9 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
 
 long long tst_available_mem(void)
 {
-	long long mem_available;
+	long long mem_available = 0;
 
-	if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %ld",
+	if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %lld",
 		&mem_available)) {
 		mem_available = SAFE_READ_MEMINFO("MemFree:")
 			+ SAFE_READ_MEMINFO("Cached:");
Signature · 1 line
2.25.1

Just curious, did you find this on 32-bit ARM?

Anyway looks correct.

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Richard,

Quoted 2 lines · Richard Palethorpe

Just curious, did you find this on 32-bit ARM?

Yes, it was on 32-bit ARMv7. It happens on the real hardware, and also under qemuarm emulation.

You can see my replies in the "fallocate05: increase the the fallocate and defallocate size" thread, so see how I ended up discovering this problem.

Cheers,
Ralph

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp