History log of /freebsd-current/sys/kern/kern_rctl.c
Revision Date Author Comments
# 6bb132ba 15-Apr-2024 Brooks Davis <brooks@FreeBSD.org>

Reduce reliance on sys/sysproto.h pollution

Add sys/errno.h, sys/malloc.h, sys/queue.h, and vm/uma.h as needed.

sys/sysproto.h currently includes sys/acl.h which currently includes
sys/param.h, sys/queue.h, and vm/uma.h which in turn bring in
sys/errno.h sys/malloc.h.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D44465


# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 0a713948 22-Nov-2023 Alexander Motin <mav@FreeBSD.org>

Replace random sbuf_printf() with cheaper cat/putc.


# e0205aa3 19-Oct-2023 Olivier Certner <olce.freebsd@certner.fr>

kern_rctl.c: Minimal includes when RCTL not defined

If RCTL is not defined, only the system call stubs returning ENOSYS are
compiled in. In this case, don't waste time including most headers
since their code is not used.

Reviewed by: markj
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 95ee2897 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: two-line .h pattern

Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

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


# 31d1b816 28-May-2022 Dmitry Chagin <dchagin@FreeBSD.org>

sysent: Get rid of bogus sys/sysent.h include.

Where appropriate hide sysent.h under proper condition.

MFC after: 2 weeks


# e8a5a1ad 30-Dec-2020 Jason A. Harmening <jah@FreeBSD.org>

rctl(4): support throttling resource usage to 0

For rate-based resources that support throttling (e.g.
readiops/writeips), this fixes a divide-by-zero panic when rctl(8)
passes 0 as the throttle value. For these resources, treat
zero-throttle requests as requests to suspend forward progress as long
as possible using the duration specified in
kern.racct.rctl.throttle_max.

PR: 251803
Reported by: chris@cretaforce.gr
Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D27858


# bce7ee9d 28-Oct-2020 Edward Tomasz Napierala <trasz@FreeBSD.org>

Drop "All rights reserved" from all my stuff. This includes
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


# 6fed89b1 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

kern: clean up empty lines in .c and .h files


# 887611b1 28-Aug-2020 Warner Losh <imp@FreeBSD.org>

Retire devctl_notify_f()

devctl_notify_f isn't needed, so retire it. The flags argument is now
unused, so rather than keep it around, retire it. Convert all old
users of it to devctl_notify(). This path no longer sleeps, so is safe
to call from any context. Since it doesn't sleep, it doesn't need to
know if it is OK to sleep or not.

Reviewed by: markj@
Differential Revision: https://reviews.freebsd.org/D26140


# 773e541e 20-Aug-2020 Warner Losh <imp@FreeBSD.org>

Use devctl.h instead of bus.h to reduce newbus pollution.

There's no need for these parts of the kernel to know about newbus,
so narrow what is included to devctl.h for device_notify_*.

Suggested by: kib@


# e0d69c5a 15-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (1 of many)

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.

Reviewed by: kib, trasz
Approved by: kib (mentor)
Differential Revision: https://reviews.freebsd.org/D23640


# f87beb93 20-Apr-2018 Andriy Gapon <avg@FreeBSD.org>

call racct_proc_ucred_changed() under the proc lock

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


# 8a36da99 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/kern: adoption of SPDX licensing ID tags.

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.


# e3043798 29-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/kern: spelling fixes in comments.

No functional change.


# bbe4eb6d 21-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Get rid of rctl_lock; use racct_lock where appropriate. The fast paths
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


# b483e111 19-Apr-2016 Conrad Meyer <cem@FreeBSD.org>

kern_rctl: Fix resource leak in error path

Ordinarily, rctl_write_outbuf frees 'sb'. However, if we are in low memory
conditions we skip past the rctl_write_outbuf. In that case, free 'sb'.

Reported by: Coverity
CID: 1338539
Sponsored by: EMC / Isilon Storage Division


# 74a7305a 19-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix debugging printf.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 23e6fff2 15-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Allocate RACCT/RCTL zones without UMA_ZONE_NOFREE; no idea why it was there
in the first place.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# c1a43e73 15-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Sort variable declarations.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# f459a818 12-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix overflow checking.

There are some other potential problems related to overflowing racct
counters; I'll revisit those later.

Submitted by: Pieter de Goeje (earlier version)
Reviewed by: emaste@
MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 8bd8c8f1 08-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make it possible to tweak RCTL throttling sysctls at runtime.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# ae34b6ff 06-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add four new RCTL resources - readbps, readiops, writebps and writeiops,
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


# 4c230cda 05-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Use proper locking macros in RACCT in RCTL.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# f70c075e 02-Apr-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add configurable rate limit for "log" and "devctl" actions.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# ac3c9819 31-Mar-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Refactor; no functional changes.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# b450d447 31-Mar-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix overflows, making it impossible to add negative amounts using rctl(8).

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# ed810200 26-Jan-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix the way RCTL handles rules' rrl_exceeded on credenials change.
Because of what this variable does, it was probably harmless - but
still incorrect.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# af1a7b25 13-Dec-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Tweak comments.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 15db3c07 14-Nov-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Speed up rctl operation with large rulesets, by holding the lock
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


# ea228b48 08-Nov-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make naming more consistent; no functional changes.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 2b4035ee 08-Nov-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Speed up rctl(8) rule retrieval; the difference shows mostly in "rctl -n",
as otherwise most of the time is spent resolving UIDs to names.

Reviewed by: mjg@
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D4059


# 4b5c9cf6 29-Apr-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add kern.racct.enable tunable and RACCT_DISABLED config option.
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


# 36af9869 26-Oct-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add CPU percentage limit enforcement to RCTL. The resouce name is "pcpu".
It was implemented by Rudolf Tomori during Google Summer of Code 2012.


# 0b18eb6d 17-Apr-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Stop treating system processes as special. This fixes panics
like the one triggered by this:

# kldload geom_vinum
# pwait `pgrep -S gv_worker` &
# kldunload geom_vinum

or this:

GEOM_JOURNAL: Shutting down geom gjournal 3464572051.
panic: destroying non-empty racct: 1 allocated for resource 6

which were tracked by jh@ to be caused by checking p->p_flag,
while it wasn't initialised yet. Basically, during fork, the code
checked p_flag, concluded the process isn't marked as P_SYSTEM,
incremented the counter, and later on, when exiting, checked that
the process was marked as P_SYSTEM, and thus didn't decrement it.

Also, I believe there wasn't any good reason for checking P_SYSTEM
in the first place.

Tested by: jh


# 786813aa 17-Apr-2012 Edward Tomasz Napierala <trasz@FreeBSD.org>

Enforce upper bound on the input buffer length.

Reported by: Mateusz Guzik


# d745c852 06-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs.

This means that their use is restricted to a single C file.


# 72a401d9 03-Oct-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix another bug introduced in r225641, which caused rctl to access certain
fields in 'struct proc' before they got initialized in do_fork().

MFC after: 3 days


# 8451d0dd 16-Sep-2011 Kip Macy <kmacy@FreeBSD.org>

In order to maximize the re-usability of kernel code in user space this
patch modifies makesyscalls.sh to prefix all of the non-compatibility
calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel
entry points and all places in the code that use them. It also
fixes an additional name space collision between the kernel function
psignal and the libc function of the same name by renaming the kernel
psignal kern_psignal(). By introducing this change now we will ease future
MFCs that change syscalls.

Reviewed by: rwatson
Approved by: re (bz)


# ba1b2069 07-Sep-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix whitespace.

Submitted by: amdmi3
Approved by: re (rwatson)


# 3044751e 06-Sep-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Work around a kernel panic triggered by forkbomb with an rctl rule
such as j:name:maxproc:sigkill=100. Proper fix - deferring psignal
to a taskqueue - is somewhat complicated and thus will happen
after 9.0.

Approved by: re (kib)


# cff08ec0 03-Sep-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Since r224036 the cputime and wallclock are supposed to be in seconds,
not microseconds. Make it so.

Approved by: re (kib)


# 85a2f1b4 14-Jul-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Rename resource names to match these in login.conf.


# 4fe84775 07-Jul-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Style fix - macros are supposed to be uppercase.


# 7e2548ae 27-May-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Remove definitions for RACCT_FSIZE and RACCT_SBSIZE - these two are rather
performance-sensitive and not that useful, so I won't be merging them
before 9.0.


# a7ad07bf 03-May-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Change the way rctl interfaces with jails by introducing prison_racct
structure, which acts as a proxy between them. This makes jail rules
persistent, i.e. they can be added before jail gets created, and they
don't disappear when the jail gets destroyed.


# 415896e3 10-Apr-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Rename a misnamed structure field (hr_loginclass), and reorder priv(9)
constants to match the order and naming of syscalls. No functional changes.


# ec125fbb 30-Mar-2011 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add rctl. It's used by racct to take user-configurable actions based
on the set of rules it maintains and the current resource usage. It also
privides userland API to manage that ruleset.

Sponsored by: The FreeBSD Foundation
Reviewed by: kib (earlier version)