Thursday, August 26, 2010

controlling cpu usage part 4: The Fair Share Scheduler

The Fair Share Scheduler (FSS) is an alternative scheduling class. It is not used by default an is explicitly enabled. The FSS guarantees a minimum proportion of the machines CPU resources are made available to each holder of shares, in proportion of the number of shares held.
The absolute quantity of shares is not important. Any number that is in proportion with the desired CPU entitlement can be used.
To configure projects the /etc/project file needs to be modified to identify the number of shares to be granted to each project, and the /etc/user_attr file needs to be modified to assign each user to a project.

To define two users, u1 and u2 with u1 having twice the CPU resources as u2 the entries in /etc/user_attr and /etc/project would be similar to the following:



 # egrep 'u[12]' /etc/passwd
 u1:x:1000:1::/export/home/u1:/bin/sh
 u2:x:1001:1::/export/home/u2:/bin/sh

 # egrep 'u[12]' /etc/user_attr
 u1::::type=normal;project=u1
 u2::::type=normal;project=u2

 # egrep 'u[12]' /etc/project
 u1:1000:User 1:u1::project.cpu-shares=(privileged,20,none)
 u2:1001:User 2:u2::project.cpu-shares=(privileged,10,none)

To determine the project of the current process the ps command may be used, and the prctl command will show the number of shares.



 # ps -o project= -p $$
 user.root

 # su - u1
 $ ps -o project= -p $$
          u1

 $ prctl -t privileged -n project.cpu-shares -i pid $$
 process: 1444: -sh
 NAME      PRIVILEGED         VALUE       FLAG    ACTION          RECIPIENT
 project.cpu-shares
           privileged            20                               None            -         

To change the scheduling class of a running process you can use the priocntl command.


 #  priocntl -s -c FSS -i pid            # Change one process
 #  priocntl -s -c FSS -i class TS       # Change everything currently in TS
 #  priocntl -s -c FSS -i zoneid 1       # Change all processes in zone ID 1
 #  priocntl -s -c FSS -i pid 1          # Change init (special case)

To examine the shares granted to a process (or zone) use the prctl command.

 # prctl -t privileged -n zone.cpu-shares -i zoneid 1     # Shares for zone ID 1

To modify the number of shares granted to a zone we can use -r option to prctl. This change only lasts until next reboot.

 # prctl -r -v 10 -t privileged -n zone.cpu-shares -i zoneid 1  
 # Change number of shares to 10

To change the default scheduling class, so that on next and subsequent reboots all process will use FSS by default we can use the dispadmin command.

 # dispadmin -d FSS


No comments:

Post a Comment