From: corey@milton.u.washington.edu (Corey Satten)
Subject: Ultrix Load Spikes caused by select(2)
Date: 30 Sep 91 23:56:51 GMT [thread overview]
Message-ID: <1991Sep30.235651.28089@milton.u.washington.edu> (raw)
: ----- cut here ----- cut here ----- cut here ----- cut here -----
: This is a "shell archive". Save everything after the cut mark
: in a file called thisstuff, then feed it to sh by typing sh thisstuff.
: SHAR archive format. Archive created Thu Sep 26 13:12:34 PDT 1991
echo x - READ_ME
echo '-rw-r--r-- 1 corey 5534 Sep 24 13:27 READ_ME (as sent)'
sed 's/^-//' >READ_ME <<'+FUNKY+STUFF+'
-
- Load Spikes on Ultrix
- traced to
- Bogus Select Collisions
-
- Corey Satten, corey@cac.washington.edu
- Networks and Distributed Computing
- University of Washington
- Seattle, Washington
- 9/24/91
-
-If you have been experiencing load spikes on your Ultrix system, the
-following may be of considerable interest to you.
-
-Background
-
- The implementation of the select(2) system call found in versions of
- BSD up though 4.3 Tahoe (not to imply anything about later versions)
- has a simple but expensive way of handling "select collisions". True
- "collisions" occur very rarely and refer to a situation in which two
- or more processes are blocked in select on a single device or network
- connection. Since the data structures used to wake up processes when
- they have input contain space for only a single process id, when two
- or more processes must be awakened, all processes blocked in select
- for any reason are slightly awakened and most quickly roll over and
- go back to sleep. If any of these processes are swapped out, some
- small part of them is swapped back in before they go back to sleep.
-
- All X clients, when idle, are blocked in select, so if you have
- a lot of X clients and you experience a select collision, a large
- number of processes can be affected. If these programs happen to run
- at the very moment the load average measurements are done, a very
- large load spike can result.
-
- A short program, spike.c, (enclosed) will generate a true select
- collisions for each newline typed.
-
-Ultrix Bugs
-
- RISC Ultrix version 4.1 and 4.2 (not to imply anything about other
- versions) generates select collisions in circumstances which do
- not appear to be proper. I call these "bogus select collisions".
- On our system the collisions are quite common (often several per
- minute) and affect roughly 300 processes out of 550 on our system.
-
- Two short programs: spike2.c and spike3.c (enclosed) will generate
- bogus select collisions only on our Ultrix systems.
-
- It is unclear whether select collisions are mostly a measurement
- anomaly or a real performance problem. Clearly there is some
- unnecessary disk I/O associated with them and some CPU time is wasted
- but they are over almost as soon as they start so it's hard to tell
- how much of a problem they really are. They certainly make the load
- average a useless number on our system since it spikes from a baseline
- of around one up to as much as 40 and then exponentially decays back
- down (often only part way before the next spike).
-
-Detecting the problem
-
- There are several ways to look for select collisions on Ultrix. The
- most direct is to examine the kernel variable which counts them. It
- is called "nselcoll" and can be viewed with my kmem program (previously
- posted and included below for completeness) or with dbx:
-
- kmem nselcoll
- echo print nselcoll | dbx -k /vmunix
-
- You can also see the effect of the select collisions by running:
-
- vmstat -v 5
-
- and watching the number of "sleepers" (sl: the number of processes
- which have not run within the last 20 seconds). When a select collision
- happens, the number will jump to include all the processes blocked in
- select:
-
- % vmstat -v 5
- procs memory
- r dw pw sl w vm avm rm arm fre
- 1 0 0 86 0 203k 69k 93k 37k 4564
- 0 0 0 80 0 202k 62k 92k 35k 4612
- 1 0 0 80 0 202k 62k 92k 32k 4740
- 1 0 0294 0 202k 153k 92k 78k 4516
- 0 0 0288 0 202k 153k 92k 77k 4404
- 0 0 0287 0 202k 151k 92k 76k 4364
- 1 0 0286 0 202k 151k 92k 76k 4344
- 0 0 0 65 0 202k 53k 92k 28k 4344
- 3 0 0 66 0 202k 58k 92k 31k 4344
-
- The more "sleepers" were swapped out, the longer it takes the system
- to wake them and then put them back to sleep so the greater the chance
- of having the collision show up as a spike in the load average.
-
-Programs which generate "bogus select collisions"
-
- X clients which use XtAddInput (to incorporate a pipe into the list
- of file descriptors watched in the X event loop) or in some other way
- cause the X event loop to select on a pipe seem to be the largest
- source of bogus select collisions. Xmh is probably a widely available
- example of this but the work I've done has been on home-grown clients
- so there is a chance xmh is doing something different.
-
- Without getting into any custom software, you can generate collisions
- on the console by starting and ending a dxterm from the session
- manager (dxsession).
-
- As an aid to tracking down this problem, I hacked our kernel to save
- the PID of the process which generates the collision. As a result,
- I have a list of processes which have "collided", (though I don't have
- what they collided with). I find the *vast* majority are caused by
- IslandLIC (3rd party software) and xmh (the X version of the mh mail
- agent) however the following other programs have also shown up:
-
- Xprompter dxcardfiler
- emacs rlogin
- rlogind rsh
- rshd sh
- telnet telnetd
- xterm
-
-Closing remarks
-
- I haven't tried to fix the kernel and I'm not sure I will. I'm curious
- what feedback I'll get from posting what I've discovered so far.
- I assume it's too much to hope that someone has already found and fixed
- this but asking is cheap...
-
-This posting contains the following files:
-
- READ_ME
- spike.c
- spike2.c
- spike3.c
- kmem.c
+FUNKY+STUFF+
chmod u=rw,g=r,o=r READ_ME
ls -l READ_ME
echo x - spike.c
echo '-rw-r--r-- 1 corey 2161 Sep 26 12:51 spike.c (as sent)'
sed 's/^-//' >spike.c <<'+FUNKY+STUFF+'
-/*
- * This program demonstrates a quirk in the implementation of
- * select on 4.3BSD, Ultrix 4.1, SUNOS 4.1.1 (and maybe others).
- *
- * Looking at the kernel source for the routine "selwakeup", I find
- * that if there is more than one process using select to wait for
- * I/O on the same device; when I/O is ready, *ALL* processes on the
- * system sleeping on "selwait" (waiting for any select) are awakened.
- * Since most have no input they don't seem to run much (judging from
- * how many can "run" like this per second and have no significant
- * impact on idle CPU). If, however, any were swapped out, they swap
- * in (or maybe only a tiny part swaps in since so little disk
- * traffic results from the swapping) and this stretches the real-time
- * over which the number of processes "runable" is high and increases
- * the chances that a system load average spike will result. I believe
- * the load spike is mostly a measurement anomaly however the active
- * real memory does goes up a little. Another indication of these
- * processes running is that the "SL" field of a "ps avx" shows all
- * of these processes have recently run. On ultrix, the "vmstat -v 5"
- * command will show the number of "sl" (short term sleepers) has also
- * jumped accordingly.
- *
- * To see which processes are waiting in select, do a "ps axl" and look
- * at the WCHAN field. If it is numeric, do a "nm /vmunix|grep selwait"
- * and look for the least significant part of that number in the WCHAN
- * field; otherwise, look for the word "selwait" directly in the ps list.
- * All the processes in selwait will be affected -- on our system, of
- * the roughly 550 processes, there are about 300 in selwait.
- *
- * To generate a spike, run this program and type return for each spike
- *
- * Corey Satten, corey@cac.washington.edu 5/24/91
- */
-#include <stdio.h>
-#include <fcntl.h>
-main(){
- int i;
- char buf[100];
- if (fcntl(0,F_SETFL,O_NDELAY) < 0) {
- fprintf(stderr, "fcntl failed\n");
- exit(1);
- }
- fork(); /* both parent and child select on stdin */
- for (;;) {
- i=1;
- printf ("select in pid %d returned %d\n", getpid(), select(1,&i,0,0,0));
- read(0,buf,100);
- }
- }
+FUNKY+STUFF+
chmod u=rw,g=r,o=r spike.c
ls -l spike.c
echo x - spike2.c
echo '-rw-r--r-- 1 corey 779 Sep 26 13:09 spike2.c (as sent)'
sed 's/^-//' >spike2.c <<'+FUNKY+STUFF+'
-/*
- * generate a bogus select collision on Ultrix by selecting for input
- * with timeout on a pipe descriptor.
- */
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#define IN 0
-#define OUT 1
-
-main() {
- int pipedes[2];
- int ret;
- struct timeval tv;
- fd_set readfds, writefds, exceptfds;
- extern int errno;
-
- pipe(pipedes);
- fprintf(stderr, "process ID %d\n", getpid());
- fprintf(stderr, "pipe descriptors %d %d\n", pipedes[IN], pipedes[OUT]);
-
- tv.tv_sec = 1;
- tv.tv_usec = 0;
-
- FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds);
- FD_SET(pipedes[IN], &readfds);
-
- fprintf(stderr, "mask = 0x%x\n", readfds);
- ret = select(pipedes[IN]+1, &readfds, 0, 0, &tv);
- fprintf(stderr, "ret=%d errno=%d\n", ret, errno);
-}
+FUNKY+STUFF+
chmod u=rw,g=r,o=r spike2.c
ls -l spike2.c
echo x - spike3.c
echo '-rw-r--r-- 1 corey 963 Sep 26 13:06 spike3.c (as sent)'
sed 's/^-//' >spike3.c <<'+FUNKY+STUFF+'
-/*
- * generate a bogus select collision on Ultrix by selecting for input on
- * both descriptors of a pipe. This is probably not a sensible thing for a
- * program to do, but it probably shouldn't generate a collision either.
- */
-#include <stdio.h>
-#include <fcntl.h>
-#define IN 0
-#define OUT 1
-main(){
- int i,j;
- int child;
- char buf[100];
- int pipedes[2];
-
- pipe(pipedes);
- fprintf(stderr, "pipe descriptors: %d, %d\n", pipedes[IN], pipedes[OUT]);
-
- if (child=fork()) { /* parent */
-#ifdef NOSPIKE
- i = (1<<(pipedes[IN]));
-#else
- i = (1<<(pipedes[IN])) | (1<<(pipedes[OUT]));
-#endif
- printf ("select in pid %d returned %d\n",
- getpid(),
- select(pipedes[OUT]+1,&i,0,0,0));
- i = read(pipedes[IN], buf, 100);
- write(1,buf,i);
- wait(&i);
- sleep(10);
- exit(0);
- }
- else { /* child */
- close(1); dup(pipedes[OUT]);
- close(0);
- close(2);
- close(pipedes[IN]);
- close(pipedes[OUT]);
- sleep(5);
- execlp("date", "date", 0);
- exit(0);
- }
- }
+FUNKY+STUFF+
chmod u=rw,g=r,o=r spike3.c
ls -l spike3.c
echo x - kmem.c
echo '-rw-r--r-- 1 corey 3925 Apr 25 10:24 kmem.c (as sent)'
sed 's/^-//' >kmem.c <<'+FUNKY+STUFF+'
-/*
- * a tool to use in place of adb (on systems without adb) which lets you
- * peek and poke at the values of kernel variables in /dev/kmem
- *
- * usage: kmem [-s#] var1 var2 ... varN
- * or
- * usage: kmem -w var1=val1 var2=val2 ... varN=valN
- *
- * If -s# is given, loop every # seconds and repeat. This is handy for
- * watching variables like freemem or debugging flags. The following simple
- * awk script can postprocess the output filtering out values which don't
- * change:
- * { if (NF > 2) date = $0
- * else if (seen[$1] != $2) {
- * seen[$1] = $2
- * if (date != "") {
- * print ""; print date
- * date = ""
- * }
- * print
- * }
- * }
- *
- * Corey Satten, corey@cac.washington.edu, 9/6/90 - Ultrix 4.0 version
- */
-#include<stdio.h>
-#include<nlist.h>
-#include<sys/file.h>
-#include <time.h>
-
-struct nlist *nl; /* how we find locations of names */
-int *nv; /* the new values for each name */
-int w_flag = 0; /* write new values? */
-char *file = "/vmunix"; /* default file to read symbols from */
-int kmem;
-
-main(argc, argv)
- int argc;
- char *argv[];
-{
- int f; /* walks argv upto index of first non-flag */
- int i; /* walks through remaining arguments */
- int value = 0;
- int rc = 0;
- int sleeptime = 0; /* if set nonzero with -s#, repeat every # secs */
-
- /*
- * flag parsing
- */
- for (f=1; f<argc && *(argv[f]) == '-'; ++f) {
- switch(argv[f][1]) {
- default:
- fprintf(stderr, "%s: unknown flag -%c\n", argv[0], argv[f][1]);
- exit(1);
- case 'w':
- w_flag = 1;
- break;
- case 's':
- sscanf(argv[f][2] ? argv[f]+2 : argv[++f], "%d", &sleeptime);
- break;
- case 'f':
- file = argv[++f];
- break;
- }
- }
-
- /*
- * handle the remaining arguments as either symname or symname=value
- * depending on whether -w (w_flag) was specified.
- */
-
- nl = (struct nlist *) malloc( sizeof(*nl) * (argc-f+1) );
- nv = (int *) malloc( sizeof(int) * (argc-f+1) );
- if (!nv || !nl) {perror("malloc"); exit(1);};
-
- for (i=0; i<argc-f; ++i) {
- char *name = (char *)malloc(strlen(argv[i+f])+1);
-
- if (!name) {perror("malloc"); exit(1);};
- rc = sscanf(argv[i+f], "%[^=]=%d", name, &value);
- if (rc - w_flag != 1) {
- fprintf(stderr, "%s: bad argument: %s\n", argv[0], argv[i+f]);
- exit(1);
- }
- nl[i].n_name = name;
- nv[i] = value;
- }
- nl[i].n_name = "";
-
- /*
- * now figure out where to read/write in /dev/kmem and do it
- */
-
- nlist(file, nl);
-
- kmem = open("/dev/kmem", w_flag ? O_RDWR : O_RDONLY);
- if (kmem < 0) {
- perror("/dev/kmem open");
- exit(1);
- }
-
- sleeploop:
-
- if (sleeptime) {
- putchar('\n'); date();
- }
-
- for (i=0; i<argc-f; ++i) {
- long seekto = (long)nl[i].n_value;
-
- if (nl[i].n_type == 0) {
- fprintf(stderr, "%s: symbol `%s' not found in namelist of %s\n",
- argv[0], nl[i].n_name, file);
- /*
- * We promise to do all writes in command line order, so if one
- * is going to fail, we'd best bail out rather than continue.
- */
- if (w_flag) exit(2);
- else continue;
- }
- if ( lseek(kmem, seekto, 0) != seekto ) {
- perror("/dev/kmem lseek"); exit(2);
- }
- if ( read(kmem, &value, sizeof(int)) != sizeof(int) ) {
- perror("/dev/kmem read"); exit(2);
- }
-
- printf("%s(0x%x)\t%d", nl[i].n_name, nl[i].n_value, value);
-
- if (w_flag) {
- if ( lseek(kmem, seekto, 0) != seekto ) {
- perror("/dev/kmem lseek"); exit(2);
- }
- value = nv[i];
- printf(" -> %d", value);
- if ( write(kmem, &value, sizeof(int)) != sizeof(int) ) {
- perror("/dev/kmem write"); exit(2);
- }
- }
- putchar('\n');
- }
-
- if (sleeptime) {
- fflush(stdout);
- sleep(sleeptime);
- goto sleeploop;
- }
-}
-/*
- * print ascii version of current date and time
- */
-date() {
- char *at;
- static char db[30];
- int i;
-
- time(&i);
- at = asctime(localtime(&i));
- strcpy(db, at+4);
- db[20] = 0;
- puts(db);
- }
+FUNKY+STUFF+
chmod u=rw,g=r,o=r kmem.c
ls -l kmem.c
exit 0
reply other threads:[~1991-09-30 23:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox