Re: SUMMARY: A nice(1) question.

From: Mark Sirota (mark@greenwich.com)
Date: Thu Aug 12 1993 - 13:00:57 CDT


In article <1993Aug11.131404.487@sadtler.com> rick@sadtler.com (Rick Morris) writes:
> In article <1993Aug4.124440.9555@sadtler.com> I wrote:
>> Question: If all other processes are running with a nice
>> value of 0, does it make a difference if the background
>> process runs at a nice value of 4 or 19?

After reading through Rick's summary of responses, it seems that a lot of
people don't know the real answer to this question, so I thought I'd
post the details in an effort to avoid the spread of misinformation.
What I'm saying here is true for SunOS 4.1.x, or (I think) any BSD-based
system.

The nice value of a process is used in a formula for calculating process
priority. The process priority is used by the scheduler to determine when
a process will run. You can see the priority in the output of ps -l.

Nice values, as you know, range from -20 to 19. Priorities range from 0 to
127, 0 being the highest.

The formula is something like
        p_usrpri = (p_cpu / 4) + PUSER + (2 * p_nice);
        if (p_flag | SFAVORED)
                p_userpri -= 20;
        if (p_rss >= maxrss && freemem < desfree)
                p_userpri += 8;

        if (p_userpri < 1)
                p_userpri = 1;
        else if (p_userpri > 127)
                p_userpri = 127;

p_cpu is incremented each tick that the process has executed, so the longer
it has been around, the lower the priority.

PUSER is 50, the base priority for a user process.

p_nice is the nice value. You can see that there's no such thing as
"Processes with a nice of 19 never execute unless nothing else is running."
They simply get a lower priority, but may still get scheduled.

I'm not sure who sets the SFAVORED flag. I know that if a process is
killed with SIGKILL or SIGTERM, and if p_nice is greater than zero, the
nice is reduced to zero. This is different from SFAVORED, as far as I
know.

If a process has hit maximum resident set size and the system is low on
memory, it gets a lower priority.

Then, make sure that the priority is between 1 and 127, and we're off and
running.

Hope that helps clear up the confusion... Note that there may be small
errors. Most of this is from memory.

-- 
Mark Sirota, System and Network Manager
Greenwich Associates, Greenwich Connecticut
mark@greenwich.com, (203) 625-5060



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:06 CDT