Introduction
-------------

Numtasks is a resource controller under the CKRM framework that allows the 
user/sysadmin to manage the number of tasks a class can create. It also allows
one to limit the fork rate across the system.

As with any other resource under the CKRM framework, numtasks also assigns
all the resources to the detault class(/rcfs/taskclass). Since , the number
of tasks in a system is not limited, this resource controller provides a
way to set the total number of tasks available in the system through the config
file. By default this value is 128k(131072). In other words, if not changed,
the total number of tasks allowed in a system is 131072.

The config variable that affect this is sys_total_tasks.

This resource controller also allows the sysadmin to limit the number of forks
that are allowed in the system within the specified number of seconds. This
can be acheived by changing the attributes forkrate and forkrate_interval in 
the config file. Through this feature one can protect the system from being
attacked by fork bomb type applications.

Installation
-------------

1. Configure "Number of Tasks Resource Manager" under CKRM (see
      Documentation/ckrm/installation). This can be configured as a module
      also. But, when inserted as a module it cannot be removed.

2. Reboot the system with the new kernel. Insert the module, if compiled
      as a module.

3. Verify that the memory controller is present by reading the file
   /rcfs/taskclass/config (should show a line with res=numtasks)

Usage
-----

For brevity, unless otherwise specified all the following commands are
executed in the default class (/rcfs/taskclass).

As explained above the config file shows sys_total_tasks and forkrate
info.

   # cd /rcfs/taskclass
   # cat config
   res=numtasks,sys_total_tasks=131072,forkrate=1000000,forkrate_interval=3600

By default, the sys_total_tasks is set to 131072(128k), and forkrate is set
to 1 million and forkrate_interval is set to 3600 seconds. Which means the
total number of tasks in a system is limited to 131072 and the forks are 
limited to 1 million per hour.

sysadmin can change these values by just writing the attribute/value pair
to the config file.

   # echo res=numtasks,forkrate=100,forkrate_interval=10 > config
   # cat config
   res=numtasks,sys_total_tasks=1000,forkrate=100,forkrate_interval=10

   # echo res=numtasks,forkrate=100,forkrate_interval=10 > config
   # cat config
   res=numtasks,sys_total_tasks=1000,forkrate=100,forkrate_interval=10

By making total_guarantee and max_limit to be same as sys_total_tasks, 
sysadmin can make the numbers in shares file be same as the number of tasks
for a class.

   # echo res=numtasks,total_guarantee=131072,max_limit=131072 > shares
   # cat shares
   res=numtasks,guarantee=-2,limit=-2,total_guarantee=131072,max_limit=131072


Class creation 
--------------

   # mkdir c1

Its initial share is don't care. The parent's share values will be unchanged.

Setting a new class share
-------------------------

'guarantee' specifies the number of tasks this class is entitled to get
'limit' is the maximum number of tasks this class can get.

Following command will set the guarantee of class c1 to be 25000 and the limit 
to be 50000

   # echo 'res=numtasks,guarantee=25000,limit=50000' > c1/shares
   # cat c1/shares	
   res=numtasks,guarantee=25000,limit=50000,total_guarantee=100,max_limit=100

Limiting forks in a time period
-------------------------------
By default, this resource controller allows forking of 1 million tasks in
an hour.

Folowing command would change it to allow only 100 forks per 10 seconds

   # echo res=numtasks,forkrate=100,forkrate_interval=10 > config
   # cat config
   res=numtasks,sys_total_tasks=1000,forkrate=100,forkrate_interval=10

Note that the same set of values is used across the system. In other words,
each individual class will be allowed 'forkrate' forks in 'forkrate_interval'
seconds.

Monitoring
----------

stats file shows statistics of the number of tasks usage of a class
[root@localhost taskclass]# cat stats
Number of tasks resource:
Total Over limit failures: 0
Total Over guarantee sucesses: 0
Total Over guarantee failures: 0
Maximum Over limit failures: 0
Maximum Over guarantee sucesses: 0
Maximum Over guarantee failures: 0
cur_alloc 38; borrowed 0; cnt_guar 131072; cnt_limit 131072 cnt_unused 131072, unused_guarantee 100, cur_max_limit 0

