All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH] mem/hugeshmat: new case for hugepage leak inspection
Date: Tue, 6 Jan 2015 04:51:52 -0500 (EST)	[thread overview]
Message-ID: <1759699028.3904548.1420537912980.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <124148100.2234995.1420452985543.JavaMail.zimbra@redhat.com>


> ----- Original Message -----
> > From: "Li Wang" <liwang@redhat.com>
> > To: "Jan Stancek" <jstancek@redhat.com>
> > Cc: ltp-list@lists.sourceforge.net
> > Sent: Sunday, 4 January, 2015 4:10:38 AM
> > Subject: Re: [LTP] [PATCH] mem/hugeshmat: new case for hugepage leak
> > inspection
> > 
> > The regression has a long history, Patch in upstream 2.6.20-rc1
> > GIT: 39dde65c9940c97fcd178a3d2b1c57ed8b7b68aa.
> > https://lkml.org/lkml/2012/4/16/129
> 
> And fix is presumably this commit:
> 
> ommit c5c99429fa57dcf6e05203ebe3676db1ec646793
> Author: Larry Woodman <lwoodman@redhat.com>
> Date:   Thu Jan 24 05:49:25 2008 -0800
>     fix hugepages leak due to pagetable page sharing
> 
> It'd be nice to include this information somewhere in testcase or commit
> message.
> More comments below:
...
> > > > +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);
> 
> Does it make a difference where you attach shared segment? I'm slightly
> worried,
> that absolute address you picked may already be in use on some
> distros/arches.

Hi Jan,

Thank you for reviewing my stupid patch. :)

Actually I also don't know why using absolute address here, I doubt this 
manner are similar with the BZ occurred environment. The sleep(3) below as well.

Since the original case is too old to found out who is the author. I hope someone 
now could provide any useful discussion here, if not, I still feel we can use these 
code to cover the regression. What do you think?


A new patch:

Subject: [PATCH] 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.

The fix is this commit:
	commit c5c99429fa57dcf6e05203ebe3676db1ec646793
	Author: Larry Woodman <lwoodman@redhat.com>
	Date:   Thu Jan 24 05:49:25 2008 -0800
    	fix hugepages leak due to pagetable page sharing

Signed-off-by: Li Wang <liwang@redhat.com>
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 runtest/hugetlb                                    |   1 +
 testcases/kernel/mem/.gitignore                    |   1 +
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat04.c     | 166 +++++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 3eaf14c..805141d 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -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
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index f96964c..c531563 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
new file mode 100644
index 0000000..43e9f3f
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -0,0 +1,166 @@
+/*
+ *   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
+ *
+ *	Test results:
+ *	   Successed: No regression found.
+ *	   Failed:    Regression 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 long huge_total;
+static long huge_free;
+static long huge_free2;
+static long hugepages;
+static long orig_hugepages;
+
+static void shared_hugepage(void);
+
+int main(int ac, char **av)
+{
+	int lc, i;
+	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++) {
+
+			shared_hugepage();
+			huge_free2 = read_meminfo("HugePages_Free:");
+
+			if (huge_free2 != huge_free)
+				tst_brkm(TFAIL, cleanup,
+					"Test failed. Hugepage leak inspection.");
+			else
+				tst_resm(TPASS, "No regression found.");
+		}
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+void 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);
+}
+
+void setup(void)
+{
+	long mem_total, hpage_size;
+
+	tst_require_root(NULL);
+
+	mem_total = read_meminfo("MemTotal:") * 1024;
+	if (mem_total < 2L*SIZE) {
+		tst_resm(TINFO, "Total memory should greater than 2G.");
+		tst_exit();
+	}
+
+	orig_hugepages = get_sys_tune("nr_hugepages");
+	hpage_size = read_meminfo("Hugepagesize:") * 1024;
+
+	hugepages = (orig_hugepages * hpage_size + SIZE) / hpage_size;
+	set_sys_tune("nr_hugepages", hugepages, 1);
+
+	huge_total = read_meminfo("HugePages_Total:");
+	huge_free = read_meminfo("HugePages_Free:");
+
+	if (huge_total != hugepages || huge_free != hugepages)
+		tst_brkm(TCONF, cleanup,
+			"Maybe huge pages not enough for test.");
+
+	TEST_PAUSE;
+}
+
+void cleanup(void)
+{
+	TEST_CLEANUP;
+	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+}
-- 
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2015-01-06  9:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-27  7:13 [LTP] [PATCH] mem/hugeshmat: new case for hugepage leak inspection Li Wang
2014-12-30  9:23 ` Jan Stancek
2015-01-04  3:10   ` Li Wang
2015-01-05 10:16     ` Jan Stancek
2015-01-06  9:51       ` Li Wang [this message]
2015-01-06 10:35         ` Jan Stancek
2015-01-06 14:07           ` Li Wang
2015-01-07 12:32             ` Jan Stancek
2015-01-07 14:59               ` Li Wang
2015-01-26 16:48                 ` Cyril Hrubis
2014-12-28  3:20 Li Wang
     [not found] <1419737900-6117-1-git-send-email-liwang@redhat.com>
2014-12-28  4:06 ` Li Wang
     [not found] <1422336738-617-1-git-send-email-liwang@redhat.com>
2015-01-27 15:31 ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1759699028.3904548.1420537912980.JavaMail.zimbra@redhat.com \
    --to=liwang@redhat.com \
    --cc=jstancek@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.