Lines Matching +full:current +full:- +full:limit

1 // SPDX-License-Identifier: GPL-2.0-only
6 * after a certain limit is reached.
8 * Since it is trivial to hit the task limit without hitting any kmemcg limits
15 * number of processes currently in the cgroup is given by pids.current.
17 * possible to have pids.current > pids.max. However, it is not possible to
18 * violate a cgroup policy through fork(). fork() will return -EAGAIN if forking
21 * To set a cgroup to have no limit, set pids.max to "max". This is the default
23 * stringent limit in the hierarchy is followed).
25 * pids.current tracks all child cgroup hierarchies, so parent/pids.current is
26 * a superset of parent/child/pids.current.
45 * Use 64-bit types so that we can safely represent "max" as
49 atomic64_t limit; member
54 /* Number of times fork failed because limit was hit. */
65 return css_pids(pids->css.parent); in parent_pids()
75 return ERR_PTR(-ENOMEM); in pids_css_alloc()
77 atomic64_set(&pids->counter, 0); in pids_css_alloc()
78 atomic64_set(&pids->limit, PIDS_MAX); in pids_css_alloc()
79 atomic64_set(&pids->events_limit, 0); in pids_css_alloc()
80 return &pids->css; in pids_css_alloc()
89 * pids_cancel - uncharge the local pid count
102 WARN_ON_ONCE(atomic64_add_negative(-num, &pids->counter)); in pids_cancel()
106 * pids_uncharge - hierarchically uncharge the pid count
119 * pids_charge - hierarchically charge the pid count
123 * This function does *not* follow the pid limit set. It cannot fail and the new
124 * pid count may exceed the limit. This is only used for reverting failed
125 * attaches, where there is no other way out than violating the limit.
132 atomic64_add(num, &p->counter); in pids_charge()
136 * pids_try_charge - hierarchically try to charge the pid count
140 * This function follows the set limit. It will fail if the charge would cause
141 * the new value to exceed the hierarchical limit. Returns 0 if the charge
142 * succeeded, otherwise -EAGAIN.
149 int64_t new = atomic64_add_return(num, &p->counter); in pids_try_charge()
150 int64_t limit = atomic64_read(&p->limit); in pids_try_charge() local
154 * p->limit is %PIDS_MAX then we know that this test will never in pids_try_charge()
157 if (new > limit) in pids_try_charge()
168 return -EAGAIN; in pids_try_charge()
225 css = cset->subsys[pids_cgrp_id]; in pids_can_fork()
227 css = task_css_check(current, pids_cgrp_id, true); in pids_can_fork()
232 if (atomic64_inc_return(&pids->events_limit) == 1) { in pids_can_fork()
234 pr_cont_cgroup_path(css->cgroup); in pids_can_fork()
237 cgroup_file_notify(&pids->events_file); in pids_can_fork()
248 css = cset->subsys[pids_cgrp_id]; in pids_cancel_fork()
250 css = task_css_check(current, pids_cgrp_id, true); in pids_cancel_fork()
267 int64_t limit; in pids_max_write() local
272 limit = PIDS_MAX; in pids_max_write()
276 err = kstrtoll(buf, 0, &limit); in pids_max_write()
280 if (limit < 0 || limit >= PIDS_MAX) in pids_max_write()
281 return -EINVAL; in pids_max_write()
285 * Limit updates don't need to be mutex'd, since it isn't in pids_max_write()
286 * critical that any racing fork()s follow the new limit. in pids_max_write()
288 atomic64_set(&pids->limit, limit); in pids_max_write()
296 int64_t limit = atomic64_read(&pids->limit); in pids_max_show() local
298 if (limit >= PIDS_MAX) in pids_max_show()
301 seq_printf(sf, "%lld\n", limit); in pids_max_show()
311 return atomic64_read(&pids->counter); in pids_current_read()
318 seq_printf(sf, "max %lld\n", (s64)atomic64_read(&pids->events_limit)); in pids_events_show()
330 .name = "current",