aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_racct.c
Commit message (Collapse)AuthorAgeFilesLines
* racct: Fix a typo in a commentMark Johnston2025-05-011-1/+1
| | | | | Reported by: kib MFC after: 1 week
* racct: Fix accounting of CPU time for the system idle processMark Johnston2025-05-011-18/+4
| | | | | | | | | | | | | - Add a flag which cleanly indicates that a given process is the system idle process. - Modify racctd() to skip over the idle proc when aggregating CPU time and other metrics which don't apply to the idle thread. - Remove handling for idle threads from racct_getpcpu(). PR: 269097 Reviewed by: olce, kib Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50073
* proc: Remove kernel stack swapping support, part 6Mark Johnston2024-07-291-6/+0
| | | | | | | | | | | | - Remove most checks of the P_INMEM flag. - Some uses remain since a few userspace tools, e.g., ps(1) and top(1) expect the flag to be set. These can be cleaned up but the code has most likely been copy-pasted elsewhere and while linger for a long time. Tested by: pho Reviewed by: alc, imp, kib Differential Revision: https://reviews.freebsd.org/D46117
* kern_racct.c: Don't compile if RACCT undefinedOlivier Certner2023-11-221-4/+0
| | | | | | | | | | Just skip compiling this file if RACCT isn't defined. This allows to skip including headers that no code uses at all, and also to remove the whole file's #ifdef/#endif bracketing. Reviewed by: markj MFC after: 2 weeks Sponsored by: The FreeBSD Foundation
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* AST: reworkKonstantin Belousov2022-08-021-7/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | Make most AST handlers dynamically registered. This allows to have subsystem-specific handler source located in the subsystem files, instead of making subr_trap.c aware of it. For instance, signal delivery code on return to userspace is now moved to kern_sig.c. Also, it allows to have some handlers designated as the cleanup (kclear) type, which are called both at AST and on thread/process exit. For instance, ast(), exit1(), and NFS server no longer need to be aware about UFS softdep processing. The dynamic registration also allows third-party modules to register AST handlers if needed. There is one caveat with loadable modules: the code does not make any effort to ensure that the module is not unloaded before all threads processed through AST handler in it. In fact, this is already present behavior for hwpmc.ko and ufs.ko. I do not think it is worth the efforts and the runtime overhead to try to fix it. Reviewed by: markj Tested by: emaste (arm64), pho Discussed with: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D35888
* sysent: Get rid of bogus sys/sysent.h include.Dmitry Chagin2022-05-281-1/+0
| | | | | | Where appropriate hide sysent.h under proper condition. MFC after: 2 weeks
* kern_racct: Fix a typo in a source code commentGordon Bergling2022-02-061-1/+1
| | | | | | - s/maxumum/maximum/ MFC after: 3 days
* umtx: Split umtx.h on two counterparts.Dmitry Chagin2021-07-291-1/+1
| | | | | | | | | | | | To prevent umtx.h polluting by future changes split it on two headers: umtx.h - ABI header for userspace; umtxvar.h - the kernel staff. While here fix umtx_key_match style. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D31248 MFC after: 2 weeks
* Use atomic loads/stores when updating td->td_stateAlex Richardson2021-02-181-1/+1
| | | | | | | | | | | | | | | KCSAN complains about racy accesses in the locking code. Those races are fine since they are inside a TD_SET_RUNNING() loop that expects the value to be changed by another CPU. Use relaxed atomic stores/loads to indicate that this variable can be written/read by multiple CPUs at the same time. This will also prevent the compiler from doing unexpected re-ordering. Reported by: GENERIC-KCSAN Test Plan: KCSAN no longer complains, kernel still runs fine. Reviewed By: markj, mjg (earlier version) Differential Revision: https://reviews.freebsd.org/D28569
* Drop "All rights reserved" from all my stuff. This includesEdward Tomasz Napierala2020-10-281-1/+0
| | | | | | | | | | | | Foundation copyrights, approved by emaste@. It does not include files which carry other people's copyrights; if you're one of those people, feel free to make similar change. Reviewed by: emaste, imp, gbe (manpages) Differential Revision: https://reviews.freebsd.org/D26980 Notes: svn path=/head/; revision=367105
* Move racct/rctl throttling from userret() to ast(). There's no reasonEdward Tomasz Napierala2020-09-141-0/+2
| | | | | | | | | | | | for it to sit in the syscall fast path. Reviewed by: kib MFC after: 2 weeks Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D26368 Notes: svn path=/head/; revision=365710
* kern: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-1/+1
| | | | Notes: svn path=/head/; revision=365222
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)Pawel Biernacki2020-02-261-1/+2
| | | | | | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Mark all obvious cases as MPSAFE. All entries that haven't been marked as MPSAFE before are by default marked as NEEDGIANT Approved by: kib (mentor, blanket) Commented by: kib, gallatin, melifaro Differential Revision: https://reviews.freebsd.org/D23718 Notes: svn path=/head/; revision=358333
* proc: eliminate the zombproc listMateusz Guzik2019-08-281-8/+2
| | | | | | | | | | | | It is not needed by anything in the kernel and it slightly drives up contention on both proctree and allproc locks. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D21447 Notes: svn path=/head/; revision=351572
* racct: add RACCT_ENABLED macro and racct_set_unlockedMateusz Guzik2018-12-071-0/+12
| | | | | | | | | | This allows to remove PROC_LOCK/UNLOCK pairs spread thorought the kernel only used to appease racct_set. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341701
* Convert racct_enable to bool and annotate as __read_frequentlyMateusz Guzik2018-11-291-3/+3
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341182
* Deinline racct throttling out of syscall exit path.Mateusz Guzik2018-11-291-0/+16
| | | | | | | | | | | | racct is not enabled by default and even when it is enabled processes are typically not throttled. The order of checks is left unchanged since racct_enable will be annotated as __read_frequently, while checking for the flag in the processes would probably require an extra fetch. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341181
* proc: create a dedicated lock for zombproc to ligthen the load on allproc_lockMateusz Guzik2018-11-291-0/+2
| | | | | | | | | | | | waitpid always takes proctree to evaluate the list, but only takes allproc if it can reap. With this patch allproc is no longer taken, which helps during poudriere -j 128. Discussed with: kib Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341176
* fork: remove avoidable proc lock/unlock pairMateusz Guzik2018-11-221-2/+2
| | | | | | | | | | We don't have to access the process after making it runnable, so there is no need to hold it either. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=340785
* call racct_proc_ucred_changed() under the proc lockAndriy Gapon2018-04-201-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The lock is required to ensure that the switch to the new credentials and the transfer of the process's accounting data from the old credentials to the new ones is done atomically. Otherwise, some updates may be applied to the new credentials and then additionally transferred from the old credentials if the updates happen after proc_set_cred() and before racct_proc_ucred_changed(). The problem is especially pronounced for RACCT_RSS because - there is a strict accounting for this resource (it's reclaimable) - it's updated asynchronously by the vm daemon - it's updated by setting an absolute value instead of applying a delta I had to remove a call to rctl_proc_ucred_changed() from racct_proc_ucred_changed() and make all callers of latter call the former as well. The reason is that rctl_proc_ucred_changed, as it is implemented now, cannot be called while holding the proc lock, so the lock is dropped after calling racct_proc_ucred_changed. Additionally, I've added calls to crhold / crfree around the rctl call, because without the proc lock there is no gurantee that the new credentials, owned by the process, will stay stable. That does not eliminate a possibility that the credentials passed to the rctl will get stale. Ideally, rctl_proc_ucred_changed should be able to work under the proc lock. Many thanks to kib for pointing out the above problems. PR: 222027 Discussed with: kib No comment: trasz MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D15048 Notes: svn path=/head/; revision=332816
* sys/kern: adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326271
* try to fix RACCT_RSS accountingAndriy Gapon2017-02-141-1/+4
| | | | | | | | | | | | | | | | | | | | | There could be a race between the vm daemon setting RACCT_RSS based on the vm space and vmspace_exit (called from exit1) resetting RACCT_RSS to zero. In that case we can get a zombie process with non-zero RACCT_RSS. If the process is jailed, that may break accounting for the jail. There could be other consequences. Fix this race in the vm daemon by updating RACCT_RSS only when a process is in the normal state. Also, make accounting a little bit more accurate by refreshing the page resident count after calling vm_pageout_map_deactivate_pages(). Finally, add an assert that the RSS is zero when a process is reaped. PR: 210315 Reviewed by: trasz Differential Revision: https://reviews.freebsd.org/D9464 Notes: svn path=/head/; revision=313730
* Remove redundant KASSERT.Edward Tomasz Napierala2017-01-221-5/+1
| | | | Notes: svn path=/head/; revision=312623
* Get rid of rctl_lock; use racct_lock where appropriate. The fast pathsEdward Tomasz Napierala2016-04-211-27/+45
| | | | | | | | | | | | | already required both of them, so having a separate rctl_lock didn't buy us anything. Reviewed by: mjg@ MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D5914 Notes: svn path=/head/; revision=298414
* Allocate RACCT/RCTL zones without UMA_ZONE_NOFREE; no idea why it was thereEdward Tomasz Napierala2016-04-151-1/+1
| | | | | | | | | | in the first place. MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=298050
* Sort variable declarations.Edward Tomasz Napierala2016-04-151-8/+5
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=298045
* Add four new RCTL resources - readbps, readiops, writebps and writeiops,Edward Tomasz Napierala2016-04-071-11/+66
| | | | | | | | | | | | | | | | | | for limiting disk (actually filesystem) IO. Note that in some cases these limits are not quite precise. It's ok, as long as it's within some reasonable bounds. Testing - and review of the code, in particular the VFS and VM parts - is very welcome. MFC after: 1 month Relnotes: yes Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D5080 Notes: svn path=/head/; revision=297633
* Use proper locking macros in RACCT in RCTL.Edward Tomasz Napierala2016-04-051-37/+39
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297578
* Fix mismerge.Edward Tomasz Napierala2016-04-011-1/+1
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297495
* Drop the 'resource' argument to racct_decay(); it wouldn't make senseEdward Tomasz Napierala2016-04-011-13/+11
| | | | | | | | | | to iterate separately for each resource. MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297494
* Call rctl_enforce() in all cases the resource usage goes up, even when calledEdward Tomasz Napierala2016-04-011-8/+6
| | | | | | | | | | | from racct_*_force() functions. It makes the "log" and "devctl" actions work in those cases. MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297492
* Reorder the functions; no functional changes.Edward Tomasz Napierala2016-04-011-32/+32
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297491
* Reduce code duplication.Edward Tomasz Napierala2016-04-011-17/+13
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297490
* Reduce code duplication. There should be no (intended) functional changes.Edward Tomasz Napierala2016-04-011-64/+27
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297489
* Rename P_KTHREAD struct proc p_flag to P_KPROC.Konstantin Belousov2016-02-091-1/+1
| | | | | | | | | | | I left as is an apparent bug in ntoskrnl_var.h:AT_PASSIVE_LEVEL() definition. Suggested by: jhb Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=295435
* fork: plug a use after free of the returned processMateusz Guzik2016-02-041-2/+1
| | | | | | | | | | | | | | | | | fork1 required its callers to pass a pointer to struct proc * which would be set to the new process (if any). procdesc and racct manipulation also used said pointer. However, the process could have exited prior to do_fork return and be automatically reaped, thus making this a use-after-free. Fix the problem by letting callers indicate whether they want the pid or the struct proc, return the process in stopped state for the latter case. Reviewed by: kib Notes: svn path=/head/; revision=295233
* Fix style issues around existing SDT probes.Mark Johnston2015-12-161-33/+34
| | | | | | | | | | | | - Use SDT_PROBE<N>() instead of SDT_PROBE(). This has no functional effect at the moment, but will be needed for some future changes. - Don't hardcode the module component of the probe identifier. This is set automatically by the SDT framework. MFC after: 1 week Notes: svn path=/head/; revision=292384
* Tweak comments.Edward Tomasz Napierala2015-12-131-2/+2
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=292162
* Actually make the 'amount' argument to racct_adjust_resource() signed,Edward Tomasz Napierala2015-12-131-1/+1
| | | | | | | | | | as it was always supposed to be. MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=292161
* Avoid useless relocking.Edward Tomasz Napierala2015-12-131-1/+1
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=292160
* Speed up rctl operation with large rulesets, by holding the lockEdward Tomasz Napierala2015-11-151-4/+20
| | | | | | | | | | | | during iteration instead of relocking it for each traversed rule. Reviewed by: mjg@ MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D4110 Notes: svn path=/head/; revision=290857
* Fix a bug in the CPU % limiting codeJosh Paetzel2015-11-101-8/+8
| | | | | | | | | | | | | | | If you attempt to set a pcpu limit that is higher than 110% using rctl (for instance, you want a jail to be able to use 2 cores on your system so you set pcpu to 200%) the thing you are trying to limit becomes unthrottled. PR: 189870 Submitted by: dustinwenz@ebureau.com Reviewed by: trasz MFC after: 1 week Notes: svn path=/head/; revision=290662
* save some bytes by using more concise SDT_PROBE<n> instead of SDT_PROBEAndriy Gapon2015-09-281-15/+13
| | | | | | | | | | | | SDT_PROBE requires 5 parameters whereas SDT_PROBE<n> requires n parameters where n is typically smaller than 5. Perhaps SDT_PROBE should be made a private implementation detail. MFC after: 20 days Notes: svn path=/head/; revision=288336
* nit: Rename racct_alloc_resource to racct_adjust_resource.Jeremie Le Hen2015-06-141-12/+12
| | | | | | | | | This is more accurate as the amount can be negative. MFC after: 2 weeks Notes: svn path=/head/; revision=284378
* Build GENERIC with RACCT/RCTL support by default. Note that it stillEdward Tomasz Napierala2015-05-141-1/+1
| | | | | | | | | | | | | needs to be enabled by adding "kern.racct.enable=1" to /boot/loader.conf. Differential Revision: https://reviews.freebsd.org/D2407 Reviewed by: emaste@, wblock@ MFC after: 1 month Relnotes: yes Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=282901
* Add kern.racct.enable tunable and RACCT_DISABLED config option.Edward Tomasz Napierala2015-04-291-1/+97
| | | | | | | | | | | | | | The point of this is to be able to add RACCT (with RACCT_DISABLED) to GENERIC, to avoid having to rebuild the kernel to use rctl(8). Differential Revision: https://reviews.freebsd.org/D2369 Reviewed by: kib@ MFC after: 1 month Relnotes: yes Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=282213
* The process spin lock currently has the following distinct uses:Konstantin Belousov2014-11-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Threads lifetime cycle, in particular, counting of the threads in the process, and interlocking with process mutex and thread lock. The main reason of this is that turnstile locks are after thread locks, so you e.g. cannot unlock blockable mutex (think process mutex) while owning thread lock. - Virtual and profiling itimers, since the timers activation is done from the clock interrupt context. Replace the p_slock by p_itimmtx and PROC_ITIMLOCK(). - Profiling code (profil(2)), for similar reason. Replace the p_slock by p_profmtx and PROC_PROFLOCK(). - Resource usage accounting. Need for the spinlock there is subtle, my understanding is that spinlock blocks context switching for the current thread, which prevents td_runtime and similar fields from changing (updates are done at the mi_switch()). Replace the p_slock by p_statmtx and PROC_STATLOCK(). The split is done mostly for code clarity, and should not affect scalability. Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=275121