* [LTP] [PATCH v1] lib: add .min_swap_avail in tst_test struct
@ 2023-09-04 7:44 Andrea Cervesato
2023-09-04 8:48 ` Cyril Hrubis
2023-09-05 3:09 ` Li Wang
0 siblings, 2 replies; 4+ messages in thread
From: Andrea Cervesato @ 2023-09-04 7:44 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This new field is mainly to set the minimum size of SwapFree for
LTP testcase. If system available free swap memory is less than
.min_swap_avail, test will be exit with TCONF.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/tst_memutils.h | 5 +++++
include/tst_test.h | 3 +++
lib/tst_memutils.c | 9 +++++++++
lib/tst_test.c | 3 +++
4 files changed, 20 insertions(+)
diff --git a/include/tst_memutils.h b/include/tst_memutils.h
index 45dec55bc..19b593430 100644
--- a/include/tst_memutils.h
+++ b/include/tst_memutils.h
@@ -25,6 +25,11 @@ void tst_pollute_memory(size_t maxsize, int fillchar);
*/
long long tst_available_mem(void);
+/*
+ * Read the value of SwapFree from /proc/meminfo.
+ */
+long long tst_available_swap(void);
+
/*
* Enable OOM protection to prevent process($PID) being killed by OOM Killer.
* echo -1000 >/proc/$PID/oom_score_adj
diff --git a/include/tst_test.h b/include/tst_test.h
index 0ac492a80..75c2109b9 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -210,6 +210,9 @@ struct tst_test {
/* Minimum size(MB) of MemAvailable required by the test */
unsigned long min_mem_avail;
+ /* Minimum size(MB) of SwapFree required by the test */
+ unsigned long min_swap_avail;
+
/*
* Two policies for reserving hugepage:
*
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index 6fc9f6a93..c5382ff10 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -95,6 +95,15 @@ long long tst_available_mem(void)
return mem_available;
}
+long long tst_available_swap(void)
+{
+ unsigned long long swap_available = 0;
+
+ FILE_LINES_SCANF("/proc/meminfo", "SwapFree: %llu", &swap_available);
+
+ return swap_available;
+}
+
static int has_caps(void)
{
struct tst_cap_user_header hdr = {
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 0efabe467..3cc4aee0a 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1198,6 +1198,9 @@ static void do_setup(int argc, char *argv[])
if (tst_test->min_mem_avail > (unsigned long)(tst_available_mem() / 1024))
tst_brk(TCONF, "Test needs at least %luMB MemAvailable", tst_test->min_mem_avail);
+ if (tst_test->min_swap_avail > (unsigned long)(tst_available_swap() / 1024))
+ tst_brk(TCONF, "Test needs at least %luMB SwapFree", tst_test->min_swap_avail);
+
if (tst_test->hugepages.number)
tst_reserve_hugepages(&tst_test->hugepages);
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [LTP] [PATCH v1] lib: add .min_swap_avail in tst_test struct
2023-09-04 7:44 [LTP] [PATCH v1] lib: add .min_swap_avail in tst_test struct Andrea Cervesato
@ 2023-09-04 8:48 ` Cyril Hrubis
2023-09-04 9:45 ` Andrea Cervesato via ltp
2023-09-05 3:09 ` Li Wang
1 sibling, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2023-09-04 8:48 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
This looks good, but should be immediatelly followed by a patch that
fixes the process_madvise test.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v1] lib: add .min_swap_avail in tst_test struct
2023-09-04 7:44 [LTP] [PATCH v1] lib: add .min_swap_avail in tst_test struct Andrea Cervesato
2023-09-04 8:48 ` Cyril Hrubis
@ 2023-09-05 3:09 ` Li Wang
1 sibling, 0 replies; 4+ messages in thread
From: Li Wang @ 2023-09-05 3:09 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
On Mon, Sep 4, 2023 at 3:45 PM Andrea Cervesato <andrea.cervesato@suse.de>
wrote:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> This new field is mainly to set the minimum size of SwapFree for
> LTP testcase. If system available free swap memory is less than
> .min_swap_avail, test will be exit with TCONF.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> include/tst_memutils.h | 5 +++++
> include/tst_test.h | 3 +++
> lib/tst_memutils.c | 9 +++++++++
> lib/tst_test.c | 3 +++
> 4 files changed, 20 insertions(+)
>
> diff --git a/include/tst_memutils.h b/include/tst_memutils.h
> index 45dec55bc..19b593430 100644
> --- a/include/tst_memutils.h
> +++ b/include/tst_memutils.h
> @@ -25,6 +25,11 @@ void tst_pollute_memory(size_t maxsize, int fillchar);
> */
> long long tst_available_mem(void);
>
> +/*
> + * Read the value of SwapFree from /proc/meminfo.
> + */
> +long long tst_available_swap(void);
> +
> /*
> * Enable OOM protection to prevent process($PID) being killed by OOM
> Killer.
> * echo -1000 >/proc/$PID/oom_score_adj
> diff --git a/include/tst_test.h b/include/tst_test.h
> index 0ac492a80..75c2109b9 100644
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -210,6 +210,9 @@ struct tst_test {
> /* Minimum size(MB) of MemAvailable required by the test */
> unsigned long min_mem_avail;
>
> + /* Minimum size(MB) of SwapFree required by the test */
> + unsigned long min_swap_avail;
>
It would be great to have a brief introduction in the document,
like what we did for min_mem_avail.
Anyway, we can add it in a separate patch. Thanks!
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-05 3:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-04 7:44 [LTP] [PATCH v1] lib: add .min_swap_avail in tst_test struct Andrea Cervesato
2023-09-04 8:48 ` Cyril Hrubis
2023-09-04 9:45 ` Andrea Cervesato via ltp
2023-09-05 3:09 ` Li Wang
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.