From b4601988635d2745b55c7bc09ebae673cadc2c30 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Sat, 18 Feb 2012 19:34:57 +0000 Subject: [PATCH] Reduce memory usage of xCAT by about 66% git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@11616 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/sbin/xcatd | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index 817f8cc52..510686c37 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -569,6 +569,7 @@ sleep 0.05; sub scan_plugins { + my $serialdest = shift; my @plugins=glob($plugins_dir."/*.pm"); foreach (@plugins) { /.*\/([^\/]*).pm$/; @@ -606,8 +607,36 @@ sub scan_plugins { } ${"xCAT_plugin::".$modname."::"}{init_plugin}->(\&do_request); } + if ($serialdest) { print $serialdest freeze(\%cmd_handlers); }; } -scan_plugins; + +my $pid_init; +my $readpipe; +my $writepipe; +if (socketpair($readpipe, $writepipe,AF_UNIX,SOCK_STREAM,PF_UNSPEC)) { + $pid_init = xCAT::Utils->xfork; +} else { + xCAT::MsgUtils->message("S", "socketpair failed: $!"); +} +if (defined $pid_init) { + if ($pid_init) { #parent, just sit and wait.. + close($writepipe); + my $serialized_handlers; + while ($serialized_handlers !~ /xCATINITDoneWithHandlersNow/) { + $serialized_handlers.=<$readpipe>; + } + %cmd_handlers=%{thaw($serialized_handlers)}; + } else { + scan_plugins($writepipe); + print $writepipe "\nxCATINITDoneWithHandlersNow\n"; + exit(0); + } +} else { + print "Unable to branch the initialization portion, will use more memory\n"; + scan_plugins(); +} + + unless (xCAT::Utils->isLinux()) { # messes up the output of the service cmd on linux eval { xCAT::MsgUtils->message("S","xCATd: service starting");