From: George Beshers <gbeshers@sgi.com>
To: linux-hotplug@vger.kernel.org
Subject: udevd on very large systems: again
Date: Tue, 01 May 2007 23:42:09 +0000 [thread overview]
Message-ID: <4637D051.7060103@sgi.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 388 bytes --]
After some testing the following patch seems safe for dealing with computers
with more than 500 processors. It occurred to me that it might be
easier and
just as useful to note when udev is running on a large computer (e.g., >= 8p
and >= 16Gb of memory) and simply not worry about throttling at that point.
The patch should apply cleanly against udev-110.
Comments welcome.
George
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2344 bytes --]
diff -Naur udev-110.Orig/udevd.c udev-110.new/udevd.c
--- udev-110.Orig/udevd.c 2007-05-01 08:33:39.000000000 -0400
+++ udev-110.new/udevd.c 2007-05-01 12:49:38.000000000 -0400
@@ -347,31 +347,21 @@
static int cpu_count(void)
{
- int f;
- char buf[65536];
+ FILE* f;
+ char buf[1024];
int len;
const char *pos;
int count = 0;
- f = open("/proc/stat", O_RDONLY);
- if (f == -1)
+ f = fopen("/proc/stat", "r");
+ if (f == NULL)
return -1;
- len = read(f, buf, sizeof(buf)-1);
- close(f);
- if (len <= 0)
- return -1;
- buf[len] = '\0';
-
- pos = strstr(buf, "cpu");
- if (pos == NULL)
- return -1;
-
- while (pos != NULL) {
- if (strncmp(pos, "cpu", 3) == 0 &&isdigit(pos[3]))
+ while (fgets(buf, 1024, f) != NULL) {
+ if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3]))
count++;
- pos = strstr(&pos[3], "cpu");
}
+ fclose(f);
if (count == 0)
return -1;
@@ -380,30 +370,46 @@
static int running_processes(void)
{
- int f;
- char buf[32768];
+ FILE* f;
+ char buf[1024];
int len;
- int running;
+ int running = -1;
const char *pos;
+ int retries = 3;
- f = open("/proc/stat", O_RDONLY);
- if (f == -1)
- return -1;
-
- len = read(f, buf, sizeof(buf)-1);
- close(f);
- if (len <= 0)
- return -1;
- buf[len] = '\0';
-
- pos = strstr(buf, "procs_running ");
- if (pos == NULL)
- return -1;
+ /*
+ * The retries is probably overkill but the text display is
+ * changing rapidly.on large systems (>= 512p) and so, while
+ * I have not actually recorded an instance where the retry
+ * was used I would rather not have it fail.
+ *
+ * An alternative approach would be to note when we are on
+ * a fairly large system (8cpus and 16Gbytes say) at which
+ * point throttling is probably not really necessary.
+ */
+ do {
+ f = fopen("/proc/stat", "r");
+ if (f == NULL)
+ return -1;
+
+ while (fgets(buf, 1024, f) != NULL) {
+ pos = strstr(buf, "procs_running ");
+ if (pos != NULL) {
+ int res;
+ res = sscanf(pos, "procs_running %u",
+ &running);
+ if (res == 1) {
+ fclose(f);
+ return running;
+ }
+ break;
+ }
+ }
- if (sscanf(pos, "procs_running %u", &running) != 1)
- return -1;
+ fclose(f);
+ } while (retries-- > 0);
- return running;
+ return -1;
}
/* return the number of process es in our session, count only until limit */
[-- Attachment #3: Type: text/plain, Size: 286 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
[-- 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
next reply other threads:[~2007-05-01 23:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-01 23:42 George Beshers [this message]
2007-05-02 19:37 ` udevd on very large systems: again Kay Sievers
2007-05-02 21:11 ` Kay Sievers
2007-05-02 21:26 ` George Beshers
2007-05-02 21:39 ` George Beshers
2007-05-02 23:42 ` Kay Sievers
2007-05-02 23:51 ` Kay Sievers
2007-05-03 19:49 ` George Beshers
2007-05-03 21:12 ` 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=4637D051.7060103@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).