linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve Dickson <steved@redhat.com>
To: Linux NFS Mailing list <linux-nfs@vger.kernel.org>
Cc: Systemd Mailing List <systemd-devel@lists.freedesktop.org>
Subject: [PATCH] gssd: Improve scalability by not waiting for child processes
Date: Wed, 23 Sep 2015 17:20:50 -0400	[thread overview]
Message-ID: <1443043250-25703-1-git-send-email-steved@redhat.com> (raw)

Instead of waiting on every fork, which would
become a bottle neck during a mount storm, simply
set a SIGCHLD signal handler to do the wait on
the child process

Signed-off-by: Steve Dickson <steved@redhat.com>
---
 utils/gssd/gssd.c      | 18 ++++++++++++++++++
 utils/gssd/gssd_proc.c | 11 ++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/utils/gssd/gssd.c b/utils/gssd/gssd.c
index e480349..8b778cb 100644
--- a/utils/gssd/gssd.c
+++ b/utils/gssd/gssd.c
@@ -44,11 +44,13 @@
 #define _GNU_SOURCE
 #endif
 
+#include <sys/types.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/inotify.h>
+#include <sys/wait.h>
 #include <rpc/rpc.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -736,6 +738,21 @@ sig_die(int signal)
 	printerr(1, "exiting on signal %d\n", signal);
 	exit(0);
 }
+static void
+sig_child(int signal)
+{
+	int err;
+	pid_t pid;
+
+	/* Parent: just wait on child to exit and return */
+	do {
+		pid = wait(&err);
+	} while(pid == -1 && errno != -ECHILD);
+
+	if (WIFSIGNALED(err))
+		printerr(0, "WARNING: forked child was killed"
+			 "with signal %d\n", WTERMSIG(err));
+}
 
 static void
 usage(char *progname)
@@ -902,6 +919,7 @@ main(int argc, char *argv[])
 
 	signal(SIGINT, sig_die);
 	signal(SIGTERM, sig_die);
+	signal(SIGCHLD, sig_child);
 	signal_set(&sighup_ev, SIGHUP, gssd_scan_cb, NULL);
 	signal_add(&sighup_ev, NULL);
 	event_set(&inotify_ev, inotify_fd, EV_READ | EV_PERSIST, gssd_inotify_cb, NULL);
diff --git a/utils/gssd/gssd_proc.c b/utils/gssd/gssd_proc.c
index 11168b2..8f5ca03 100644
--- a/utils/gssd/gssd_proc.c
+++ b/utils/gssd/gssd_proc.c
@@ -656,16 +656,9 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
 			/* fork() failed! */
 			printerr(0, "WARNING: unable to fork() to handle"
 				"upcall: %s\n", strerror(errno));
-			return;
+			/* FALLTHROUGH */
 		default:
-			/* Parent: just wait on child to exit and return */
-			do {
-				pid = wait(&err);
-			} while(pid == -1 && errno != -ECHILD);
-
-			if (WIFSIGNALED(err))
-				printerr(0, "WARNING: forked child was killed"
-					 "with signal %d\n", WTERMSIG(err));
+			/* Parent: Return and wait for the SIGCHLD */
 			return;
 		}
 no_fork:
-- 
2.4.3


             reply	other threads:[~2015-09-23 21:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-23 21:20 Steve Dickson [this message]
2015-09-25 10:53 ` [PATCH] gssd: Improve scalability by not waiting for child processes Jeff Layton
2015-09-26 13:55   ` Steve Dickson
2015-09-26 13:59     ` Jeff Layton
2015-09-25 11:13 ` Jeff Layton
2015-10-04  8:19 ` [systemd-devel] " Florian Weimer
2015-10-05 11:50   ` Steve Dickson

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=1443043250-25703-1-git-send-email-steved@redhat.com \
    --to=steved@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=systemd-devel@lists.freedesktop.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).