public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] lib: add tst_available_mem function
@ 2021-09-24  7:07 Li Wang
  2021-09-24  7:07 ` [LTP] [PATCH 2/3] swapping01: make use of tst_available_mem Li Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Li Wang @ 2021-09-24  7:07 UTC (permalink / raw)
  To: ltp

tst_available_mem helps to get the value of MemAvailable
from /proc/meminfo, if no support on older kernels,
return 'MemFree + Cached' for instead.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 include/tst_memutils.h |  6 ++++++
 lib/tst_memutils.c     | 13 +++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/include/tst_memutils.h b/include/tst_memutils.h
index 91dad07cd..f605f544e 100644
--- a/include/tst_memutils.h
+++ b/include/tst_memutils.h
@@ -19,4 +19,10 @@
  */
 void tst_pollute_memory(size_t maxsize, int fillchar);
 
+/*
+ * Read the value of MemAvailable from /proc/meminfo, if no support on
+ * older kernels, return 'MemFree + Cached' for instead.
+ */
+long long tst_available_mem(void);
+
 #endif /* TST_MEMUTILS_H__ */
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index 70b60091f..69077861f 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -62,3 +62,16 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
 
 	free(map_blocks);
 }
+
+long long tst_available_mem(void)
+{
+	long long mem_available;
+
+	if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %ld",
+		&mem_available)) {
+		mem_available = SAFE_READ_MEMINFO("MemFree:")
+			+ SAFE_READ_MEMINFO("Cached:");
+	}
+
+	return mem_available;
+}
-- 
2.31.1


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

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

end of thread, other threads:[~2021-09-28  7:53 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-24  7:07 [LTP] [PATCH 1/3] lib: add tst_available_mem function Li Wang
2021-09-24  7:07 ` [LTP] [PATCH 2/3] swapping01: make use of tst_available_mem Li Wang
2021-09-24 14:17   ` Petr Vorel
2021-09-24  7:07 ` [LTP] [PATCH 3/3] lib: unlimit the tmpfs size when test on small systems Li Wang
2021-09-24  9:51   ` Cyril Hrubis
2021-09-24 10:27     ` Li Wang
2021-09-24 10:40     ` Petr Vorel
2021-09-24 10:52   ` [LTP] [PATCH v2 3/3] lib: adjust the tmpfs size according to .dev_min_size and MemAvailable Li Wang
2021-09-24 11:05     ` Cyril Hrubis
2021-09-24 11:32       ` Li Wang
2021-09-24 14:23     ` Petr Vorel
2021-09-27  2:39       ` Li Wang
2021-09-27 15:12         ` Ralph Siemsen
2021-09-27 19:09           ` Ralph Siemsen
2021-09-28  1:19             ` Li Wang
2021-09-28  2:22               ` Ralph Siemsen
2021-09-28  7:53                 ` Li Wang
2021-09-24 14:15 ` [LTP] [PATCH 1/3] lib: add tst_available_mem function Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox