linux/Documentation/cgroups/resource_counter.txt
<<
>>
Prefs
   1
   2                The Resource Counter
   3
   4The resource counter, declared at include/linux/res_counter.h,
   5is supposed to facilitate the resource management by controllers
   6by providing common stuff for accounting.
   7
   8This "stuff" includes the res_counter structure and routines
   9to work with it.
  10
  11
  12
  131. Crucial parts of the res_counter structure
  14
  15 a. unsigned long long usage
  16
  17        The usage value shows the amount of a resource that is consumed
  18        by a group at a given time. The units of measurement should be
  19        determined by the controller that uses this counter. E.g. it can
  20        be bytes, items or any other unit the controller operates on.
  21
  22 b. unsigned long long max_usage
  23
  24        The maximal value of the usage over time.
  25
  26        This value is useful when gathering statistical information about
  27        the particular group, as it shows the actual resource requirements
  28        for a particular group, not just some usage snapshot.
  29
  30 c. unsigned long long limit
  31
  32        The maximal allowed amount of resource to consume by the group. In
  33        case the group requests for more resources, so that the usage value
  34        would exceed the limit, the resource allocation is rejected (see
  35        the next section).
  36
  37 d. unsigned long long failcnt
  38
  39        The failcnt stands for "failures counter". This is the number of
  40        resource allocation attempts that failed.
  41
  42 c. spinlock_t lock
  43
  44        Protects changes of the above values.
  45
  46
  47
  482. Basic accounting routines
  49
  50 a. void res_counter_init(struct res_counter *rc,
  51                                struct res_counter *rc_parent)
  52
  53        Initializes the resource counter. As usual, should be the first
  54        routine called for a new counter.
  55
  56        The struct res_counter *parent can be used to define a hierarchical
  57        child -> parent relationship directly in the res_counter structure,
  58        NULL can be used to define no relationship.
  59
  60 c. int res_counter_charge(struct res_counter *rc, unsigned long val,
  61                                struct res_counter **limit_fail_at)
  62
  63        When a resource is about to be allocated it has to be accounted
  64        with the appropriate resource counter (controller should determine
  65        which one to use on its own). This operation is called "charging".
  66
  63        Whi}ied .merctlmport st    whics operati-    resource allocat/a>
     d fot;chargi- i}is o infallee fi, babout
       * is of the allocation s o infallee fi, es thmay crepriaang.
          attohiey    resourge o-he usame by ter tate resource countiines
         er_chad;nes
       * is of tot;chargion s o infallee fi, esen as it should uner_chadnes
         atierrd fpa wi(is of tch oon is calion).

     Is of tot;chargiit_fsure ane a hierarchiuldpendency exists, ese/a>
      **limit_failgt; " nountii sebout    the particulct res_counteluirem/a>
       ere of tot;chargiit_failed.

 c. int res_counter_cha__t ladnes
                     rge(struct res_counter *rc, unsigned long v boolled ce_at)

        Ts" nup, nt res_counter_char), bab as mt jued .ac requupsle  case /a>
     nt res_counld -&_t l c. erns cyi(is mt jubtine call   wint res_counld -&_t l/a>
     held)ime. Ted cegt; " nountindicperat  ey othweULL cayp cleed the liled.

 a. void res_countuner_cha[__t lad]/a>
                     rge(struct res_counter *rc, unsigned long _at)

        When a resource psle  cd (freali as it should de-be accounted
     fromzes the resource coun as wp, be accounout.     Whi}ine calted
     ing&quuner_charging".

        T__t lading routitlmply so that tnt res_counld -&_t l cleeakes on.

 a. void res_countuner_cha_ccouical
             rge(struct res_counter *rge(struct res_countetopval,
              c, ungigned long _at)

     Almo jus" nup, nt re_countuner_cha() bab  appaglocatiof uner_chait.
     stopsful whrc ==outpot;. This is useful whkillhen a rce_tnuntinit.
        chion/cgr it.


 T ere are or morg routitso thmay help youl   wing commneals,thekait.
 checkunti  ey othed the lirce psached d fps/etountit  The max_usage
 ve vaime. y are e cer, declarin at include/linux/res_counte it.


  10
  12
  13 Is of the failcis valto ct stly n/cws, es thmeans so that tce_coun'i/a>
 he lirce too tx/rig Eiy othed the gro thmisbehavuntire ato conse too/a>
 mor are resourceornit the figuoperation ed .suitabl Ted hed the gr/a>
 re aed the lirit should at re  cd it.

  18
  19 seboud the li has he maximal vasure aeiy othloadnit the cainunt   w/a>
 li hng commrm avity it.
  33 ce requ> Iirce bettotheo  allrit  The lira blirleavuntior more resou/a>
  44
     Filene" n/a>
     he lirrrrrrrrrrr **limin_&lquunit_of_of measuremd -&/a>

  66



 D, decl a taskhn/cgro(eake a ax_l  thnn/cgro.subsystem ed hedis).re /a>
 foldhen a rce_coun anne liage

     ge(strumy_n/cgro{/a>
     /a>     ge(stru a rce_coun  a &/a>

             &lquny othfieldsd -&/a>



     c. ihe al_st seding(..._at)
     {/a>
             cf (rt res_counter_charrt res_countptr,the amo) &lqu 0_at)
     /a>     /a>     ps"retu-ENOMEM&/a>

             &lqube allocrt, the resource ane"retuot    tne card -&/a>
     }/a>
     a. voidle  c_st seding(..._at)
     {/a>
             id res_countuner_charrt res_countptr,the amo)&/a>

             &lqupsle  case the resoud -&/a>
     }/a>

 Ineordotheo keephat the usage va self-to ciscontv bo wit  /a>
 ing&qurt res_countptruff&quore aed tuff&quhe amouff"oidle  c_st seding()ent should be
 t  Ts" nup, t. y were ly in the al_st seding()ful whse thele  herage

 stillhLL chelp rk withion).




   Toriginal LXR softwecl me by tt)
LXR cg cunity 65<, es thexperiocumel.merscatime t)
lxn@de/li.no 65<.
   


lxn.de/li.no kindly hxstmined t)
Redpell Le/pro AS 65<, py pro mber Le/uxato coltuntire acs operati servicasu heour1995.
   
/bodydi>/htmldi