<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 4, 2019 at 1:44 PM Xiao Liang <<a href="mailto:xiliang@redhat.com">xiliang@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">When the system's Hugepagesize is large(eg. 512MiB), the test may<br>
break as cannot set nr_hugepages to default 128.<br>
<br>
This patch continue to use 128 as default hugepages, but it checks<br>
the memory available and Hugepagesize registered. If default 128 is<br>
larger than available count, then use the small one.<br>
<br>
With this patch:<br>
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s<br>
hugemmap01.c:99: INFO: max page available count is 54<br>
mem.c:814: INFO: set nr_hugepages to 54<br>
hugemmap01.c:73: PASS: call succeeded<br>
mem.c:814: INFO: set nr_hugepages to 0<br>
<br>
Without this patch:<br>
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s<br>
mem.c:814: INFO: set nr_hugepages to 128<br>
mem.c:823: BROK: nr_hugepages = 54, but expect 128<br>
mem.c:814: INFO: set nr_hugepages to 0<br>
<br><span class="gmail_default" style="font-size:small">[...snip...]</span><br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c<br>
index 841f527b7..998bee717 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c<br>
@@ -79,8 +79,11 @@ void setup(void)<br>
long hpage_size;<br>
<br>
save_nr_hugepages();<br>
- if (nr_opt)<br>
+ if (nr_opt) {<br>
hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);<br>
+ } else {<br>
+ hugepages = get_available_hugepages();<br>
+ }<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">There are still have two disadvantages if code change like these above.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">1. No ganrantee for each hugepage test to initialize their default hugepages to 128. Suppose that if a new hugemmap07 is created with 'hugepages == 100' (or anything else but not 128), then this patch is make no sense to it. What we can do maybe just to create a simple function get_max_hugepages() in libarary.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">2. if someone pass an improper value to hugepages via '-s #big_number#', that would still break this test as what you hit before.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">So a wiser method is probably to compare a decided(no matter setting by ltp user or using default 128) huagepages with the max avaliable hugepages which system can provides. If the default value is larger than system max_hugepages, just use the proper one.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Something I'm thinking maybe like:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">In hugemmap01.c:</div><div class="gmail_default" style="font-size:small">---------------</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default">void setup(void)</div><div class="gmail_default">{</div><div class="gmail_default"><span style="white-space:pre"> </span>...</div><div class="gmail_default"><br></div><div class="gmail_default"><span style="white-space:pre"> </span>if (nr_opt)</div><div class="gmail_default"><span style="white-space:pre"> </span>hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);</div><div class="gmail_default"><br></div><div class="gmail_default"><span style="white-space:pre"> </span>if (hugepages > get_max_hugepages()) {</div><div class="gmail_default"><span style="white-space:pre"> </span>tst_res(TINFO, "The hugepages beyond system available, here "</div><div class="gmail_default"><span style="white-space:pre"> </span>"reset to 80%% of the max page count %ld",</div><div class="gmail_default"><span style="white-space:pre"> </span>get_max_hugepages());</div><div class="gmail_default"><span style="white-space:pre"> </span>hugepages = get_max_hugepages() * 0.8;</div><div class="gmail_default"><span style="white-space:pre"> </span>}</div><div class="gmail_default"><br></div><div class="gmail_default"><span style="white-space:pre"> </span>...</div><div class="gmail_default">}</div><div style="font-size:small"><br></div><div style="font-size:small">In hugetlb libarary:</div><div style="font-size:small">---------------</div><div style="font-size:small"><div>long get_max_hugepages(void)</div><div>{</div><div><span style="white-space:pre"> </span>return SAFE_READ_MEMINFO("MemFree:") / SAFE_READ_MEMINFO("Hugepagesize:");</div><div>}</div><div><br></div></div></div><div class="gmail_default" style="font-size:small">More declaration: </div><div class="gmail_default" style="font-size:small">I found that some old platforms(e.g. rhel6 i686) has no "MemAvailable:" in their /proc/meminfo, so I'd take use of "MemFree:" as an replacement. About to set hugepages only as 80% of the max pages count, is becuase of memory fragment issue, we cann't always get sequential meory to all reserve as huage pages, so this is to avoid the nr_hugepages setting failure in next step.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">And what do you think? comment?</div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
set_sys_tune("nr_hugepages", hugepages, 1);<br>
hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;<br>
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.c b/testcases/kernel/mem/hugetlb/lib/hugetlb.c<br>
index 1ea47ebb5..dacbe4918 100644<br>
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.c<br>
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.c<br>
@@ -56,6 +56,22 @@ void restore_nr_hugepages(void)<br>
set_sys_tune("nr_hugepages", orig_hugepages, 0);<br>
}<br>
<br>
+long get_available_hugepages(void)<br>
+{<br>
+ long page_sz = 0;</blockquote><div><br></div><div class="gmail_default" style="font-size:small">maybe declare as hpage_sz ?</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ long mem_avail = 0;<br>
+ long max_pages = 0;<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">max_hpages?</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ long hugepages = 128;<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Or, these local variable are redundant to the function.</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ page_sz = SAFE_READ_MEMINFO("Hugepagesize:");<br>
+ mem_avail = SAFE_READ_MEMINFO("MemAvailable:");<br>
+ max_pages = mem_avail/page_sz;<br>
+ tst_res(TINFO, "max page available count is %ld", max_pages);<br>
+ hugepages=(page_sz*hugepages>mem_avail)?max_pages:hugepages;<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">Spaces are required between the operation expression.</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ return hugepages;<br>
+}<br>
+<br>
/*<br>
* getipckey() - generates and returns a message key used by the "get"<br>
* calls to create an IPC resource.<br>
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h<br>
index 2843f0a8e..48a8d08f3 100644<br>
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.h<br>
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h<br>
@@ -58,5 +58,6 @@ char *Hopt;<br>
void check_hugepage(void);<br>
long save_nr_hugepages(void);<br>
void restore_nr_hugepages(void);<br>
+long get_available_hugepages(void);<br>
<br>
#endif /* hugetlb.h */<br>
-- <br>
2.17.2<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>