Skip to contentSkip to conversation

hugetlb/hugemmap01: dynamically change default hugepages

PATCH New Xiao Liang 2 participants 4 messages Apr 3, 2019 – Apr 4, 2019 1 message not in the archive

lore
Share & tools
lore

Xiao Liang

author
#0 lore raw

PATCH 1/1 hugetlb/hugemmap01: dynamically change default hugepages

When the system's Hugepagesize is large(eg. 512MiB), the test may break as cannot set nr_hugepages to default 128.

This patch checks the memory available and Hugepagesize registered to set a reasonable num.

With this patch:
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s hugemmap01.c:99: INFO: max page available count is 54 mem.c:814: INFO: set nr_hugepages to 54 hugemmap01.c:73: PASS: call succeeded mem.c:814: INFO: set nr_hugepages to 0

Without this patch:
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s mem.c:814: INFO: set nr_hugepages to 128 mem.c:823: BROK: nr_hugepages = 54, but expect 128 mem.c:814: INFO: set nr_hugepages to 0

---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c +13 -1
index 4dc330dc0..ea2f42827 100644
@@ -89,14 +89,26 @@ static void test_hugemmap(void)
 
 void setup(void)
 {
+	long page_sz = 0;
+	long mem_avail = 0;
+	long max_pages = 0;
+
+	page_sz = SAFE_READ_MEMINFO("Hugepagesize:");
+	mem_avail = SAFE_READ_MEMINFO("MemAvailable:");
+	max_pages = mem_avail/page_sz;
+	tst_res(TINFO, "max page available count is %ld", max_pages);
+
 	save_nr_hugepages();
 
 	if (!Hopt)
 		Hopt = tst_get_tmpdir();
 	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
 
-	if (nr_opt)
+	if (nr_opt) {
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
+	} else {
+		hugepages=(page_sz*hugepages>mem_avail)?max_pages:hugepages;
+	}
 	set_sys_tune("nr_hugepages", hugepages, 1);
 
 	snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt, getpid());
Signature · 1 line
2.17.2
#1 lore raw

PATCH 1/1 hugetlb/hugemmap01: dynamically change default hugepages

Hi Xiao,

Quoted 3 lines · Xiao Liang

When the system's Hugepagesize is large(eg. 512MiB), the test may break as cannot set nr_hugepages to default 128.

Yes, that's true. But each of ltp/hugemmap test has a parameter(hugemmap01 -s #nr_hpage#) to reset the nr_huagepges number before testing. What we have done to avoid that is to customize the hugetlb runtest file via a wrapper script.

Quoted 4 lines

This patch checks the memory available and Hugepagesize registered to set a reasonable num.

I have no objection on this way. But a better way maybe to achieve a new function in the hugetlb library to reset nr_hugepages dynamically for the whole hugepage tests.

Quoted 61 lines

With this patch:
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s hugemmap01.c:99: INFO: max page available count is 54 mem.c:814: INFO: set nr_hugepages to 54 hugemmap01.c:73: PASS: call succeeded mem.c:814: INFO: set nr_hugepages to 0

Without this patch:
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s mem.c:814: INFO: set nr_hugepages to 128 mem.c:823: BROK: nr_hugepages = 54, but expect 128 mem.c:814: INFO: set nr_hugepages to 0

---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c +13 -1
index 4dc330dc0..ea2f42827 100644
@@ -89,14 +89,26 @@ static void test_hugemmap(void)
 
 void setup(void)
 {
+       long page_sz = 0;
+       long mem_avail = 0;
+       long max_pages = 0;
+
+       page_sz = SAFE_READ_MEMINFO("Hugepagesize:");
+       mem_avail = SAFE_READ_MEMINFO("MemAvailable:");
+       max_pages = mem_avail/page_sz;
+       tst_res(TINFO, "max page available count is %ld", max_pages);
+
        save_nr_hugepages();
 
        if (!Hopt)
                Hopt = tst_get_tmpdir();
        SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
 
-       if (nr_opt)
+       if (nr_opt) {
                hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
+       } else {
+
 hugepages=(page_sz*hugepages>mem_avail)?max_pages:hugepages;
+       }
        set_sys_tune("nr_hugepages", hugepages, 1);
 

snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt,
getpid());
--
2.17.2

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

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190403/b87c88fd/attachment.html>

A message that is not in the archive (sent off-list or not yet received): CAAb+4C6Jf2iLCcAXiaYdoBv_YG=7s7K2vUw0mNyX0qXTS4SGpA@mail.gmail.com

#3 lore raw

PATCH 1/1 hugetlb/hugemmap01: dynamically change default hugepages

[Cc' LTP mailling list] To respect the ML:).

Quoted 27 lines · Xiao Liang
Quoted 4 lines · Li Wang

Hi Xiao,

On Wed, Apr 3, 2019 at 7:56 PM Xiao Liang <[email protected]> wrote:

Quoted 9 lines
Quoted 3 lines

When the system's Hugepagesize is large(eg. 512MiB), the test may break as cannot set nr_hugepages to default 128.

Yes, that's true. But each of ltp/hugemmap test has a parameter(hugemmap01 -s #nr_hpage#) to reset the nr_huagepges number before testing. What we have done to avoid that is to customize the hugetlb runtest file via a wrapper script.

Yes, I tried '-s' option too, but runtest file does not specify it.
Although default 128 works in most situations, I feel it is not very convenient for users to specify it or need double check it in each run in different platforms.

Quoted 5 lines
Quoted 4 lines

This patch checks the memory available and Hugepagesize registered to set a reasonable num.

Quoted 7 lines
Quoted 4 lines

I have no objection on this way. But a better way maybe to achieve a new function in the hugetlb library to reset nr_hugepages dynamically for the whole hugepage tests.

Yes. I prefer this way than hard coding it with 128. I think we can add a new function into library as other cases use it too.

Ok, It'd be great if you can help to draft a new patch for this.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190404/6e414519/attachment.html>
author
#4 lore raw

PATCH 1/1 hugetlb/hugemmap01: dynamically change default hugepages

Quoted 3 lines · Li Wang

[Cc' LTP mailling list] To respect the ML:).

Maybe I click reply directly. :)

Quoted 34 lines · Xiao Liang
Quoted 32 lines · Li Wang
Quoted 5 lines

Hi Xiao,

On Wed, Apr 3, 2019 at 7:56 PM Xiao Liang <[email protected]> wrote:

Quoted 9 lines
Quoted 3 lines

When the system's Hugepagesize is large(eg. 512MiB), the test may break as cannot set nr_hugepages to default 128.

Yes, that's true. But each of ltp/hugemmap test has a parameter(hugemmap01 -s #nr_hpage#) to reset the nr_huagepges number before testing. What we have done to avoid that is to customize the hugetlb runtest file via a wrapper script.

Yes, I tried '-s' option too, but runtest file does not specify it.
Although default 128 works in most situations, I feel it is not very convenient for users to specify it or need double check it in each run in different platforms.

Quoted 9 lines
Quoted 4 lines

This patch checks the memory available and Hugepagesize registered to set a reasonable num.

I have no objection on this way. But a better way maybe to achieve a new function in the hugetlb library to reset nr_hugepages dynamically for the whole hugepage tests.

Quoted 6 lines
Quoted 3 lines

Yes. I prefer this way than hard coding it with 128. I think we can add a new function into library as other cases use it too.

Ok, It'd be great if you can help to draft a new patch for this.

I will prepare new patch now. Thanks

Quoted 5 lines

--
Regards,
Li Wang

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190404/83b12c0a/attachment.html>