Scheduling Priorities

All processes have assigned to them an execution priority—an integer value that is dynamically computed and updated on the basis of several different factors. Whenever the CPU is free, the scheduler selects the most favored process to resume executing. The process selected is the one with the lowest-priority number because lower numbers are defined as more favored than higher ones. Multiple processes at the same priority level are placed in the run queue for that priority level. Whenever the CPU is free, the scheduler starts the processes at the head of the lowest-numbered non-empty run queue. When the process at the top of a run queue stops executing, it goes to the end of the line and the next process moves up to the front. After a process begins to run, it continues to execute until it needs to wait for an I/O operation to complete, receives an interrupt signal, or exhausts the maximum execution time slice defined on that system. A typical time slice is 10 milliseconds.

A UNIX process has two priority numbers associated with it. One of the priority numbers is its requested execution priority with respect to other processes. This value (its nice number) is set by the process’s owner and by root; it appears in the NI column in a ps -l listing. The other priority assigned to a process is the execution priority. This priority is computed and updated dynamically by the operating system, taking into account such factors as the process’s nice number, how much CPU time it has had recently, and other processes that are running and their priorities. The execution priority value appears in the PRI column on a ps -l listing.

Although the CPU is the most-watched resource on a system, it is not the only one. Memory use, disk use, I/O activity, and the number of processes all tie together in determining the computer’s throughput. For example, suppose you have two groups, A and B. Both groups require large amounts of memory—more than is available when both are running simultaneously. Raising the priority of Group A over Group B might not help if Group B does not fully relinquish the memory it is using. Although the paging system will do this over time, the process of swapping a process out to disk can be intensive and can greatly reduce performance. A better alternative might be to completely stop Group B with a signal and then continue it later, when Group A has finished.

Fair Share Scheduler (FSS) and Fixed Scheduler (FX)

The operating system has to arbitrate which processes obtain access to the system’s resources. The default scheduler in the Solaris operating environment is the Timeshare Scheduler (TS), which tries to give every process relatively equal access to the CPU(s). However, in some situations you might want to specify that certain processes be given more resources than others. The FSS can be used to control the allocation of resources, based on their relative importance; the importance is specified in the /etc/projects file mentioned earlier in the section “Projects and Tasks” by giving each project “shares.” These shares operate in much the same way as shares in a commercial company work—that is, the more you own, the more power you have. The shares in this case, though, relate to how much CPU resource the project is entitled to, in relation to other projects.

Note

Processes in projects with zero shares always run at the lowest system priority (0). These processes will run only when projects with nonzero shares are not using CPU resources.


The FX is a fixed priority scheduler that provide an ensured priority for processes. The priority is not automatically adjusted, so you should not run the FX and TS schedulers on the same system; otherwise, TS-scheduled processes could be starved of resources if the FX priority is set too high.

Note

The FSS should not be mixed with FX or TS processes unless processor sets are used. Scheduling can be mixed on the same system only if each processor set contains processes from just one of the scheduling classes; otherwise, high-priority FX processes will starve applications in the FSS and TS classes.


More information on the FSS and FX schedulers can be found in the “System Administration Guide: Resource Management and Network Services” manual online at http://docs.sun.com and the manual page for FSS.

Changing the Priority of a Time-Sharing Process with nice

The nice command is supported only for backward compatibility with previous Solaris releases.The priocntl command provides more flexibility in managing processes.The priority of a process is determined by the policies of its scheduling class and by its nice number. Each time-sharing process has a global priority that is calculated by adding the user-supplied priority, which can be influenced by the nice or priocntl commands and the system-calculated priority.

The execution priority number of a process is assigned by the operating system and is determined by several factors, including its schedule class, how much CPU time it has used, and its nice number. Each time-sharing process starts with a default nice number, which it inherits from its parent process. The nice number is shown in the NI column of the ps report.

A user can lower the priority of a process by increasing its user-supplied priority number. Only the superuser can increase the priority of a process by lowering its nice value. This prevents users from increasing the priorities of their own processes, thereby monopolizing a greater share of the CPU.

In UNIX, nice numbers range from 0 to +19. The highest priority is 0. Two versions of the command are available: the standard version, /usr/bin/ nice, and a version that is integrated into the C shell as a C shell built-in.

Use the nice command as described in Table 15.14 when submitting a program or command.

Table 15.14. Setting Priorities with nice
Command Description
LOWERING THE PRIORITY OF A PROCESS
nice <command_name> Increases the nice number by four units (the default)
nice +4 <command_name> Increases the nice number by four units
nice +10 <command_name> Increases the nice number by 10 units
INCREASING THE PRIORITY OF A PROCESS
nice -10 <command_name> Raises the priority of the command by lowering the nice number

As a system administrator, you can use the renice command to change the priority of a process after it has been submitted. The renice command has the following form:

renice priority -n <value> -p <pid> 

Use the ps -el command to find the PID of the process for which you want to change the priority. The process that you want to change in the following example is named largejob:

F S  UID   PID  PPID  C PRI  NI     ADDR   SZ   WCHAN TTY  TIME  CMD 
9 S   0   8200  4100  0  84  20  f0274e38  193        ?    0:00 largejob 

Issue the following command to increase the priority of PID 8200:

renice -n -4 -p 8200 

Issuing the ps -el command again shows the process with a higher priority:

F S  UID  PID  PPID  C PRI  NI   ADDR    SZ   WCHAN TTY   TIME   CMD 
9 S   0  8200  4100  0  60  16 f0274e38  193         ?    0:00  largejob

Changing the Scheduling Priority of Processes with priocntl

The standard priority scheme has been improved since earlier versions of Solaris as part of its support for real-time processes. Real-time processes are designed to work in application areas in which nearly immediate response to events is required. These processes are given nearly complete access to all system resources when they are running. Solaris uses time-sharing priority numbers ranging from –20 to 20. Solaris uses the priocntl command, intended as an improvement over the nice command, to modify process priorities. To use priocntl to change a priority on a process, type this:

priocntl -s -p <new-priority>  -i pid <process-id> 

new-priority is the new priority for the process, and process-id is the PID of the process you want to change.

The following example sets the priority level for process 8200 to -5:

priocntl -s -p -5 -i pid 8200 

The following example is used to set the priority (nice value) for every process created by a given parent process:

priocntl -s -p -5 -I ppid 8200 

As a result of this command, all processes forked from process 8200 will have a priority of -5.

The priority value assigned to a process can be displayed using the ps command, which was described earlier in this chapter.

The functionality of the priocntl command goes much further than what I’ve described in this section. Consult the online manual pages for more information about the priocntl command.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset