summaryrefslogtreecommitdiff
path: root/sys/kern/kern_resource.c
Commit message (Collapse)AuthorAgeFilesLines
* thread: batch resource limit free callsMateusz Guzik2020-11-141-0/+8
| | | | Notes: svn path=/head/; revision=367694
* Allow rtprio_thread to operate on threads of any processMateusz Guzik2020-11-101-2/+1
| | | | | | | | | | | | | | | | | | | | | | | This in particular unbreaks rtkit. The limitation was a leftover of previous state, to quote a comment: /* * Though lwpid is unique, only current process is supported * since there is no efficient way to look up a LWP yet. */ Long since then a global tid hash was introduced to remedy the problem. Permission checks still apply. Submitted by: greg_unrelenting.technology (Greg V) Differential Revision: https://reviews.freebsd.org/D27158 Notes: svn path=/head/; revision=367572
* kern: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-2/+0
| | | | Notes: svn path=/head/; revision=365222
* Remove duplicated empty lines from kern/*.cMateusz Guzik2020-01-301-1/+0
| | | | | | | No functional changes. Notes: svn path=/head/; revision=357312
* dd kern_getpriority(), make Linuxulator use it.Edward Tomasz Napierala2020-01-121-8/+15
| | | | | | | | | | Reviewed by: kib, emaste MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D22842 Notes: svn path=/head/; revision=356659
* Add kern_setpriority(), use it in Linuxulator.Edward Tomasz Napierala2020-01-121-12/+19
| | | | | | | | | | Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D22841 Notes: svn path=/head/; revision=356658
* schedlock 1/4Jeff Roberson2019-12-151-9/+16
| | | | | | | | | | | | | | | Eliminate recursion from most thread_lock consumers. Return from sched_add() without the thread_lock held. This eliminates unnecessary atomics and lock word loads as well as reducing the hold time for scheduler locks. This will eventually allow for lockless remote adds. Discussed with: kib Reviewed by: jhb Tested by: pho Differential Revision: https://reviews.freebsd.org/D22626 Notes: svn path=/head/; revision=355779
* Fix a typo introduced in r344133Andrew Gallatin2019-03-181-1/+1
| | | | | | | | | | | | | | | The line was misedited to change tt to st instead of changing ut to st. The use of st as the denominator in mul64_by_fraction() will lead to an integer divide fault in the intr proc (the process holding ithreads) where st will be 0. This divide by 0 happens after the total runtime for all ithreads exceeds 76 hours. Submitted by: bde Notes: svn path=/head/; revision=345273
* Finish the fix for overflow in calcru1().Bruce Evans2019-02-141-6/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous fix was unnecessarily very slow up to 105 hours where the simple formula used previously worked, and unnecessarily slow by a factor of about 5/3 up to 388 days, and didn't work above 388 days. 388 days is not a long time, since it is a reasonable uptime, and for processes the times being calculated are aggregated over all threads, so with N CPUs running the same thread a runtime of 388 days is reachable after only 388 / N physical days. The PRs document overflow at 388 days, but don't try to fix it. Use the simple formula up to 76 hours. Then use a complicated general method that reduces to the simple formula up to a bit less than 105 hours, then reduces to the previous method without its extra work up to almost 388 days, then does more complicated reductions, usually many bits at a time so that this is not slow. This works up to half of maximum representable time (292271 years), with accumulated rounding errors of at most 32 usec. amd64 can do all this with no avoidable rounding errors in an inline asm with 2 instructions, but this is too special to use. __uint128_t can do the same with 100's of instructions on 64-bit arches. Long doubles with at least 64 bits of precision are the easiest method to use on i386 userland, but are hard to use in the kernel. PR: 76972 and duplicates Reviewed by: kib Notes: svn path=/head/; revision=344133
* Prevent overflow for usertime/systime in caclru1Conrad Meyer2019-02-101-4/+13
| | | | | | | | | | | PR: 76972 and duplicates Reported by: Dr. Christopher Landauer <cal AT aero.org>, Steinar Haug <sthaug AT nethelp.no> Submitted by: Andrey Zonov <andrey AT zonov.org> (earlier version) MFC after: 2 weeks Notes: svn path=/head/; revision=343985
* Make lim_cur inline if possible.Mateusz Guzik2018-12-111-1/+1
| | | | | | | | | | | | | It is a function call only to accomodate *some* ABIs which install a hook. They only care for 3 types of limits: DATA, STACK, VMEM Instead of always calling the func, see at compilation time if the requested limit is something else and just do the read if so. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341818
* Replace hand-rolled unrefs if > 1 with refcount_release_if_not_lastMateusz Guzik2018-12-071-5/+1
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341698
* eliminate locking surrounding ui_vmsize and swap reserve by using atomicsMatt Macy2018-10-051-3/+0
| | | | | | | | | | | | | | | | Change swap_reserve and swap_total to be in units of pages so that swap reservations can be done using only atomics instead of using a single global mutex for swap_reserve and a single mutex for all processes running under the same uid for uid accounting. Results in mmap speed up and a 70% increase in brk calls / second. Reviewed by: alc@, markj@, kib@ Approved by: re (delphij@) Differential Revision: https://reviews.freebsd.org/D16273 Notes: svn path=/head/; revision=339187
* Move most of the contents of opt_compat.h to opt_global.h.Brooks Davis2018-04-061-2/+0
| | | | | | | | | | | | | | | | | | | | | opt_compat.h is mentioned in nearly 180 files. In-progress network driver compabibility improvements may add over 100 more so this is closer to "just about everywhere" than "only some files" per the guidance in sys/conf/options. Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of sys/compat/linux/*.c. A fake _COMPAT_LINUX option ensure opt_compat.h is created on all architectures. Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the set of compiled files. Reviewed by: kib, cem, jhb, jtl Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14941 Notes: svn path=/head/; revision=332122
* Always use atomic_fetchadd() when updating per-user accounting values.John Baldwin2018-01-041-6/+5
| | | | | | | | | | | | This avoids re-reading a variable after it has been updated via an atomic op. It is just a cosmetic cleanup as the read value was only used to control a diagnostic printf that should rarely occur (if ever). Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D13768 Notes: svn path=/head/; revision=327562
* sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. 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. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326023
* Save on uihash table locking by checking if the caller already uses the structMateusz Guzik2017-11-011-0/+12
| | | | | | | In particular with poudriere this saves about 90% of lookups. Notes: svn path=/head/; revision=325263
* Remove register keyword from sys/ and ANSIfy prototypesEd Maste2017-05-171-8/+8
| | | | | | | | | | | | | | | A long long time ago the register keyword told the compiler to store the corresponding variable in a CPU register, but it is not relevant for any compiler used in the FreeBSD world today. ANSIfy related prototypes while here. Reviewed by: cem, jhb Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D10193 Notes: svn path=/head/; revision=318389
* Renumber license clauses in sys/kern to avoid skipping #3Ed Maste2016-09-151-1/+1
| | | | Notes: svn path=/head/; revision=305832
* Implement process-shared locks support for libthr.so.3, withoutKonstantin Belousov2016-02-281-0/+7
| | | | | | | | | | | | | | | breaking the ABI. Special value is stored in the lock pointer to indicate shared lock, and offline page in the shared memory is allocated to store the actual lock. Reviewed by: vangyzen (previous version) Discussed with: deischen, emaste, jhb, rwatson, Martin Simmons <martin@lispworks.com> Tested by: pho Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=296162
* Fold lim_shared into lim_copy to mute a -Wunused compiler warning fromEnji Cooper2015-12-221-10/+1
| | | | | | | | | | | | clang when the kernel is compiled without INVARIANTS Differential Revision: https://reviews.freebsd.org/D4683 Reviewed by: kib, jhb MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=292626
* Speed up rctl operation with large rulesets, by holding the lockEdward Tomasz Napierala2015-11-151-1/+6
| | | | | | | | | | | | 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
* Get rid of lim_update_thread and cred_update_thread.Mateusz Guzik2015-07-161-14/+0
| | | | | | | | | Their primary use was in thread_cow_update to free up old resources. Freeing had to be done with proc lock held and _cow_ funcs already knew how to free old structs. Notes: svn path=/head/; revision=285633
* rlimit: deduplicate code in chg* functionsMateusz Guzik2015-06-251-46/+27
| | | | Notes: svn path=/head/; revision=284783
* Implement lockless resource limits.Mateusz Guzik2015-06-101-32/+60
| | | | | | | | | | | | | Use the same scheme implemented to manage credentials. Code needing to look at process's credentials (as opposed to thred's) is provided with *_proc variants of relevant functions. Places which possibly had to take the proc lock anyway still use the proc pointer to access limits. Notes: svn path=/head/; revision=284215
* Implement support for binary to requesting specific stack size for theKonstantin Belousov2015-04-151-1/+6
| | | | | | | | | | | | | | | initial thread. It is read by the ELF image activator as the virtual size of the PT_GNU_STACK program header entry, and can be specified by the linker option -z stack-size in newer binutils. The soft RLIMIT_STACK is auto-increased if possible, to satisfy the binary' request. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=281548
* The process spin lock currently has the following distinct uses:Konstantin Belousov2014-11-261-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* ifdef RACCT ui_racct_foreach and struct uidinfo's ui_racctMateusz Guzik2014-11-231-0/+2
| | | | | | | | Change racct_ create and destroy to macros evaluating to nothing without RACCT so that their callers passing ui_racct don't have to be ifdefed. Notes: svn path=/head/; revision=274911
* Tidy up functions related to uidinfo management.Mateusz Guzik2014-10-271-45/+47
| | | | | | | | - reference found uidinfo in uilookup - reduce nesting by handling shorter cases first Notes: svn path=/head/; revision=273746
* De-k&r-ify function definitions in kern/kern_resource.cMateusz Guzik2014-10-271-57/+20
| | | | | | | No functional changes. Notes: svn path=/head/; revision=273745
* rlimit: plug duplicate assertionMateusz Guzik2014-10-251-1/+0
| | | | | | | counter sanity is already checked by refcount_release. Notes: svn path=/head/; revision=273629
* rlimit: avoid unnecessary copying of rlimitsMateusz Guzik2013-12-131-6/+16
| | | | | | | | | If refcount is 1 just modify rlimits in place. MFC after: 2 weeks Notes: svn path=/head/; revision=259331
* rlimit: add and utilize lim_sharedMateusz Guzik2013-12-131-1/+11
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=259330
* Add a resource limit for the total number of kqueues available to theKonstantin Belousov2013-10-211-0/+18
| | | | | | | | | | | | | | | | | | | | | user. Kqueue now saves the ucred of the allocating thread, to correctly decrement the counter on close. Under some specific and not real-world use scenario for kqueue, it is possible for the kqueues to consume memory proportional to the square of the number of the filedescriptors available to the process. Limit allows administrator to prevent the abuse. This is kernel-mode side of the change, with the user-mode enabling commit following. Reported and tested by: pho Discussed with: jmg Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=256849
* Call sched_prio() to immediately change the priority of the thread inIan Lepore2013-03-071-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | response to an rtprio_thread() call, when the priority is different than the old priority, and either the old or the new priority class is not RTP_PRIO_NORMAL (timeshare). The reasoning for the second half of the test is that if it's a change in timeshare priority, then the scheduler is going to adjust that priority in a way that completely wipes out the requested change anyway, so what's the point? (If that's not true, then allowing a thread to change its own timeshare priority would subvert the scheduler's adjustments and let a cpu-bound thread monopolize the cpu; if allowed at all, that should require priveleges.) On the other hand, if either the old or new priority class is not timeshare, then the scheduler doesn't make automatic adjustments, so we should honor the request and make the priority change right away. The reason the old class gets caught up in this is the very reason for this change: when thread A changes the priority of its child thread B from idle back to timeshare, thread B never actually gets moved to a timeshare-range run queue unless there are some idle cycles available to allow it to first get scheduled again as an idle thread. Reviewed by: jhb@ Notes: svn path=/head/; revision=247905
* MFcalloutng (r244251 with minor changes):Davide Italiano2013-03-041-3/+6
| | | | | | | | | | Specify that precision of 0.5s is enough for resource limitation. Sponsored by: Google Summer of Code 2012, iXsystems inc. Tested by: flo, marius, ian, markj, Fabian Keil Notes: svn path=/head/; revision=247800
* Change kern.proc.rlimit sysctl to:Mikolaj Golub2012-01-221-6/+9
| | | | | | | | | | | | | | | | - retrive only one, specified limit for a process, not the whole array, as it was previously (the sysctl has been added recently and has not been backported to stable yet, so this change is ok); - allow to set a resource limit for another process. Submitted by: Andrey Zonov <andrey at zonov.org> Discussed with: kib Reviewed by: kib MFC after: 2 weeks Notes: svn path=/head/; revision=230470
* Fix a logic bug in change 228207 in the check for a thread's new userJohn Baldwin2012-01-051-1/+1
| | | | | | | | | priority being a realtime priority. MFC after: 3 days Notes: svn path=/head/; revision=229622
* - Add a sysctl to allow non-root users the ability to set idleEitan Adler2011-12-131-25/+33
| | | | | | | | | | | | | | | priorities. - While here fix up some style nits. Discussed with: cperciva (breifly) Reviewed by: pjd (earlier version) Reviewed by: bde Approved by: jhb MFC after: 1 month Notes: svn path=/head/; revision=228470
* When changing the user priority of a thread, change the real priorityJohn Baldwin2011-12-021-2/+3
| | | | | | | | | | | | in addition to the user priority for threads whose current real priority is equal to the previous user priority or if the new priority is a real-time priority. This allows priority changes of other threads to have an immediate effect. MFC after: 2 weeks Notes: svn path=/head/; revision=228207
* In lim_fork() assert that processes locks are held.Mikolaj Golub2011-11-071-0/+4
| | | | | | | Suggested by: kib Notes: svn path=/head/; revision=227315
* In order to maximize the re-usability of kernel code in user space thisKip Macy2011-09-161-8/+8
| | | | | | | | | | | | | | | | 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) Notes: svn path=/head/; revision=225617
* - Export each thread's individual resource usage in in struct kinfo_proc'sJohn Baldwin2011-07-181-6/+34
| | | | | | | | | | | | | | | ki_rusage member when KERN_PROC_INC_THREAD is passed to one of the process sysctls. - Correctly account for the current thread's cputime in the thread when doing the runtime fixup in calcru(). - Use TIDs as the key to lookup the previous thread to compute IO stat deltas in IO mode in top when thread display is enabled. Reviewed by: kib Approved by: re (kib) Notes: svn path=/head/; revision=224188
* Fix several places to ignore processes that are not yet fully constructed.John Baldwin2011-04-061-3/+6
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=220390
* Add racct. It's an API to keep per-process, per-jail, per-loginclassEdward Tomasz Napierala2011-03-291-0/+20
| | | | | | | | | | | | and per-loginclass resource accounting information, to be used by the new resource limits code. It's connected to the build, but the code that actually calls the new functions will come later. Sponsored by: The FreeBSD Foundation Reviewed by: kib (earlier version) Notes: svn path=/head/; revision=220137
* Fix some locking nits with the p_state field of struct proc:John Baldwin2011-03-241-4/+2
| | | | | | | | | | | | | | | | | | | | | - Hold the proc lock while changing the state from PRS_NEW to PRS_NORMAL in fork to honor the locking requirements. While here, expand the scope of the PROC_LOCK() on the new process (p2) to avoid some LORs. Previously the code was locking the new child process (p2) after it had locked the parent process (p1). However, when locking two processes, the safe order is to lock the child first, then the parent. - Fix various places that were checking p_state against PRS_NEW without having the process locked to use PROC_LOCK(). Every place was already locking the process, just after the PRS_NEW check. - Remove or reduce the use of PROC_SLOCK() for places that were checking p_state against PRS_NEW. The PROC_LOCK() alone is sufficient for reading the current state. - Reorder fill_kinfo_proc() slightly so it only acquires PROC_SLOCK() once. MFC after: 1 week Notes: svn path=/head/; revision=219968
* - Follow r216313, the sched_unlend_user_prio is no longer needed, alwaysDavid Xu2010-12-291-0/+2
| | | | | | | | | | use sched_lend_user_prio to set lent priority. - Improve pthread priority-inherit mutex, when a contender's priority is lowered, repropagete priorities, this may cause mutex owner's priority to be lowerd, in old code, mutex owner's priority is rise-only. Notes: svn path=/head/; revision=216791
* Add back a bounds check on valid idle priorities that was lost in anJohn Baldwin2010-12-171-8/+6
| | | | | | | | | | | | earlier commit. While here, move the thread lock down in rtp_to_pri(). It is not needed for all of the priority value checks and the computation of newpri. Reported by: swell.k @ gmail MFC after: 3 days Notes: svn path=/head/; revision=216504
* We've already set p = td->td_proc, so use it.Ed Maste2010-10-181-4/+4
| | | | Notes: svn path=/head/; revision=214025
* Create a global thread hash table to speed up thread lookup, useDavid Xu2010-10-091-23/+13
| | | | | | | | | | | | | rwlock to protect the table. In old code, thread lookup is done with process lock held, to find a thread, kernel has to iterate through process and thread list, this is quite inefficient. With this change, test shows in extreme case performance is dramatically improved. Earlier patch was reviewed by: jhb, julian Notes: svn path=/head/; revision=213642