2                The Resource Counter
   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.
   8This "stuff" includes the res_counter structure and routines
   9to work with it.
  131. Crucial parts of the res_counter structure
  15 a. unsigned long long usage
  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.
  22 b. unsigned long long max_usage
  24        The maximal value of the usage over time.
  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.
  30 c. unsigned long long limit
  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).
  37 d. unsigned long long failcnt
  39        The failcnt stands for "failures counter". This is the number of
  40        resource allocation attempts that failed.
  42 c. spinlock_t lock
  44        Protects changes of the above values.
  482. Basic accounting routines
  50 a. void res_counter_init(struct res_counter *rc,
  51                                struct res_counter *rc_parent)
  53        Initializes the resource counter. As usual, should be the first
  54        routine called for a new counter.
  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.
  60 c. int res_counter_charge(struct res_counter *rc, unsigned long val,
  61                                struct res_counter **limit_fail_at)
  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".
  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
       * 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

        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.

  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.

  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>
     Filene" n/a>
     he lirrrrrrrrrrr **limin_&lquunit_of_of measuremd -&/a>


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

     /a>     ge(stru a rce_coun  a &/a>

             &lquny othfieldsd -&/a>

     c. ihe al_st seding(..._at)
             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. voidle  c_st seding(..._at)
             id res_countuner_charrt res_countptr,the amo)&/a>

             &lqupsle  case the resoud -&/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/ 65<. kindly hxstmined t)
Redpell Le/pro AS 65<, py pro mber Le/uxato coltuntire acs operati servicasu heour1995.