linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: George Beshers <gbeshers@sgi.com>
To: linux-hotplug@vger.kernel.org
Subject: PATCH udev-106 /proc/stat buffer to small
Date: Mon, 05 Mar 2007 20:34:44 +0000	[thread overview]
Message-ID: <45EC7EE4.5000903@sgi.com> (raw)

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


I am assuming that this is the correct place to post udev patches for
consideration, feel free to inform me otherwise :-).

George


[-- Attachment #2: udev.patch --]
[-- Type: text/x-patch, Size: 2018 bytes --]

This came up on a system with 1024cores (well 768cpus and 256
hyper-threads) where the buffer size for reading /proc/stat was
not large enough causing udev to fail during the boot process.
The read_proc_stat(void) eliminates this problem.

routine makes sure that the 

--- udev-105/udevd.c	2007-02-02 19:24:48.000000000 -0500
+++ udev-105.new/udevd.c	2007-02-19 13:47:54.000000000 -0500
@@ -357,25 +357,58 @@
 	return memsize / 1024;
 }
 
-static int cpu_count(void)
+/*
+ * Use the same buffer for cpu_count() and running_processes()
+ */
+
+static char* stat_buf = NULL;
+static int   stat_buf_size = 4096;
+
+static int read_proc_stat(void)
 {
 	int f;
-	char buf[32768];
 	int len;
-	const char *pos;
-	int count = 0;
 
-	f = open("/proc/stat", O_RDONLY);
-	if (f == -1)
-		return -1;
+	if (stat_buf == NULL) {
+		stat_buf = malloc(stat_buf_size);
+		if (stat_buf == NULL)
+			return -1;
+	}
 
-	len = read(f, buf, sizeof(buf)-1);
+	do {
+		f = open("/proc/stat", O_RDONLY);
+		if (f == -1)
+			return -1;
+
+		len = read(f, stat_buf, stat_buf_size-1);
+		if (len < stat_buf_size-1)
+			break;
+
+		stat_buf_size *= 2;
+		stat_buf = realloc(stat_buf, stat_buf_size);
+		if (stat_buf == NULL)
+			return -1;
+	} while (1);
 	close(f);
+
 	if (len <= 0)
 		return -1;
-	buf[len] = '\0';
+	stat_buf[len] = '\0';
+	return len;
+}
+
 
-	pos = strstr(buf, "cpu");
+static int cpu_count(void)
+{
+	int len;
+	const char *pos;
+	int count = 0;
+
+	len = read_proc_stat();
+	if (len <= 0)
+		return -1;
+
+	pos = strstr(stat_buf, "cpu");
 	if (pos == NULL)
 		return -1;
 
@@ -392,23 +425,15 @@
 
 static int running_processes(void)
 {
-	int f;
-	char buf[32768];
 	int len;
 	int running;
 	const char *pos;
 
-	f = open("/proc/stat", O_RDONLY);
-	if (f == -1)
-		return -1;
-
-	len = read(f, buf, sizeof(buf)-1);
-	close(f);
+	len = read_proc_stat();
 	if (len <= 0)
 		return -1;
-	buf[len] = '\0';
 
-	pos = strstr(buf, "procs_running ");
+	pos = strstr(stat_buf, "procs_running ");
 	if (pos == NULL)
 		return -1;
 

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

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

             reply	other threads:[~2007-03-05 20:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-05 20:34 George Beshers [this message]
2007-03-05 20:42 ` PATCH udev-106 /proc/stat buffer to small George Beshers
2007-03-06  9:26 ` Kay Sievers
2007-03-06 15:15 ` George Beshers
2007-03-06 15:30 ` Kay Sievers

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=45EC7EE4.5000903@sgi.com \
    --to=gbeshers@sgi.com \
    --cc=linux-hotplug@vger.kernel.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).