1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2010 The FreeBSD Foundation 5 * 6 * This software was developed by Edward Tomasz Napierala under sponsorship 7 * from the FreeBSD Foundation. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #include <sys/cdefs.h> 32 #include "opt_sched.h" 33 34 #include <sys/param.h> 35 #include <sys/buf.h> 36 #include <sys/systm.h> 37 #include <sys/eventhandler.h> 38 #include <sys/jail.h> 39 #include <sys/kernel.h> 40 #include <sys/kthread.h> 41 #include <sys/lock.h> 42 #include <sys/loginclass.h> 43 #include <sys/malloc.h> 44 #include <sys/mutex.h> 45 #include <sys/proc.h> 46 #include <sys/racct.h> 47 #include <sys/resourcevar.h> 48 #include <sys/sbuf.h> 49 #include <sys/sched.h> 50 #include <sys/sdt.h> 51 #include <sys/smp.h> 52 #include <sys/sx.h> 53 #include <sys/sysctl.h> 54 #include <sys/sysproto.h> 55 #include <sys/umtxvar.h> 56 #include <machine/smp.h> 57 58 #ifdef RCTL 59 #include <sys/rctl.h> 60 #endif 61 62 FEATURE(racct, "Resource Accounting"); 63 64 /* 65 * Do not block processes that have their %cpu usage <= pcpu_threshold. 66 */ 67 static int pcpu_threshold = 1; 68 #ifdef RACCT_DEFAULT_TO_DISABLED 69 bool __read_frequently racct_enable = false; 70 #else 71 bool __read_frequently racct_enable = true; 72 #endif 73 74 SYSCTL_NODE(_kern, OID_AUTO, racct, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 75 "Resource Accounting"); 76 SYSCTL_BOOL(_kern_racct, OID_AUTO, enable, CTLFLAG_RDTUN, &racct_enable, 77 0, "Enable RACCT/RCTL"); 78 SYSCTL_UINT(_kern_racct, OID_AUTO, pcpu_threshold, CTLFLAG_RW, &pcpu_threshold, 79 0, "Processes with higher %cpu usage than this value can be throttled."); 80 81 /* 82 * How many seconds it takes to use the scheduler %cpu calculations. When a 83 * process starts, we compute its %cpu usage by dividing its runtime by the 84 * process wall clock time. After RACCT_PCPU_SECS pass, we use the value 85 * provided by the scheduler. 86 */ 87 #define RACCT_PCPU_SECS 3 88 89 struct mtx racct_lock; 90 MTX_SYSINIT(racct_lock, &racct_lock, "racct lock", MTX_DEF); 91 92 static uma_zone_t racct_zone; 93 94 static void racct_sub_racct(struct racct *dest, const struct racct *src); 95 static void racct_sub_cred_locked(struct ucred *cred, int resource, 96 uint64_t amount); 97 static void racct_add_cred_locked(struct ucred *cred, int resource, 98 uint64_t amount); 99 static int racct_set_locked(struct proc *p, int resource, uint64_t amount, 100 int force); 101 static void racct_updatepcpu_locked(struct proc *p); 102 static void racct_updatepcpu_racct_locked(struct racct *racct); 103 static void racct_updatepcpu_containers(void); 104 static void racct_settime_locked(struct proc *p, bool exit); 105 static void racct_zeropcpu_locked(struct proc *p); 106 107 SDT_PROVIDER_DEFINE(racct); 108 SDT_PROBE_DEFINE3(racct, , rusage, add, 109 "struct proc *", "int", "uint64_t"); 110 SDT_PROBE_DEFINE3(racct, , rusage, add__failure, 111 "struct proc *", "int", "uint64_t"); 112 SDT_PROBE_DEFINE3(racct, , rusage, add__buf, 113 "struct proc *", "const struct buf *", "int"); 114 SDT_PROBE_DEFINE3(racct, , rusage, add__cred, 115 "struct ucred *", "int", "uint64_t"); 116 SDT_PROBE_DEFINE3(racct, , rusage, add__force, 117 "struct proc *", "int", "uint64_t"); 118 SDT_PROBE_DEFINE3(racct, , rusage, set, 119 "struct proc *", "int", "uint64_t"); 120 SDT_PROBE_DEFINE3(racct, , rusage, set__failure, 121 "struct proc *", "int", "uint64_t"); 122 SDT_PROBE_DEFINE3(racct, , rusage, set__force, 123 "struct proc *", "int", "uint64_t"); 124 SDT_PROBE_DEFINE3(racct, , rusage, sub, 125 "struct proc *", "int", "uint64_t"); 126 SDT_PROBE_DEFINE3(racct, , rusage, sub__cred, 127 "struct ucred *", "int", "uint64_t"); 128 SDT_PROBE_DEFINE1(racct, , racct, create, 129 "struct racct *"); 130 SDT_PROBE_DEFINE1(racct, , racct, destroy, 131 "struct racct *"); 132 SDT_PROBE_DEFINE2(racct, , racct, join, 133 "struct racct *", "struct racct *"); 134 SDT_PROBE_DEFINE2(racct, , racct, join__failure, 135 "struct racct *", "struct racct *"); 136 SDT_PROBE_DEFINE2(racct, , racct, leave, 137 "struct racct *", "struct racct *"); 138 139 int racct_types[] = { 140 [RACCT_CPU] = 141 RACCT_IN_MILLIONS, 142 [RACCT_DATA] = 143 RACCT_RECLAIMABLE | RACCT_INHERITABLE | RACCT_DENIABLE, 144 [RACCT_STACK] = 145 RACCT_RECLAIMABLE | RACCT_INHERITABLE | RACCT_DENIABLE, 146 [RACCT_CORE] = 147 RACCT_DENIABLE, 148 [RACCT_RSS] = 149 RACCT_RECLAIMABLE, 150 [RACCT_MEMLOCK] = 151 RACCT_RECLAIMABLE | RACCT_DENIABLE, 152 [RACCT_NPROC] = 153 RACCT_RECLAIMABLE | RACCT_DENIABLE, 154 [RACCT_NOFILE] = 155 RACCT_RECLAIMABLE | RACCT_INHERITABLE | RACCT_DENIABLE, 156 [RACCT_VMEM] = 157 RACCT_RECLAIMABLE | RACCT_INHERITABLE | RACCT_DENIABLE, 158 [RACCT_NPTS] = 159 RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY, 160 [RACCT_SWAP] = 161 RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY, 162 [RACCT_NTHR] = 163 RACCT_RECLAIMABLE | RACCT_DENIABLE, 164 [RACCT_MSGQQUEUED] = 165 RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY, 166 [RACCT_MSGQSIZE] = 167 RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY, 168 [RACCT_NMSGQ] = 169 RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY, 170 [RACCT_NSEM] = 171 RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY, 172 [RACCT_NSEMOP] = 173 RACCT_RECLAIMABLE | RACCT_INHERITABLE | RACCT_DENIABLE, 174 [RACCT_NSHM] = 175 RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY, 176 [RACCT_SHMSIZE] = 177 RACCT_RECLAIMABLE | RACCT_DENIABLE | RACCT_SLOPPY, 178 [RACCT_WALLCLOCK] = 179 RACCT_IN_MILLIONS, 180 [RACCT_PCTCPU] = 181 RACCT_DECAYING | RACCT_DENIABLE | RACCT_IN_MILLIONS, 182 [RACCT_READBPS] = 183 RACCT_DECAYING, 184 [RACCT_WRITEBPS] = 185 RACCT_DECAYING, 186 [RACCT_READIOPS] = 187 RACCT_DECAYING, 188 [RACCT_WRITEIOPS] = 189 RACCT_DECAYING }; 190 191 static const fixpt_t RACCT_DECAY_FACTOR = 0.3 * FSCALE; 192 193 #ifdef SCHED_4BSD 194 /* 195 * Contains intermediate values for %cpu calculations to avoid using floating 196 * point in the kernel. 197 * ccpu_exp[k] = FSCALE * (ccpu/FSCALE)^k = FSCALE * exp(-k/20) 198 * It is needed only for the 4BSD scheduler, because in ULE, the ccpu equals to 199 * zero so the calculations are more straightforward. 200 */ 201 fixpt_t ccpu_exp[] = { 202 [0] = FSCALE * 1, 203 [1] = FSCALE * 0.95122942450071400909, 204 [2] = FSCALE * 0.90483741803595957316, 205 [3] = FSCALE * 0.86070797642505780722, 206 [4] = FSCALE * 0.81873075307798185866, 207 [5] = FSCALE * 0.77880078307140486824, 208 [6] = FSCALE * 0.74081822068171786606, 209 [7] = FSCALE * 0.70468808971871343435, 210 [8] = FSCALE * 0.67032004603563930074, 211 [9] = FSCALE * 0.63762815162177329314, 212 [10] = FSCALE * 0.60653065971263342360, 213 [11] = FSCALE * 0.57694981038048669531, 214 [12] = FSCALE * 0.54881163609402643262, 215 [13] = FSCALE * 0.52204577676101604789, 216 [14] = FSCALE * 0.49658530379140951470, 217 [15] = FSCALE * 0.47236655274101470713, 218 [16] = FSCALE * 0.44932896411722159143, 219 [17] = FSCALE * 0.42741493194872666992, 220 [18] = FSCALE * 0.40656965974059911188, 221 [19] = FSCALE * 0.38674102345450120691, 222 [20] = FSCALE * 0.36787944117144232159, 223 [21] = FSCALE * 0.34993774911115535467, 224 [22] = FSCALE * 0.33287108369807955328, 225 [23] = FSCALE * 0.31663676937905321821, 226 [24] = FSCALE * 0.30119421191220209664, 227 [25] = FSCALE * 0.28650479686019010032, 228 [26] = FSCALE * 0.27253179303401260312, 229 [27] = FSCALE * 0.25924026064589150757, 230 [28] = FSCALE * 0.24659696394160647693, 231 [29] = FSCALE * 0.23457028809379765313, 232 [30] = FSCALE * 0.22313016014842982893, 233 [31] = FSCALE * 0.21224797382674305771, 234 [32] = FSCALE * 0.20189651799465540848, 235 [33] = FSCALE * 0.19204990862075411423, 236 [34] = FSCALE * 0.18268352405273465022, 237 [35] = FSCALE * 0.17377394345044512668, 238 [36] = FSCALE * 0.16529888822158653829, 239 [37] = FSCALE * 0.15723716631362761621, 240 [38] = FSCALE * 0.14956861922263505264, 241 [39] = FSCALE * 0.14227407158651357185, 242 [40] = FSCALE * 0.13533528323661269189, 243 [41] = FSCALE * 0.12873490358780421886, 244 [42] = FSCALE * 0.12245642825298191021, 245 [43] = FSCALE * 0.11648415777349695786, 246 [44] = FSCALE * 0.11080315836233388333, 247 [45] = FSCALE * 0.10539922456186433678, 248 [46] = FSCALE * 0.10025884372280373372, 249 [47] = FSCALE * 0.09536916221554961888, 250 [48] = FSCALE * 0.09071795328941250337, 251 [49] = FSCALE * 0.08629358649937051097, 252 [50] = FSCALE * 0.08208499862389879516, 253 [51] = FSCALE * 0.07808166600115315231, 254 [52] = FSCALE * 0.07427357821433388042, 255 [53] = FSCALE * 0.07065121306042958674, 256 [54] = FSCALE * 0.06720551273974976512, 257 [55] = FSCALE * 0.06392786120670757270, 258 [56] = FSCALE * 0.06081006262521796499, 259 [57] = FSCALE * 0.05784432087483846296, 260 [58] = FSCALE * 0.05502322005640722902, 261 [59] = FSCALE * 0.05233970594843239308, 262 [60] = FSCALE * 0.04978706836786394297, 263 [61] = FSCALE * 0.04735892439114092119, 264 [62] = FSCALE * 0.04504920239355780606, 265 [63] = FSCALE * 0.04285212686704017991, 266 [64] = FSCALE * 0.04076220397836621516, 267 [65] = FSCALE * 0.03877420783172200988, 268 [66] = FSCALE * 0.03688316740124000544, 269 [67] = FSCALE * 0.03508435410084502588, 270 [68] = FSCALE * 0.03337326996032607948, 271 [69] = FSCALE * 0.03174563637806794323, 272 [70] = FSCALE * 0.03019738342231850073, 273 [71] = FSCALE * 0.02872463965423942912, 274 [72] = FSCALE * 0.02732372244729256080, 275 [73] = FSCALE * 0.02599112877875534358, 276 [74] = FSCALE * 0.02472352647033939120, 277 [75] = FSCALE * 0.02351774585600910823, 278 [76] = FSCALE * 0.02237077185616559577, 279 [77] = FSCALE * 0.02127973643837716938, 280 [78] = FSCALE * 0.02024191144580438847, 281 [79] = FSCALE * 0.01925470177538692429, 282 [80] = FSCALE * 0.01831563888873418029, 283 [81] = FSCALE * 0.01742237463949351138, 284 [82] = FSCALE * 0.01657267540176124754, 285 [83] = FSCALE * 0.01576441648485449082, 286 [84] = FSCALE * 0.01499557682047770621, 287 [85] = FSCALE * 0.01426423390899925527, 288 [86] = FSCALE * 0.01356855901220093175, 289 [87] = FSCALE * 0.01290681258047986886, 290 [88] = FSCALE * 0.01227733990306844117, 291 [89] = FSCALE * 0.01167856697039544521, 292 [90] = FSCALE * 0.01110899653824230649, 293 [91] = FSCALE * 0.01056720438385265337, 294 [92] = FSCALE * 0.01005183574463358164, 295 [93] = FSCALE * 0.00956160193054350793, 296 [94] = FSCALE * 0.00909527710169581709, 297 [95] = FSCALE * 0.00865169520312063417, 298 [96] = FSCALE * 0.00822974704902002884, 299 [97] = FSCALE * 0.00782837754922577143, 300 [98] = FSCALE * 0.00744658307092434051, 301 [99] = FSCALE * 0.00708340892905212004, 302 [100] = FSCALE * 0.00673794699908546709, 303 [101] = FSCALE * 0.00640933344625638184, 304 [102] = FSCALE * 0.00609674656551563610, 305 [103] = FSCALE * 0.00579940472684214321, 306 [104] = FSCALE * 0.00551656442076077241, 307 [105] = FSCALE * 0.00524751839918138427, 308 [106] = FSCALE * 0.00499159390691021621, 309 [107] = FSCALE * 0.00474815099941147558, 310 [108] = FSCALE * 0.00451658094261266798, 311 [109] = FSCALE * 0.00429630469075234057, 312 [110] = FSCALE * 0.00408677143846406699, 313 }; 314 #endif 315 316 #define CCPU_EXP_MAX 110 317 318 static void 319 racct_add_racct(struct racct *dest, const struct racct *src) 320 { 321 int i; 322 323 ASSERT_RACCT_ENABLED(); 324 RACCT_LOCK_ASSERT(); 325 326 /* 327 * Update resource usage in dest. 328 */ 329 for (i = 0; i <= RACCT_MAX; i++) { 330 KASSERT(dest->r_resources[i] >= 0, 331 ("%s: resource %d propagation meltdown: dest < 0", 332 __func__, i)); 333 KASSERT(src->r_resources[i] >= 0, 334 ("%s: resource %d propagation meltdown: src < 0", 335 __func__, i)); 336 dest->r_resources[i] += src->r_resources[i]; 337 } 338 } 339 340 static void 341 racct_sub_racct(struct racct *dest, const struct racct *src) 342 { 343 int i; 344 345 ASSERT_RACCT_ENABLED(); 346 RACCT_LOCK_ASSERT(); 347 348 /* 349 * Update resource usage in dest. 350 */ 351 for (i = 0; i <= RACCT_MAX; i++) { 352 if (!RACCT_IS_SLOPPY(i) && !RACCT_IS_DECAYING(i)) { 353 KASSERT(dest->r_resources[i] >= 0, 354 ("%s: resource %d propagation meltdown: dest < 0", 355 __func__, i)); 356 KASSERT(src->r_resources[i] >= 0, 357 ("%s: resource %d propagation meltdown: src < 0", 358 __func__, i)); 359 KASSERT(src->r_resources[i] <= dest->r_resources[i], 360 ("%s: resource %d propagation meltdown: src > dest", 361 __func__, i)); 362 } 363 if (RACCT_CAN_DROP(i)) { 364 dest->r_resources[i] -= src->r_resources[i]; 365 if (dest->r_resources[i] < 0) 366 dest->r_resources[i] = 0; 367 } 368 } 369 } 370 371 void 372 racct_create(struct racct **racctp) 373 { 374 375 if (!racct_enable) 376 return; 377 378 SDT_PROBE1(racct, , racct, create, racctp); 379 380 KASSERT(*racctp == NULL, ("racct already allocated")); 381 382 *racctp = uma_zalloc(racct_zone, M_WAITOK | M_ZERO); 383 } 384 385 static void 386 racct_destroy_locked(struct racct **racctp) 387 { 388 struct racct *racct; 389 int i; 390 391 ASSERT_RACCT_ENABLED(); 392 393 SDT_PROBE1(racct, , racct, destroy, racctp); 394 395 RACCT_LOCK_ASSERT(); 396 KASSERT(racctp != NULL, ("NULL racctp")); 397 KASSERT(*racctp != NULL, ("NULL racct")); 398 399 racct = *racctp; 400 401 for (i = 0; i <= RACCT_MAX; i++) { 402 if (RACCT_IS_SLOPPY(i)) 403 continue; 404 if (!RACCT_IS_RECLAIMABLE(i)) 405 continue; 406 KASSERT(racct->r_resources[i] == 0, 407 ("destroying non-empty racct: " 408 "%ju allocated for resource %d\n", 409 racct->r_resources[i], i)); 410 } 411 uma_zfree(racct_zone, racct); 412 *racctp = NULL; 413 } 414 415 void 416 racct_destroy(struct racct **racct) 417 { 418 419 if (!racct_enable) 420 return; 421 422 RACCT_LOCK(); 423 racct_destroy_locked(racct); 424 RACCT_UNLOCK(); 425 } 426 427 /* 428 * Increase consumption of 'resource' by 'amount' for 'racct', 429 * but not its parents. Differently from other cases, 'amount' here 430 * may be less than zero. 431 */ 432 static void 433 racct_adjust_resource(struct racct *racct, int resource, 434 int64_t amount) 435 { 436 437 ASSERT_RACCT_ENABLED(); 438 RACCT_LOCK_ASSERT(); 439 KASSERT(racct != NULL, ("NULL racct")); 440 441 racct->r_resources[resource] += amount; 442 if (racct->r_resources[resource] < 0) { 443 KASSERT(RACCT_IS_SLOPPY(resource) || RACCT_IS_DECAYING(resource), 444 ("%s: resource %d usage < 0", __func__, resource)); 445 racct->r_resources[resource] = 0; 446 } 447 } 448 449 static int 450 racct_add_locked(struct proc *p, int resource, uint64_t amount, int force) 451 { 452 #ifdef RCTL 453 int error; 454 #endif 455 456 ASSERT_RACCT_ENABLED(); 457 458 /* 459 * We need proc lock to dereference p->p_ucred. 460 */ 461 PROC_LOCK_ASSERT(p, MA_OWNED); 462 463 #ifdef RCTL 464 error = rctl_enforce(p, resource, amount); 465 if (error && !force && RACCT_IS_DENIABLE(resource)) { 466 SDT_PROBE3(racct, , rusage, add__failure, p, resource, amount); 467 return (error); 468 } 469 #endif 470 racct_adjust_resource(p->p_racct, resource, amount); 471 racct_add_cred_locked(p->p_ucred, resource, amount); 472 473 return (0); 474 } 475 476 /* 477 * Increase allocation of 'resource' by 'amount' for process 'p'. 478 * Return 0 if it's below limits, or errno, if it's not. 479 */ 480 int 481 racct_add(struct proc *p, int resource, uint64_t amount) 482 { 483 int error; 484 485 if (!racct_enable) 486 return (0); 487 488 SDT_PROBE3(racct, , rusage, add, p, resource, amount); 489 490 RACCT_LOCK(); 491 error = racct_add_locked(p, resource, amount, 0); 492 RACCT_UNLOCK(); 493 return (error); 494 } 495 496 /* 497 * Increase allocation of 'resource' by 'amount' for process 'p'. 498 * Doesn't check for limits and never fails. 499 */ 500 void 501 racct_add_force(struct proc *p, int resource, uint64_t amount) 502 { 503 504 if (!racct_enable) 505 return; 506 507 SDT_PROBE3(racct, , rusage, add__force, p, resource, amount); 508 509 RACCT_LOCK(); 510 racct_add_locked(p, resource, amount, 1); 511 RACCT_UNLOCK(); 512 } 513 514 static void 515 racct_add_cred_locked(struct ucred *cred, int resource, uint64_t amount) 516 { 517 struct prison *pr; 518 519 ASSERT_RACCT_ENABLED(); 520 521 racct_adjust_resource(cred->cr_ruidinfo->ui_racct, resource, amount); 522 for (pr = cred->cr_prison; pr != NULL; pr = pr->pr_parent) 523 racct_adjust_resource(pr->pr_prison_racct->prr_racct, resource, 524 amount); 525 racct_adjust_resource(cred->cr_loginclass->lc_racct, resource, amount); 526 } 527 528 /* 529 * Increase allocation of 'resource' by 'amount' for credential 'cred'. 530 * Doesn't check for limits and never fails. 531 */ 532 void 533 racct_add_cred(struct ucred *cred, int resource, uint64_t amount) 534 { 535 536 if (!racct_enable) 537 return; 538 539 SDT_PROBE3(racct, , rusage, add__cred, cred, resource, amount); 540 541 RACCT_LOCK(); 542 racct_add_cred_locked(cred, resource, amount); 543 RACCT_UNLOCK(); 544 } 545 546 /* 547 * Account for disk IO resource consumption. Checks for limits, 548 * but never fails, due to disk limits being undeniable. 549 */ 550 void 551 racct_add_buf(struct proc *p, const struct buf *bp, int is_write) 552 { 553 554 ASSERT_RACCT_ENABLED(); 555 PROC_LOCK_ASSERT(p, MA_OWNED); 556 557 SDT_PROBE3(racct, , rusage, add__buf, p, bp, is_write); 558 559 RACCT_LOCK(); 560 if (is_write) { 561 racct_add_locked(curproc, RACCT_WRITEBPS, bp->b_bcount, 1); 562 racct_add_locked(curproc, RACCT_WRITEIOPS, 1, 1); 563 } else { 564 racct_add_locked(curproc, RACCT_READBPS, bp->b_bcount, 1); 565 racct_add_locked(curproc, RACCT_READIOPS, 1, 1); 566 } 567 RACCT_UNLOCK(); 568 } 569 570 static void 571 racct_settime_locked(struct proc *p, bool exit) 572 { 573 struct thread *td; 574 struct timeval wallclock; 575 uint64_t runtime; 576 577 ASSERT_RACCT_ENABLED(); 578 RACCT_LOCK_ASSERT(); 579 PROC_LOCK_ASSERT(p, MA_OWNED); 580 581 if (exit) { 582 /* 583 * proc_reap() has already calculated rux 584 * and added crux to rux. 585 */ 586 runtime = cputick2usec(p->p_rux.rux_runtime - 587 p->p_crux.rux_runtime); 588 } else { 589 PROC_STATLOCK(p); 590 FOREACH_THREAD_IN_PROC(p, td) 591 ruxagg(p, td); 592 PROC_STATUNLOCK(p); 593 runtime = cputick2usec(p->p_rux.rux_runtime); 594 } 595 microuptime(&wallclock); 596 timevalsub(&wallclock, &p->p_stats->p_start); 597 598 racct_set_locked(p, RACCT_CPU, runtime, 0); 599 racct_set_locked(p, RACCT_WALLCLOCK, 600 (uint64_t)wallclock.tv_sec * 1000000 + 601 wallclock.tv_usec, 0); 602 } 603 604 static int 605 racct_set_locked(struct proc *p, int resource, uint64_t amount, int force) 606 { 607 int64_t old_amount, diff_proc, diff_cred; 608 #ifdef RCTL 609 int error; 610 #endif 611 612 ASSERT_RACCT_ENABLED(); 613 614 /* 615 * We need proc lock to dereference p->p_ucred. 616 */ 617 PROC_LOCK_ASSERT(p, MA_OWNED); 618 619 old_amount = p->p_racct->r_resources[resource]; 620 /* 621 * The diffs may be negative. 622 */ 623 diff_proc = amount - old_amount; 624 diff_cred = diff_proc; 625 #ifdef notyet 626 KASSERT(diff_proc >= 0 || RACCT_CAN_DROP(resource), 627 ("%s: usage of non-droppable resource %d dropping", __func__, 628 resource)); 629 #endif 630 #ifdef RCTL 631 if (diff_proc > 0) { 632 error = rctl_enforce(p, resource, diff_proc); 633 if (error && !force && RACCT_IS_DENIABLE(resource)) { 634 SDT_PROBE3(racct, , rusage, set__failure, p, resource, 635 amount); 636 return (error); 637 } 638 } 639 #endif 640 racct_adjust_resource(p->p_racct, resource, diff_proc); 641 if (diff_cred > 0) 642 racct_add_cred_locked(p->p_ucred, resource, diff_cred); 643 else if (diff_cred < 0) 644 racct_sub_cred_locked(p->p_ucred, resource, -diff_cred); 645 646 return (0); 647 } 648 649 /* 650 * Set allocation of 'resource' to 'amount' for process 'p'. 651 * Return 0 if it's below limits, or errno, if it's not. 652 * 653 * Note that decreasing the allocation always returns 0, 654 * even if it's above the limit. 655 */ 656 int 657 racct_set_unlocked(struct proc *p, int resource, uint64_t amount) 658 { 659 int error; 660 661 ASSERT_RACCT_ENABLED(); 662 PROC_LOCK(p); 663 error = racct_set(p, resource, amount); 664 PROC_UNLOCK(p); 665 return (error); 666 } 667 668 int 669 racct_set(struct proc *p, int resource, uint64_t amount) 670 { 671 int error; 672 673 if (!racct_enable) 674 return (0); 675 676 SDT_PROBE3(racct, , rusage, set__force, p, resource, amount); 677 678 RACCT_LOCK(); 679 error = racct_set_locked(p, resource, amount, 0); 680 RACCT_UNLOCK(); 681 return (error); 682 } 683 684 void 685 racct_set_force(struct proc *p, int resource, uint64_t amount) 686 { 687 688 if (!racct_enable) 689 return; 690 691 SDT_PROBE3(racct, , rusage, set, p, resource, amount); 692 693 RACCT_LOCK(); 694 racct_set_locked(p, resource, amount, 1); 695 RACCT_UNLOCK(); 696 } 697 698 /* 699 * Returns amount of 'resource' the process 'p' can keep allocated. 700 * Allocating more than that would be denied, unless the resource 701 * is marked undeniable. Amount of already allocated resource does 702 * not matter. 703 */ 704 uint64_t 705 racct_get_limit(struct proc *p, int resource) 706 { 707 #ifdef RCTL 708 uint64_t available; 709 710 if (!racct_enable) 711 return (UINT64_MAX); 712 713 RACCT_LOCK(); 714 available = rctl_get_limit(p, resource); 715 RACCT_UNLOCK(); 716 717 return (available); 718 #else 719 720 return (UINT64_MAX); 721 #endif 722 } 723 724 /* 725 * Returns amount of 'resource' the process 'p' can keep allocated. 726 * Allocating more than that would be denied, unless the resource 727 * is marked undeniable. Amount of already allocated resource does 728 * matter. 729 */ 730 uint64_t 731 racct_get_available(struct proc *p, int resource) 732 { 733 #ifdef RCTL 734 uint64_t available; 735 736 if (!racct_enable) 737 return (UINT64_MAX); 738 739 RACCT_LOCK(); 740 available = rctl_get_available(p, resource); 741 RACCT_UNLOCK(); 742 743 return (available); 744 #else 745 746 return (UINT64_MAX); 747 #endif 748 } 749 750 /* 751 * Returns amount of the %cpu resource that process 'p' can add to its %cpu 752 * utilization. Adding more than that would lead to the process being 753 * throttled. 754 */ 755 static int64_t 756 racct_pcpu_available(struct proc *p) 757 { 758 #ifdef RCTL 759 uint64_t available; 760 761 ASSERT_RACCT_ENABLED(); 762 763 RACCT_LOCK(); 764 available = rctl_pcpu_available(p); 765 RACCT_UNLOCK(); 766 767 return (available); 768 #else 769 770 return (INT64_MAX); 771 #endif 772 } 773 774 /* 775 * Decrease allocation of 'resource' by 'amount' for process 'p'. 776 */ 777 void 778 racct_sub(struct proc *p, int resource, uint64_t amount) 779 { 780 781 if (!racct_enable) 782 return; 783 784 SDT_PROBE3(racct, , rusage, sub, p, resource, amount); 785 786 /* 787 * We need proc lock to dereference p->p_ucred. 788 */ 789 PROC_LOCK_ASSERT(p, MA_OWNED); 790 KASSERT(RACCT_CAN_DROP(resource), 791 ("%s: called for non-droppable resource %d", __func__, resource)); 792 793 RACCT_LOCK(); 794 KASSERT(amount <= p->p_racct->r_resources[resource], 795 ("%s: freeing %ju of resource %d, which is more " 796 "than allocated %jd for %s (pid %d)", __func__, amount, resource, 797 (intmax_t)p->p_racct->r_resources[resource], p->p_comm, p->p_pid)); 798 799 racct_adjust_resource(p->p_racct, resource, -amount); 800 racct_sub_cred_locked(p->p_ucred, resource, amount); 801 RACCT_UNLOCK(); 802 } 803 804 static void 805 racct_sub_cred_locked(struct ucred *cred, int resource, uint64_t amount) 806 { 807 struct prison *pr; 808 809 ASSERT_RACCT_ENABLED(); 810 811 racct_adjust_resource(cred->cr_ruidinfo->ui_racct, resource, -amount); 812 for (pr = cred->cr_prison; pr != NULL; pr = pr->pr_parent) 813 racct_adjust_resource(pr->pr_prison_racct->prr_racct, resource, 814 -amount); 815 racct_adjust_resource(cred->cr_loginclass->lc_racct, resource, -amount); 816 } 817 818 /* 819 * Decrease allocation of 'resource' by 'amount' for credential 'cred'. 820 */ 821 void 822 racct_sub_cred(struct ucred *cred, int resource, uint64_t amount) 823 { 824 825 if (!racct_enable) 826 return; 827 828 SDT_PROBE3(racct, , rusage, sub__cred, cred, resource, amount); 829 830 #ifdef notyet 831 KASSERT(RACCT_CAN_DROP(resource), 832 ("%s: called for resource %d which can not drop", __func__, 833 resource)); 834 #endif 835 836 RACCT_LOCK(); 837 racct_sub_cred_locked(cred, resource, amount); 838 RACCT_UNLOCK(); 839 } 840 841 /* 842 * Inherit resource usage information from the parent process. 843 */ 844 int 845 racct_proc_fork(struct proc *parent, struct proc *child) 846 { 847 int i, error = 0; 848 849 if (!racct_enable) 850 return (0); 851 852 /* 853 * Create racct for the child process. 854 */ 855 racct_create(&child->p_racct); 856 857 PROC_LOCK(parent); 858 PROC_LOCK(child); 859 RACCT_LOCK(); 860 861 #ifdef RCTL 862 error = rctl_proc_fork(parent, child); 863 if (error != 0) 864 goto out; 865 #endif 866 867 child->p_throttled = 0; 868 869 /* 870 * Inherit resource usage. 871 */ 872 for (i = 0; i <= RACCT_MAX; i++) { 873 if (parent->p_racct->r_resources[i] == 0 || 874 !RACCT_IS_INHERITABLE(i)) 875 continue; 876 877 error = racct_set_locked(child, i, 878 parent->p_racct->r_resources[i], 0); 879 if (error != 0) 880 goto out; 881 } 882 883 error = racct_add_locked(child, RACCT_NPROC, 1, 0); 884 error += racct_add_locked(child, RACCT_NTHR, 1, 0); 885 886 out: 887 RACCT_UNLOCK(); 888 PROC_UNLOCK(child); 889 PROC_UNLOCK(parent); 890 891 if (error != 0) 892 racct_proc_exit(child); 893 894 return (error); 895 } 896 897 /* 898 * Called at the end of fork1(), to handle rules that require the process 899 * to be fully initialized. 900 */ 901 void 902 racct_proc_fork_done(struct proc *child) 903 { 904 905 if (!racct_enable) 906 return; 907 908 #ifdef RCTL 909 PROC_LOCK(child); 910 RACCT_LOCK(); 911 rctl_enforce(child, RACCT_NPROC, 0); 912 rctl_enforce(child, RACCT_NTHR, 0); 913 RACCT_UNLOCK(); 914 PROC_UNLOCK(child); 915 #endif 916 } 917 918 void 919 racct_proc_exit(struct proc *p) 920 { 921 int i; 922 923 if (!racct_enable) 924 return; 925 926 PROC_LOCK(p); 927 RACCT_LOCK(); 928 929 racct_settime_locked(p, true); 930 racct_zeropcpu_locked(p); 931 932 KASSERT(p->p_racct->r_resources[RACCT_RSS] == 0, 933 ("process reaped with %ju allocated for RSS\n", 934 p->p_racct->r_resources[RACCT_RSS])); 935 for (i = 0; i <= RACCT_MAX; i++) { 936 if (p->p_racct->r_resources[i] == 0) 937 continue; 938 if (!RACCT_IS_RECLAIMABLE(i)) 939 continue; 940 racct_set_locked(p, i, 0, 0); 941 } 942 943 #ifdef RCTL 944 rctl_racct_release(p->p_racct); 945 #endif 946 racct_destroy_locked(&p->p_racct); 947 RACCT_UNLOCK(); 948 PROC_UNLOCK(p); 949 } 950 951 /* 952 * Called to signal credentials change, to move resource utilisation 953 * between raccts. Must be called with the proc lock held, in the same span as 954 * the credentials change itself (i.e., without the proc lock being unlocked 955 * between the two), but the order does not matter. 956 */ 957 void 958 racct_proc_ucred_changed(struct proc *p, struct ucred *oldcred, 959 struct ucred *newcred) 960 { 961 struct uidinfo *olduip, *newuip; 962 struct loginclass *oldlc, *newlc; 963 struct prison *oldpr, *newpr, *pr; 964 965 if (!racct_enable) 966 return; 967 968 PROC_LOCK_ASSERT(p, MA_OWNED); 969 970 newuip = newcred->cr_ruidinfo; 971 olduip = oldcred->cr_ruidinfo; 972 newlc = newcred->cr_loginclass; 973 oldlc = oldcred->cr_loginclass; 974 newpr = newcred->cr_prison; 975 oldpr = oldcred->cr_prison; 976 977 RACCT_LOCK(); 978 if (newuip != olduip) { 979 racct_sub_racct(olduip->ui_racct, p->p_racct); 980 racct_add_racct(newuip->ui_racct, p->p_racct); 981 } 982 if (newlc != oldlc) { 983 racct_sub_racct(oldlc->lc_racct, p->p_racct); 984 racct_add_racct(newlc->lc_racct, p->p_racct); 985 } 986 if (newpr != oldpr) { 987 for (pr = oldpr; pr != NULL; pr = pr->pr_parent) 988 racct_sub_racct(pr->pr_prison_racct->prr_racct, 989 p->p_racct); 990 for (pr = newpr; pr != NULL; pr = pr->pr_parent) 991 racct_add_racct(pr->pr_prison_racct->prr_racct, 992 p->p_racct); 993 } 994 RACCT_UNLOCK(); 995 } 996 997 void 998 racct_move(struct racct *dest, struct racct *src) 999 { 1000 1001 ASSERT_RACCT_ENABLED(); 1002 1003 RACCT_LOCK(); 1004 racct_add_racct(dest, src); 1005 racct_sub_racct(src, src); 1006 dest->r_runtime = src->r_runtime; 1007 dest->r_time = src->r_time; 1008 src->r_runtime = 0; 1009 timevalsub(&src->r_time, &src->r_time); 1010 RACCT_UNLOCK(); 1011 } 1012 1013 static void 1014 ast_racct(struct thread *td, int tda __unused) 1015 { 1016 struct proc *p; 1017 1018 ASSERT_RACCT_ENABLED(); 1019 1020 p = td->td_proc; 1021 if (p->p_throttled == 0) 1022 return; 1023 1024 PROC_LOCK(p); 1025 while (p->p_throttled != 0) { 1026 msleep(p->p_racct, &p->p_mtx, 0, "racct", 1027 p->p_throttled < 0 ? 0 : p->p_throttled); 1028 if (p->p_throttled > 0) 1029 p->p_throttled = 0; 1030 } 1031 PROC_UNLOCK(p); 1032 } 1033 1034 /* 1035 * Make the process sleep in userret() for 'timeout' ticks. Setting 1036 * timeout to -1 makes it sleep until woken up by racct_proc_wakeup(). 1037 */ 1038 void 1039 racct_proc_throttle(struct proc *p, int timeout) 1040 { 1041 struct thread *td; 1042 #ifdef SMP 1043 int cpuid; 1044 #endif 1045 1046 KASSERT(timeout != 0, ("timeout %d", timeout)); 1047 ASSERT_RACCT_ENABLED(); 1048 PROC_LOCK_ASSERT(p, MA_OWNED); 1049 1050 /* 1051 * Do not block kernel processes. Also do not block processes with 1052 * low %cpu utilization to improve interactivity. 1053 */ 1054 if ((p->p_flag & (P_SYSTEM | P_KPROC)) != 0) 1055 return; 1056 1057 if (p->p_throttled < 0 || (timeout > 0 && p->p_throttled > timeout)) 1058 return; 1059 1060 p->p_throttled = timeout; 1061 1062 FOREACH_THREAD_IN_PROC(p, td) { 1063 thread_lock(td); 1064 ast_sched_locked(td, TDA_RACCT); 1065 1066 switch (TD_GET_STATE(td)) { 1067 case TDS_RUNQ: 1068 /* 1069 * If the thread is on the scheduler run-queue, we can 1070 * not just remove it from there. So we set the flag 1071 * TDA_SCHED for the thread, so that once it is 1072 * running, it is taken off the cpu as soon as possible. 1073 */ 1074 ast_sched_locked(td, TDA_SCHED); 1075 break; 1076 case TDS_RUNNING: 1077 /* 1078 * If the thread is running, we request a context 1079 * switch for it by setting the TDA_SCHED flag. 1080 */ 1081 ast_sched_locked(td, TDA_SCHED); 1082 #ifdef SMP 1083 cpuid = td->td_oncpu; 1084 if ((cpuid != NOCPU) && (td != curthread)) 1085 ipi_cpu(cpuid, IPI_AST); 1086 #endif 1087 break; 1088 default: 1089 break; 1090 } 1091 thread_unlock(td); 1092 } 1093 } 1094 1095 static void 1096 racct_proc_wakeup(struct proc *p) 1097 { 1098 1099 ASSERT_RACCT_ENABLED(); 1100 1101 PROC_LOCK_ASSERT(p, MA_OWNED); 1102 1103 if (p->p_throttled != 0) { 1104 p->p_throttled = 0; 1105 wakeup(p->p_racct); 1106 } 1107 } 1108 1109 static void 1110 racct_decay_callback(struct racct *racct, void *dummy1, void *dummy2) 1111 { 1112 ASSERT_RACCT_ENABLED(); 1113 RACCT_LOCK_ASSERT(); 1114 1115 #ifdef RCTL 1116 rctl_throttle_decay(racct, RACCT_READBPS); 1117 rctl_throttle_decay(racct, RACCT_WRITEBPS); 1118 rctl_throttle_decay(racct, RACCT_READIOPS); 1119 rctl_throttle_decay(racct, RACCT_WRITEIOPS); 1120 #endif 1121 } 1122 1123 static void 1124 racct_decay_pre(void) 1125 { 1126 1127 RACCT_LOCK(); 1128 } 1129 1130 static void 1131 racct_decay_post(void) 1132 { 1133 1134 RACCT_UNLOCK(); 1135 } 1136 1137 static void 1138 racct_decay(void) 1139 { 1140 1141 ASSERT_RACCT_ENABLED(); 1142 1143 ui_racct_foreach(racct_decay_callback, racct_decay_pre, 1144 racct_decay_post, NULL, NULL); 1145 loginclass_racct_foreach(racct_decay_callback, racct_decay_pre, 1146 racct_decay_post, NULL, NULL); 1147 prison_racct_foreach(racct_decay_callback, racct_decay_pre, 1148 racct_decay_post, NULL, NULL); 1149 } 1150 1151 static void 1152 racct_updatepcpu_racct_locked(struct racct *racct) 1153 { 1154 struct timeval diff; 1155 uint64_t elapsed; 1156 uint64_t runtime; 1157 uint64_t newpcpu; 1158 uint64_t oldpcpu; 1159 1160 ASSERT_RACCT_ENABLED(); 1161 RACCT_LOCK_ASSERT(); 1162 1163 /* Difference between now and previously-recorded time. */ 1164 microuptime(&diff); 1165 timevalsub(&diff, &racct->r_time); 1166 elapsed = (uint64_t)diff.tv_sec * 1000000 + diff.tv_usec; 1167 1168 /* Difference between current and previously-recorded runtime. */ 1169 runtime = racct->r_resources[RACCT_CPU] - racct->r_runtime; 1170 1171 newpcpu = runtime * 100 * 1000000 / elapsed; 1172 oldpcpu = racct->r_resources[RACCT_PCTCPU]; 1173 /* 1174 * This calculation is equivalent to 1175 * (1 - 0.3) * newpcpu + 0.3 * oldpcpu 1176 * where RACCT_DECAY_FACTOR = 0.3 * FSCALE. 1177 */ 1178 racct->r_resources[RACCT_PCTCPU] = ((FSCALE - RACCT_DECAY_FACTOR) * 1179 newpcpu + RACCT_DECAY_FACTOR * oldpcpu) / FSCALE; 1180 if (racct->r_resources[RACCT_PCTCPU] > 1181 100 * 1000000 * (uint64_t)mp_ncpus) 1182 racct->r_resources[RACCT_PCTCPU] = 100 * 1000000 * 1183 (uint64_t)mp_ncpus; 1184 1185 /* Record current times. */ 1186 racct->r_runtime = racct->r_resources[RACCT_CPU]; 1187 timevaladd(&racct->r_time, &diff); 1188 } 1189 1190 static void 1191 racct_zeropcpu_locked(struct proc *p) 1192 { 1193 ASSERT_RACCT_ENABLED(); 1194 PROC_LOCK_ASSERT(p, MA_OWNED); 1195 1196 p->p_racct->r_resources[RACCT_PCTCPU] = 0; 1197 } 1198 1199 static void 1200 racct_updatepcpu_locked(struct proc *p) 1201 { 1202 ASSERT_RACCT_ENABLED(); 1203 PROC_LOCK_ASSERT(p, MA_OWNED); 1204 1205 racct_updatepcpu_racct_locked(p->p_racct); 1206 } 1207 1208 static void 1209 racct_updatepcpu_pre(void) 1210 { 1211 1212 RACCT_LOCK(); 1213 } 1214 1215 static void 1216 racct_updatepcpu_post(void) 1217 { 1218 1219 RACCT_UNLOCK(); 1220 } 1221 1222 static void 1223 racct_updatepcpu_racct_callback(struct racct *racct, void *dummy1, void *dummy2) 1224 { 1225 racct_updatepcpu_racct_locked(racct); 1226 } 1227 1228 static void 1229 racct_updatepcpu_containers(void) 1230 { 1231 ASSERT_RACCT_ENABLED(); 1232 1233 ui_racct_foreach(racct_updatepcpu_racct_callback, racct_updatepcpu_pre, 1234 racct_updatepcpu_post, NULL, NULL); 1235 loginclass_racct_foreach(racct_updatepcpu_racct_callback, racct_updatepcpu_pre, 1236 racct_updatepcpu_post, NULL, NULL); 1237 prison_racct_foreach(racct_updatepcpu_racct_callback, racct_updatepcpu_pre, 1238 racct_updatepcpu_post, NULL, NULL); 1239 } 1240 1241 static bool 1242 racct_proc_to_skip(const struct proc *p) 1243 { 1244 PROC_LOCK_ASSERT(p, MA_OWNED); 1245 return (p->p_state != PRS_NORMAL || (p->p_flag & P_IDLEPROC) != 0); 1246 } 1247 1248 static void 1249 racctd(void) 1250 { 1251 struct proc *p; 1252 1253 ASSERT_RACCT_ENABLED(); 1254 1255 for (;;) { 1256 racct_decay(); 1257 1258 sx_slock(&allproc_lock); 1259 1260 FOREACH_PROC_IN_SYSTEM(p) { 1261 PROC_LOCK(p); 1262 if (racct_proc_to_skip(p)) { 1263 PROC_UNLOCK(p); 1264 continue; 1265 } 1266 1267 RACCT_LOCK(); 1268 #ifdef RCTL 1269 rctl_throttle_decay(p->p_racct, RACCT_READBPS); 1270 rctl_throttle_decay(p->p_racct, RACCT_WRITEBPS); 1271 rctl_throttle_decay(p->p_racct, RACCT_READIOPS); 1272 rctl_throttle_decay(p->p_racct, RACCT_WRITEIOPS); 1273 #endif 1274 racct_settime_locked(p, false); 1275 racct_updatepcpu_locked(p); 1276 RACCT_UNLOCK(); 1277 PROC_UNLOCK(p); 1278 } 1279 1280 /* 1281 * To ensure that processes are throttled in a fair way, we need 1282 * to iterate over all processes again and check the limits 1283 * for %cpu resource only after ucred racct containers have been 1284 * properly filled. 1285 */ 1286 FOREACH_PROC_IN_SYSTEM(p) { 1287 PROC_LOCK(p); 1288 if (racct_proc_to_skip(p)) { 1289 PROC_UNLOCK(p); 1290 continue; 1291 } 1292 1293 if (racct_pcpu_available(p) <= 0) { 1294 if (p->p_racct->r_resources[RACCT_PCTCPU] > 1295 pcpu_threshold) 1296 racct_proc_throttle(p, -1); 1297 } else if (p->p_throttled == -1) { 1298 racct_proc_wakeup(p); 1299 } 1300 PROC_UNLOCK(p); 1301 } 1302 sx_sunlock(&allproc_lock); 1303 1304 racct_updatepcpu_containers(); 1305 pause("-", hz); 1306 } 1307 } 1308 1309 static struct kproc_desc racctd_kp = { 1310 "racctd", 1311 racctd, 1312 NULL 1313 }; 1314 1315 static void 1316 racctd_init(void *dummy __unused) 1317 { 1318 if (!racct_enable) 1319 return; 1320 1321 kproc_start(&racctd_kp); 1322 } 1323 SYSINIT(racctd, SI_SUB_RACCTD, SI_ORDER_FIRST, racctd_init, NULL); 1324 1325 static void 1326 racct_init(void *dummy __unused) 1327 { 1328 if (!racct_enable) 1329 return; 1330 1331 racct_zone = uma_zcreate("racct", sizeof(struct racct), 1332 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); 1333 ast_register(TDA_RACCT, ASTR_ASTF_REQUIRED, 0, ast_racct); 1334 1335 /* 1336 * XXX: Move this somewhere. 1337 */ 1338 prison0.pr_prison_racct = prison_racct_find("0"); 1339 } 1340 SYSINIT(racct, SI_SUB_RACCT, SI_ORDER_FIRST, racct_init, NULL); 1341