Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Process priorities



On Tuesday, September 17, 2002, at 11:13 , Jonas Maebe wrote:

On dinsdag, september 17, 2002, at 02:51 , James Whitwell wrote:

I've noticed if I run 2 CPU-bound processes (for testing, 2 copies of
seti@home), leave one at the normal priority and nice 20 the other, the
nice'd process still consumes about 40% of CPU (this is with 'ps l' -- 'top'
shows about 20%). I thought that setting nice 20 would mean the process
would run only when nothing else was running -- is that right?

It's right under Linux and probably under most *nix OS'es, but not under Darwin (at least not under 5.x and below, I don't know whether this had been changed in 6.x). Under Darwin, priority 20 simply means "a very low priority" (which is still dynamically adjustable).

I, too, find this a little annoying. nice values just don't seem to have that much affect:

stix-pbg3:bash$ nice -20 perl -e 'while(1){}' &
[1] 4363
stix-pbg3:bash$ perl -e 'while(1){}' &
[2] 4364
stix-pbg3:bash$ ps alx | egrep 'UID|perl'
UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TT TIME COMMAND
20008 4363 542 0 0 20 1284 324 - RN std 0:25.41 perl -e while(1){}
20008 4364 542 0 5 0 1284 328 - R std 0:32.20 perl -e while(1){}
20008 4370 542 0 31 0 1112 196 - R+ std 0:00.01 egrep UID|perl
stix-pbg3:bash$ ps aux | egrep '^USER|perl'
USER PID %CPU %MEM VSZ RSS TT STAT TIME COMMAND
stix 4364 21.6 0.2 1284 328 std R 0:33.38 perl -e while(1){}
stix 4363 18.0 0.2 1284 324 std RN 0:26.33 perl -e while(1){}
stix 4372 0.0 0.0 2204 84 std R+ 0:00.00 egrep ^USER|perl
stix-pbg3:bash$

The nice value is effectively mapped to a mach priority in xnu/bsd/kern/kern_synch.c:
(void)task_importance(p->task, -p->p_nice);

Just for laughs, I modified task_importance() (in xnu/osfmk/kern/task_policy.c) to bind a nice value of 20 to mach IDLEPRI (which is #defined to zero). I'm running a kernel with that mod now, and there is little, if any, difference. Looking at the priority computation code (to elevate priorities for starved processes) in mk_sp.c, I completely lost the motivation to look any further... Mucking with the scheduler is not something to be done lightly, and it's a fairly complex, tuned beast.

Cheers,
--
Paul Ripke
Unix/OpenVMS/DBA
101 reasons why you can't find your Sysadmin:
67: It's 9AM and they're not working that late.
-- Koos van den Hout
_______________________________________________
darwin-userlevel mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-userlevel
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Process priorities (From: Jonas Maebe <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.