All of lore.kernel.org
 help / color / mirror / Atom feed
* user-cr thread safety
@ 2010-07-26 18:37 Nathan Lynch
  2010-07-29 14:56 ` Oren Laadan
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Nathan Lynch @ 2010-07-26 18:37 UTC (permalink / raw)
  To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

user-cr's restart program creates a thread to pipe the checkpoint image
into the sys_restart file descriptor.  This is a thread created with
clone(2) and it shares its address space with the coordinator.

While glibc has internal mechanisms to ensure thread safety, these work
only with threads that were created using glibc/pthread interfaces.
clone(2) bypasses the housekeeping that glibc does to track threads.  It
is not safe to call e.g. malloc or printf from the feeder thread.

The behavior I've been seeing is that restart will occasionally abort,
crash, or sleep indefinitely (with both the coordinator and feeder
threads waiting forever on the same futex) - before restart(2) or
eclone(2) are ever called.

I have tried patching user-cr to create the feeder thread with
pthread_create, but it's not trivial -- I think the program's correct
functioning depends heavily on the threads having separate file
descriptor tables.

The best I can come up with right now is to allocate ckpt_msg's buffer
on the stack - I think this avoids most if not all of the concurrent
malloc activity associated with the crashes/hangs I've been seing.

 common.h |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/common.h b/common.h
index 99b224d..927b146 100644
--- a/common.h
+++ b/common.h
@@ -1,25 +1,21 @@
 #include <stdio.h>
 #include <signal.h>
 
-#define BUFSIZE  (4 * 4096)
+#define BUFSIZE  (4096)
 
 static inline void ckpt_msg(int fd, char *format, ...)
 {
+	char buf[BUFSIZE] = { '\0' };
 	va_list ap;
-	char *bufp;
+
 	if (fd < 0)
 		return;
 
 	va_start(ap, format);
-
-	bufp = malloc(BUFSIZE);
-	if(bufp) {
-		vsnprintf(bufp, BUFSIZE, format, ap);
-		write(fd, bufp, strlen(bufp));
-	}
-	free(bufp);
-
+	vsnprintf(buf, BUFSIZE, format, ap);
 	va_end(ap);
+
+	write(fd, buf, strlen(buf));
 }
 
 #define ckpt_perror(s) 							\

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

end of thread, other threads:[~2010-08-04 23:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-26 18:37 user-cr thread safety Nathan Lynch
2010-07-29 14:56 ` Oren Laadan
     [not found]   ` <4C51968D.3000301-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-07-29 17:37     ` Nathan Lynch
2010-07-29 22:14       ` Oren Laadan
2010-07-30 17:08 ` [PATCH 1/4] restart: check for overflow when counting (nested) vpids Oren Laadan
2010-07-30 17:08 ` [PATCH 2/4] restart thread safety: remove malloc from ckpt_fork_child Oren Laadan
2010-07-30 17:08 ` [PATCH 3/4] restart thread safety: remove malloc from genstack Oren Laadan
     [not found]   ` <1280509713-6745-3-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-07-30 18:46     ` Matt Helsley
     [not found]       ` <20100730184641.GB3426-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-07-30 18:57         ` Oren Laadan
2010-08-04 23:08     ` Nathan Lynch
2010-07-30 17:08 ` [PATCH 4/4] restart thread-safety: avoid malloc in ckpt_msg() Oren Laadan
     [not found]   ` <1280509713-6745-4-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-08-04 23:30     ` Nathan Lynch
2010-08-04 23:56       ` Oren Laadan

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.