All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] mm/oom: add oom control check for memcg
@ 2012-02-27 12:41 Caspar Zhang
  2012-03-09 17:39 ` Caspar Zhang
  0 siblings, 1 reply; 2+ messages in thread
From: Caspar Zhang @ 2012-02-27 12:41 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 503 bytes --]


upstream commit: 9490ff2 implements OOM notifier using cgroup
notification API, which allows applications to be notified when OOM
happens in memory cgroups. This patch adds oom control checking when
executing oom tests.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 configure.ac                       |    1 +
 testcases/kernel/mem/include/mem.h |    4 +++
 testcases/kernel/mem/lib/mem.c     |   40 +++++++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 1 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-mm-oom-add-oom-control-check-for-memcg.patch --]
[-- Type: text/x-patch; name="0001-mm-oom-add-oom-control-check-for-memcg.patch", Size: 2778 bytes --]

diff --git a/configure.ac b/configure.ac
index 1696df0..21b3137 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,7 @@ AC_CHECK_HEADERS([ \
     linux/module.h \
     linux/netlink.h \
     sys/epoll.h \
+    sys/eventfd.h \
     sys/inotify.h \
     sys/jfsdmapi.h \
     sys/prctl.h \
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 4464c29..fe88861 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -25,6 +25,10 @@
 #define PATH_KSM		"/sys/kernel/mm/ksm/"
 #define PATH_SYSVM		"/proc/sys/vm/"
 #define PATH_MEMINFO		"/proc/meminfo"
+#if HAVE_SYS_EVENTFD_H
+#define PATH_OOMCTRL		MEMCG_PATH_NEW "/memory.oom_control"
+#define PATH_EVTCTRL		MEMCG_PATH_NEW "/cgroup.event_control"
+#endif
 
 int opt_num, opt_size, opt_unit;
 char *opt_numstr, *opt_sizestr, *opt_unitstr;
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index a83eef1..876f430 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -1,5 +1,8 @@
 #include "config.h"
 #include <sys/types.h>
+#if HAVE_SYS_EVENTFD_H
+#include <sys/eventfd.h>
+#endif
 #include <sys/mman.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
@@ -67,6 +70,28 @@ void oom(int testcase, int mempolicy, int lite)
 	&& HAVE_MPOL_CONSTANTS
 	unsigned long nmask = 2;
 #endif
+#if HAVE_SYS_EVENTFD_H
+	int efd = 0, ofd = 0;
+	char buf[BUFSIZ];
+	uint64_t u;
+#endif
+
+#if HAVE_SYS_EVENTFD_H
+	if (path_exist(PATH_OOMCTRL) && path_exist(PATH_EVTCTRL)) {
+		efd = eventfd(0, 0);
+		if (efd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "eventfd");
+		ofd = open(PATH_OOMCTRL, O_RDWR);
+		if (ofd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup,
+				"open %s", PATH_OOMCTRL);
+		if (write(ofd, "0", 1) != 1)
+			tst_brkm(TBROK|TERRNO, cleanup,
+				"write %s", PATH_OOMCTRL);
+		snprintf(buf, BUFSIZ, "%d %d", efd, ofd);
+		write_file(PATH_EVTCTRL, buf);
+	}
+#endif
 
 	switch (pid = fork()) {
 	case -1:
@@ -97,6 +122,19 @@ void oom(int testcase, int mempolicy, int lite)
 			tst_resm(TFAIL, "the victim unexpectedly failed: %d",
 				status);
 	}
+#if HAVE_SYS_EVENTFD_H
+	if (path_exist(PATH_OOMCTRL) && path_exist(PATH_EVTCTRL)) {
+		if (read(efd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
+			tst_resm(TFAIL|TERRNO, "fail to receive oom event.");
+		else
+			tst_resm(TINFO, "memcg oom event received %lu.", u);
+
+		if (efd > 0)
+			close(efd);
+		if (ofd > 0)
+			close(ofd);
+	}
+#endif
 }
 
 void testoom(int mempolicy, int lite, int numa)
@@ -737,7 +775,7 @@ long count_numa(long nodes[])
 
 	nnodes = 0;
 	for (i = 0; i <= MAXNODES; i++)
-		if(path_exist(PATH_SYS_SYSTEM "/node/node%d", i))
+		if (path_exist(PATH_SYS_SYSTEM "/node/node%d", i))
 			nodes[nnodes++] = i;
 
 	return nnodes;

[-- Attachment #3: Type: text/plain, Size: 377 bytes --]

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mm/oom: add oom control check for memcg
  2012-02-27 12:41 [LTP] [PATCH] mm/oom: add oom control check for memcg Caspar Zhang
@ 2012-03-09 17:39 ` Caspar Zhang
  0 siblings, 0 replies; 2+ messages in thread
From: Caspar Zhang @ 2012-03-09 17:39 UTC (permalink / raw)
  To: LTP List

On 02/27/2012 08:41 PM, Caspar Zhang wrote:
> 
> upstream commit: 9490ff2 implements OOM notifier using cgroup
> notification API, which allows applications to be notified when OOM
> happens in memory cgroups. This patch adds oom control checking when
> executing oom tests.
> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
> ---
>  configure.ac                       |    1 +
>  testcases/kernel/mem/include/mem.h |    4 +++
>  testcases/kernel/mem/lib/mem.c     |   40 +++++++++++++++++++++++++++++++++++-
>  3 files changed, 44 insertions(+), 1 deletions(-)
> 

FYI. This one has been committed since no objection seen so far.

Thanks,
Caspar

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2012-03-09 17:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-27 12:41 [LTP] [PATCH] mm/oom: add oom control check for memcg Caspar Zhang
2012-03-09 17:39 ` Caspar Zhang

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.