All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] lib: add tst_request_hugepages
@ 2019-11-28  8:45 Li Wang
  2019-11-28  8:45 ` [LTP] [PATCH 2/2] pkey01: disable hugetlb test if failed to reserve hugepage Li Wang
  2019-12-03 10:49 ` [LTP] [PATCH 1/2] lib: add tst_request_hugepages Cyril Hrubis
  0 siblings, 2 replies; 6+ messages in thread
From: Li Wang @ 2019-11-28  8:45 UTC (permalink / raw)
  To: ltp

Note: more and more tests need to configure hugepage before testing, so
this is a start to add some useful hugetlb functions in global library
for the whole LTP.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 include/tst_hugepage.h | 19 +++++++++++++++++++
 include/tst_test.h     |  1 +
 lib/tst_hugepage.c     | 43 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 include/tst_hugepage.h
 create mode 100644 lib/tst_hugepage.c

diff --git a/include/tst_hugepage.h b/include/tst_hugepage.h
new file mode 100644
index 000000000..e06705bd0
--- /dev/null
+++ b/include/tst_hugepage.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ */
+
+#ifndef TST_HUGEPAGE__
+#define TST_HUGEPAGE__
+
+/*
+ * Try to request the specified number of huge pages from system.
+ *
+ * Note: this depend on the status of system memory fragmentation.
+ *       0 - reserve fail
+ *       1 - reserve success
+ */
+int tst_request_hugepages(long hpages);
+
+#endif /* TST_HUGEPAGE_H */
+
diff --git a/include/tst_test.h b/include/tst_test.h
index 21c7dfbdb..7ec1ab865 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -37,6 +37,7 @@
 #include "tst_coredump.h"
 #include "tst_buffers.h"
 #include "tst_capability.h"
+#include "tst_hugepage.h"
 
 /*
  * Reports testcase result.
diff --git a/lib/tst_hugepage.c b/lib/tst_hugepage.c
new file mode 100644
index 000000000..00cf90843
--- /dev/null
+++ b/lib/tst_hugepage.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ */
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+#include "tst_hugepage.h"
+
+int tst_request_hugepages(long hpages)
+{
+	int val;
+	long mem_avail, max_hpages;
+
+	if (FILE_LINES_SCANF("/proc/meminfo",
+				"MemAvailable: %ld", &mem_avail)) {
+		/*
+		 * Dropping caches and using "MemFree:" on kernel
+		 * that doesn't have "MemAvailable:" in Meminfo
+		 */
+		tst_res(TINFO, "MemAvailable: not found in /proc/meminfo");
+
+		SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
+		mem_avail = SAFE_READ_MEMINFO("MemFree:");
+	}
+
+	max_hpages = mem_avail / SAFE_READ_MEMINFO("Hugepagesize:");
+
+	if (hpages > max_hpages) {
+		tst_res(TINFO, "Request %ld hugepages failed, memory too fragmented? "
+				"The max hugepage available count %ld",
+				hpages, max_hpages);
+		return 0;
+	}
+
+	SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%ld", hpages);
+	SAFE_FILE_SCANF("/proc/sys/vm/nr_hugepages", "%d", &val);
+	if (val != hpages)
+		tst_brk(TBROK, "nr_hugepages = %d, but expect %ld", val, hpages);
+
+	return 1;
+}
-- 
2.20.1


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

* [LTP] [PATCH 2/2] pkey01: disable hugetlb test if failed to reserve hugepage
  2019-11-28  8:45 [LTP] [PATCH 1/2] lib: add tst_request_hugepages Li Wang
@ 2019-11-28  8:45 ` Li Wang
  2019-12-03 10:49 ` [LTP] [PATCH 1/2] lib: add tst_request_hugepages Cyril Hrubis
  1 sibling, 0 replies; 6+ messages in thread
From: Li Wang @ 2019-11-28  8:45 UTC (permalink / raw)
  To: ltp

To handle the false positive:
  pkey01.c:69: BROK: nr_hugepages = 0, but expect 1

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/syscalls/pkeys/pkey01.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/pkeys/pkey01.c b/testcases/kernel/syscalls/pkeys/pkey01.c
index fa84e71f3..b5831af37 100644
--- a/testcases/kernel/syscalls/pkeys/pkey01.c
+++ b/testcases/kernel/syscalls/pkeys/pkey01.c
@@ -61,13 +61,12 @@ static void setup(void)
 		size = getpagesize();
 		no_hugepage = 1;
 	} else {
-		int val;
-		SAFE_FILE_PRINTF(PATH_VM_NRHPS, "%d", 1);
-		SAFE_FILE_SCANF(PATH_VM_NRHPS, "%d", &val);
-		if (val != 1)
-			tst_brk(TBROK, "nr_hugepages = %d, but expect %d",
-					val, 1);
-		size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
+		if (tst_request_hugepages(1)) {
+			size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
+		} else {
+			size = getpagesize();
+			no_hugepage = 1;
+		}
 	}
 
 	check_pkey_support();
-- 
2.20.1


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

* [LTP] [PATCH 1/2] lib: add tst_request_hugepages
  2019-11-28  8:45 [LTP] [PATCH 1/2] lib: add tst_request_hugepages Li Wang
  2019-11-28  8:45 ` [LTP] [PATCH 2/2] pkey01: disable hugetlb test if failed to reserve hugepage Li Wang
@ 2019-12-03 10:49 ` Cyril Hrubis
  2019-12-04  6:40   ` Li Wang
  1 sibling, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2019-12-03 10:49 UTC (permalink / raw)
  To: ltp

Hi!
> Note: more and more tests need to configure hugepage before testing, so
> this is a start to add some useful hugetlb functions in global library
> for the whole LTP.
> 
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
>  include/tst_hugepage.h | 19 +++++++++++++++++++
>  include/tst_test.h     |  1 +
>  lib/tst_hugepage.c     | 43 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 63 insertions(+)
>  create mode 100644 include/tst_hugepage.h
>  create mode 100644 lib/tst_hugepage.c
> 
> diff --git a/include/tst_hugepage.h b/include/tst_hugepage.h
> new file mode 100644
> index 000000000..e06705bd0
> --- /dev/null
> +++ b/include/tst_hugepage.h
> @@ -0,0 +1,19 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2019 Red Hat, Inc.
> + */
> +
> +#ifndef TST_HUGEPAGE__
> +#define TST_HUGEPAGE__
> +
> +/*
> + * Try to request the specified number of huge pages from system.
> + *
> + * Note: this depend on the status of system memory fragmentation.
> + *       0 - reserve fail
> + *       1 - reserve success
> + */
> +int tst_request_hugepages(long hpages);

Can we add this to the tst_test structure so that test case use this as:

static struct tst_test test = {
	...
	.needs_hugepages = 1,
	...
}

That way it will be included in the test metadata I'm working on.

> +#endif /* TST_HUGEPAGE_H */
> +
> diff --git a/include/tst_test.h b/include/tst_test.h
> index 21c7dfbdb..7ec1ab865 100644
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -37,6 +37,7 @@
>  #include "tst_coredump.h"
>  #include "tst_buffers.h"
>  #include "tst_capability.h"
> +#include "tst_hugepage.h"
>  
>  /*
>   * Reports testcase result.
> diff --git a/lib/tst_hugepage.c b/lib/tst_hugepage.c
> new file mode 100644
> index 000000000..00cf90843
> --- /dev/null
> +++ b/lib/tst_hugepage.c
> @@ -0,0 +1,43 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2019 Red Hat, Inc.
> + */
> +
> +#define TST_NO_DEFAULT_MAIN
> +
> +#include "tst_test.h"
> +#include "tst_hugepage.h"
> +
> +int tst_request_hugepages(long hpages)
> +{
> +	int val;
> +	long mem_avail, max_hpages;
> +
> +	if (FILE_LINES_SCANF("/proc/meminfo",
> +				"MemAvailable: %ld", &mem_avail)) {
> +		/*
> +		 * Dropping caches and using "MemFree:" on kernel
> +		 * that doesn't have "MemAvailable:" in Meminfo
> +		 */
> +		tst_res(TINFO, "MemAvailable: not found in /proc/meminfo");
> +
> +		SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
> +		mem_avail = SAFE_READ_MEMINFO("MemFree:");
> +	}
> +
> +	max_hpages = mem_avail / SAFE_READ_MEMINFO("Hugepagesize:");
> +
> +	if (hpages > max_hpages) {
> +		tst_res(TINFO, "Request %ld hugepages failed, memory too fragmented? "
> +				"The max hugepage available count %ld",
> +				hpages, max_hpages);
> +		return 0;

I guess that rest of the library functions returns non-zero on failure.

> +	}
> +
> +	SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%ld", hpages);
> +	SAFE_FILE_SCANF("/proc/sys/vm/nr_hugepages", "%d", &val);
> +	if (val != hpages)
> +		tst_brk(TBROK, "nr_hugepages = %d, but expect %ld", val, hpages);
> +
> +	return 1;

I guess that things will be more complicated than this. If there is
already a pool of hugepages allocated on the machine and some are used
this will utimatelly fail.

I rember that we changed some tests to increase the nr_hugepages if
needed instead of blindly writing values there.

Also this fails to cleanup after itself, we have to restore the system
after the test, which is one more reason why we need .needs_hugepages in
the tst_test structure because the test library can cleanup after the
test with that.

> +}
> -- 
> 2.20.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 1/2] lib: add tst_request_hugepages
  2019-12-03 10:49 ` [LTP] [PATCH 1/2] lib: add tst_request_hugepages Cyril Hrubis
@ 2019-12-04  6:40   ` Li Wang
  2019-12-04  9:26     ` Li Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Li Wang @ 2019-12-04  6:40 UTC (permalink / raw)
  To: ltp

On Tue, Dec 3, 2019 at 6:49 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> ...
>
> Can we add this to the tst_test structure so that test case use this as:
>
> static struct tst_test test = {
>         ...
>         .needs_hugepages = 1,
>         ...
> }
>
>
Good point.


> That way it will be included in the test metadata I'm working on.
>
> ...
> > +
> > +     if (hpages > max_hpages) {
> > +             tst_res(TINFO, "Request %ld hugepages failed, memory too
> fragmented? "
> > +                             "The max hugepage available count %ld",
> > +                             hpages, max_hpages);
> > +             return 0;
>
> I guess that rest of the library functions returns non-zero on failure.
>

Sure, will reset the value for return.


>
> > +     }
> > +
> > +     SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%ld", hpages);
> > +     SAFE_FILE_SCANF("/proc/sys/vm/nr_hugepages", "%d", &val);
> > +     if (val != hpages)
> > +             tst_brk(TBROK, "nr_hugepages = %d, but expect %ld", val,
> hpages);
> > +
> > +     return 1;
>
> I guess that things will be more complicated than this. If there is
> already a pool of hugepages allocated on the machine and some are used
> this will utimatelly fail.
>

I don't think so, if they're already many huge pages being used, the free
memory of the system will firstly tell us the max_hpages is not satisfy for
testing, it means we have no chance to arrive here.


>
> I rember that we changed some tests to increase the nr_hugepages if
> needed instead of blindly writing values there.
>

Yes, but that's only fit for the situation which does not need the precise
number of pages, we could take 80% of the max_hpages and do our testing in
our system.

But in this function, my purpose is to request the least number of pages
for the test. e.g if the .needs_hugepages is set to an expected number, we
should verify strictly if the system can provide that.


>
> Also this fails to cleanup after itself, we have to restore the system
> after the test, which is one more reason why we need .needs_hugepages in
> the tst_test structure because the test library can cleanup after the
> test with that.
>

Agree, I will add the save/restore part for this.

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191204/d52cedff/attachment.htm>

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

* [LTP] [PATCH 1/2] lib: add tst_request_hugepages
  2019-12-04  6:40   ` Li Wang
@ 2019-12-04  9:26     ` Li Wang
  2019-12-04 11:10       ` Cyril Hrubis
  0 siblings, 1 reply; 6+ messages in thread
From: Li Wang @ 2019-12-04  9:26 UTC (permalink / raw)
  To: ltp

On Wed, Dec 4, 2019 at 2:40 PM Li Wang <liwang@redhat.com> wrote:

> ...
> if the .needs_hugepages is set to an expected number, we should verify
> strictly if the system can provide that.
>

Oh, I guess maybe I misunderstand your suggestion here. you mean just to
let .needs_hugepages = 1 but not set an expected number, right? if so, that
will more easy to achieve.


>
>> Also this fails to cleanup after itself, we have to restore the system
>> after the test, which is one more reason why we need .needs_hugepages in
>> the tst_test structure because the test library can cleanup after the
>> test with that.
>>
>
> Agree, I will add the save/restore part for this.
>

Or just go with .save_restore in the testcase?

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191204/6ae5a7b1/attachment.htm>

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

* [LTP] [PATCH 1/2] lib: add tst_request_hugepages
  2019-12-04  9:26     ` Li Wang
@ 2019-12-04 11:10       ` Cyril Hrubis
  0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2019-12-04 11:10 UTC (permalink / raw)
  To: ltp

Hi!
> > if the .needs_hugepages is set to an expected number, we should verify
> > strictly if the system can provide that.
> >
> 
> Oh, I guess maybe I misunderstand your suggestion here. you mean just to
> let .needs_hugepages = 1 but not set an expected number, right? if so, that
> will more easy to achieve.

We do have tests that needs more than 1 hugepage, there are tests that
do numa migration so we likely need the needs_hugepages to be unsigned
integer that represents the number of required hugepages.

> >> Also this fails to cleanup after itself, we have to restore the system
> >> after the test, which is one more reason why we need .needs_hugepages in
> >> the tst_test structure because the test library can cleanup after the
> >> test with that.
> >>
> >
> > Agree, I will add the save/restore part for this.
> >
> 
> Or just go with .save_restore in the testcase?

I guess that best option would be to call tst_sys_conf_save_str() in the
test library if we decided to change the nr_hugepages file.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2019-12-04 11:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-28  8:45 [LTP] [PATCH 1/2] lib: add tst_request_hugepages Li Wang
2019-11-28  8:45 ` [LTP] [PATCH 2/2] pkey01: disable hugetlb test if failed to reserve hugepage Li Wang
2019-12-03 10:49 ` [LTP] [PATCH 1/2] lib: add tst_request_hugepages Cyril Hrubis
2019-12-04  6:40   ` Li Wang
2019-12-04  9:26     ` Li Wang
2019-12-04 11:10       ` 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.