Skip to contentSkip to conversation

mem/hugeshmat: new case for hugepage leak inspection

PATCH New Li Wang 3 participants 3 messages Dec 28, 2014 – Jan 26, 2015 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Li Wang

author
#1 lore raw

PATCH 1/1 mem/hugeshmat: new case for hugepage leak inspection

Description of Problem:
When over 1GB shared memory was alocated in hugepage, the hugepage is not released though process finished.

---
 runtest/hugetlb                                    |   1 +
 testcases/kernel/mem/.gitignore                    |   1 +
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat04.c     | 185 +++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
runtest/hugetlb +1 -0
index 3eaf14c..805141d 100644
@@ -10,6 +10,7 @@ hugemmap05_3 hugemmap05 -s -m
 hugeshmat01 hugeshmat01 -i 5
 hugeshmat02 hugeshmat02 -i 5
 hugeshmat03 hugeshmat03 -i 5
+hugeshmat04 hugeshamt04 -i 5
 
 hugeshmctl01 hugeshmctl01 -i 5
 hugeshmctl02 hugeshmctl02 -i 5
testcases/kernel/mem/.gitignore +1 -0
index f96964c..c531563 100644
@@ -6,6 +6,7 @@
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
+/hugetlb/hugeshmat/hugeshmat04
 /hugetlb/hugeshmctl/hugeshmctl01
 /hugetlb/hugeshmctl/hugeshmctl02
 /hugetlb/hugeshmctl/hugeshmctl03
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c new file +185 -0

185 lines not on this page · raw message

Signature · 13 lines
1.8.3.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

PATCH 1/1 mem/hugeshmat: new case for hugepage leak inspection

Description of Problem:
When over 1GB shared memory was alocated in hugepage, the hugepage is not released though process finished.

---
 runtest/hugetlb                                    |   1 +
 testcases/kernel/mem/.gitignore                    |   1 +
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat04.c     | 185 +++++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
runtest/hugetlb +1 -0
index 3eaf14c..805141d 100644
@@ -10,6 +10,7 @@ hugemmap05_3 hugemmap05 -s -m
 hugeshmat01 hugeshmat01 -i 5
 hugeshmat02 hugeshmat02 -i 5
 hugeshmat03 hugeshmat03 -i 5
+hugeshmat04 hugeshamt04 -i 5
 
 hugeshmctl01 hugeshmctl01 -i 5
 hugeshmctl02 hugeshmctl02 -i 5
testcases/kernel/mem/.gitignore +1 -0
index f96964c..c531563 100644
@@ -6,6 +6,7 @@
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
+/hugetlb/hugeshmat/hugeshmat04
 /hugetlb/hugeshmctl/hugeshmctl01
 /hugetlb/hugeshmctl/hugeshmctl02
 /hugetlb/hugeshmctl/hugeshmctl03
(quoted diff) +0 -0

b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c new file mode 100644
index 0000000..efa8a73

testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c new file +16 -0
@@ -0,0 +1,185 @@
+/*
+ *   Copyright (c) Linux Test Project, 2014
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA

02110-1301 USA
+ */
+
+/*
+ * NAME
+ * hugeshmat04.c
+ *
+ * DESCRIPTION
+ * hugeshmat04 - test for hugepage leak inspection.
+ *
+ * Description of Problem:
+ * When over 1GB shered memory was alocated in hugepage, the hugepage
+ * is not released though process finished.
+ *
+ * You need more than 2GB memory in test job
+ *
+ * Return value:

+ *       0:     Test successed.  No regression found.
+ *       1:     Test failed.  Maybe memory shortage.  Please retry testing.
+ *       2:     Test failed.  Regression detected.
+ *       other: Test failed.  Other problem detected.

+ *
+ * HISTORY
+ * 05/2014 - Written by Fujistu Corp.
+ * 12/2014 - Port to LTP by Li Wang.
+ *
+ * RESTRICTIONS
+ * test must be run at root
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/shm.h>
+#include <sys/wait.h>
+
+#include "test.h"
+#include "mem.h"
+
+#define SIZE (1024 * 1024 * 1024)
+#define BOUNDARY (1024 * 1024 * 1024)
+
+char *TCID = "hugeshmat04";
+int TST_TOTAL = 3;
+
+static int huge_total;
+static int huge_free;
+static int huge_free2;
+static long hugepages;
+static long orig_hugepages;
+
+static int shared_hugepage(void);
+
+
+int main(int ac, char **av)
+{
+ int lc, i, ret;
+ const char *msg;
+
+ msg = parse_opts(ac,av, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ for (i = 0; i < TST_TOTAL; i++) {
+ huge_total = read_meminfo("HugePages_Total:");
+ huge_free = read_meminfo("HugePages_Free:");
+
+ if (huge_total == hugepages && huge_free == hugepages) {
+ ret = shared_hugepage();
+
+ huge_free2 = read_meminfo("HugePages_Free:");
+ if (huge_free2 != huge_free)
+ ret = 2;
+ } else {
+ ret = 1;
+ }
+
+ switch (ret) {
+ case 0:
+ tst_resm(TPASS,
+ "No regression found.");
+ break;
+ case 1:
+ tst_brkm(TFAIL, cleanup,
+ "Test failed. Maybe memory shortage.");
+ break;
+ case 2:
+ tst_brkm(TFAIL, cleanup,
+ "Test failed. Hugepage leak
inspection.");
+ break;
+ default:
+ tst_brkm(TFAIL, cleanup,
+ "Test failed. Other problem detected.");
+ break;
+ }
+
+ }

+       }
+       cleanup();
+       tst_exit();

+}
+
+int shared_hugepage(void)
+{

+       pid_t pid;
+       int status, shmid;
+       size_t size = (size_t)SIZE;
+       void *buf;

+
+ shmid = shmget(IPC_PRIVATE, size, SHM_HUGETLB | IPC_CREAT | 0777);
+ if (shmid < 0)
+ tst_brkm(TBROK | TERRNO, cleanup, "shmget");
+
+ buf = shmat(shmid, (void *)BOUNDARY, SHM_RND | 0777);
+ if ( buf == (void *)-1 ) {
+ shmctl(shmid, IPC_RMID, NULL);
+ tst_brkm(TBROK | TERRNO, cleanup, "shmat");
+ }
+

+       memset(buf, 2, size);
+       sleep(3);
+       pid = fork();

+
+ if (pid == 0)
+ exit(1);
+ else if (pid < 0)
+ tst_brkm(TBROK | TERRNO, cleanup, "fork");
+

+       wait(&status);
+       shmdt(buf);
+       shmctl(shmid, IPC_RMID, NULL);

+
+ return 0;
+}
+
+void setup(void)
+{
+ long mem_total, hpage_size;
+
+ tst_require_root(NULL);
+
+ mem_total = read_meminfo("MemTotal:");
+ if (mem_total < 2097152) {
+ tst_resm(TINFO, "Total memory should greater than 2G.");
+ tst_exit();
+ }
+
+ orig_hugepages = get_sys_tune("nr_hugepages");
+ hpage_size = read_meminfo("Hugepagesize:");
+
+ hugepages = (orig_hugepages * hpage_size + 1048576) / hpage_size;
+ set_sys_tune("nr_hugepages", hugepages, 1);
+
+ TEST_PAUSE;
+}
+
+void cleanup(void)
+{
+ TEST_CLEANUP;
+ set_sys_tune("nr_hugepages", orig_hugepages, 0);
+}
--
1.8.3.1

Signature · 14 lines
Regards,
Li Wang
Email: [email protected]

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#4 lore raw

Hi!

Quoted 5 lines

Description of Problem:
When over 1GB shared memory was alocated in hugepage, the hugepage is not released though process finished.

Ah, there is another version. Usually people add version number to the email subject so that is clear which patch is the newest and include short list of changes from the previous versions...

Which one is the latest version?

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list