nice,interactive programs

utzoo!decvax!ucbvax!menlo70!sri-unix!dove at mit-dspg utzoo!decvax!ucbvax!menlo70!sri-unix!dove at mit-dspg
Mon Jan 18 20:59:49 AEST 1982


The problem with nicing a process such as an editor without modifying the
code is that all spawned procs end up niced.  I have not found the editing
of the source to -nice at startup and +nice on execs to be a problem.  The
difficulty is that the proc must be setuid(root) to -nice.  I plan to fix
that by changing the kernel so setgid(0) procs can -nice since virtually
all my current setuid(root) jobs are that way solely to allow -nice.

We run on an 11/45 and have always had space contention problems.  I tried
playing with the sched to help interactive jobs in the following ways:

	Make any in core job sleeping on TTOPRI and with p_cpu>0 seem to
	be running.  This helped in our original v7 system since editors
	could then stay in long enough to put out a whole screen.
	However, it hurts because after the screen is done, the jobs is still
	hard to swap for several seconds.  A much better idea is to make a
	good sized clist and increase the tty high water mark to ~1000
	chars for fast terminals.  This allows editors to zap out the whole
	screen and get immediately swapped to allow others the use of the
	machine.  This has proven to be very effective by our 2.8bsd system
	(who's tty driver has variable high water marks by tty speed)
	and allows much more efficient use of the machine by other programs.
	Unfortunately, people who type ^S will tie up big chunks
	of the clist.  Probably the top level of the tty driver should stop
	packing the clist at a lower water mark if the tty is stopped.

	Make any swapped job runnable and at TTYPRI privileged to swap in.
	This bombs out because the editors swap in and out every char.

	Add AUTONICE to the kernel.  Our implementation goes like this:
	First, only jobs with the sticky text bit off and nice>=NZERO
	are affected (thus jobs can selectively disable AUTONICE).
	After a job has used 10 sec of cpu time, whenever it is found
	running by the clock with p_cpu>100 gets nice++.
	Any jobs found at lbolt time with nice>NZERO and p_cpu==0 gets
	nice--.  At exec time, the new job gets a clean slate (i.e. nice=0)
	Admittedly, this doesn't allow specifically clobbering jobs
	(like games), but it works much better than any other scheme I have
	tried, such as asking people to nice "bad" jobs.
		This scheme gives short jobs immunity to nice, but quickly
	pushes # crunchers up to nice 39 where they can compete with each
	other.  The 10 sec limit seems to allow most c compile passes to
	complete and other short progs.  Then one need only set sticky
	text or nice<NZERO jobs like editors or shells which accumulate
	large amounts of time, but only work in bursts (and should be
	privileged anyway since they are system interactive jobs).
		With this code, we can run 4-5 number crunchers on a machine
	with only 120kb of user memory and still get fair performance out
	of other jobs like ls pwd login.

	Finally, I nice<NZERO jobs like editors and real time process display
	programs (dpy) so they can swap in quick and generally perform
	well when competing with stuff like du quot cc f77 etc.  I also
	changed some of the factors that p_nice contributed to the swapping
	algorithm in determining ages (< is old > is new):
	
<	 		outage = rp->p_time - (rp->p_nice-NZERO)*8;
---
> 			outage = rp->p_time - (rp->p_nice-NZERO);
	This lessens the impact of nice on out jobs so they can eventually
	get back in.

<			inage = rp->p_time+rp->p_nice-NZERO;
---
>			inage = rp->p_time;
	Once you swap someone in, they have the machine irrespective of their
	nice.  This prevents thrashing of running nice jobs.
	
< 	if (maxsize>=0 || (outage>=3 && inage>=2)) {
---
> 	if (maxsize>=0 || (outage>=1 && inage>=1) )
> 	{
	This last change slightly speeds up swapping, since on the average
	one gets .5 sec in .5 sec out instead of 1.5 sec in and 2.5 sec out.
	(This only applies to swapping out running jobs.)
	
As I have said, we can now get 4-6 people on our machine and still get
work done, which certainly wouldn't have been true without the changes
(given only 120kb that is).  However, we are buying an enable 34 and
will try to adapt our 2.8bsd to it, since even with all this, we spend
an enormous amount of time swapping, and when the system gets really
busy, editors still lag substantially behind the typist.

One last note, and this can't be overemphasized: jobs which do extensive
amounts of tty output (editors, plot, ps, ls and user progs) can EAT UP the
machine if their output is not buffered!  It causes enormous numbers of
system calls, tons of swtch()'s etc.  We have a process display prog (dpy)
which refreshes and shows approximate system and user% time, I fix all such
system programs and tenaciously beat on any users writing such programs
to fix them.



More information about the Comp.unix.wizards mailing list