kernel/cgroup/pids.c
Source file repositories/reference/linux-study-clean/kernel/cgroup/pids.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/cgroup/pids.c- Extension
.c- Size
- 11811 bytes
- Lines
- 461
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/threads.hlinux/atomic.hlinux/cgroup.hlinux/slab.hlinux/sched/task.h
Detected Declarations
struct pids_cgroupenum pidcg_eventfunction pids_css_allocfunction pids_css_freefunction pids_update_watermarkfunction pids_cancelfunction pids_unchargefunction pids_chargefunction pids_try_chargefunction pids_can_attachfunction cgroup_taskset_for_eachfunction pids_cancel_attachfunction cgroup_taskset_for_eachfunction pids_eventfunction task_css_checkfunction pids_cancel_forkfunction pids_releasefunction pids_max_writefunction pids_max_showfunction pids_current_readfunction pids_peak_readfunction __pids_events_showfunction pids_events_showfunction pids_events_local_show
Annotated Snippet
* on cgroup_threadgroup_change_begin() held by the copy_process().
*/
static int pids_can_fork(struct task_struct *task, struct css_set *cset)
{
struct pids_cgroup *pids, *pids_over_limit;
int err;
pids = css_pids(cset->subsys[pids_cgrp_id]);
err = pids_try_charge(pids, 1, &pids_over_limit);
if (err)
pids_event(pids, pids_over_limit);
return err;
}
static void pids_cancel_fork(struct task_struct *task, struct css_set *cset)
{
struct pids_cgroup *pids;
pids = css_pids(cset->subsys[pids_cgrp_id]);
pids_uncharge(pids, 1);
}
static void pids_release(struct task_struct *task)
{
struct pids_cgroup *pids = css_pids(task_css(task, pids_cgrp_id));
pids_uncharge(pids, 1);
}
static ssize_t pids_max_write(struct kernfs_open_file *of, char *buf,
size_t nbytes, loff_t off)
{
struct cgroup_subsys_state *css = of_css(of);
struct pids_cgroup *pids = css_pids(css);
int64_t limit;
int err;
buf = strstrip(buf);
if (!strcmp(buf, PIDS_MAX_STR)) {
limit = PIDS_MAX;
goto set_limit;
}
err = kstrtoll(buf, 0, &limit);
if (err)
return err;
if (limit < 0 || limit >= PIDS_MAX)
return -EINVAL;
set_limit:
/*
* Limit updates don't need to be mutex'd, since it isn't
* critical that any racing fork()s follow the new limit.
*/
atomic64_set(&pids->limit, limit);
return nbytes;
}
static int pids_max_show(struct seq_file *sf, void *v)
{
struct cgroup_subsys_state *css = seq_css(sf);
struct pids_cgroup *pids = css_pids(css);
int64_t limit = atomic64_read(&pids->limit);
if (limit >= PIDS_MAX)
seq_printf(sf, "%s\n", PIDS_MAX_STR);
else
seq_printf(sf, "%lld\n", limit);
return 0;
}
static s64 pids_current_read(struct cgroup_subsys_state *css,
struct cftype *cft)
{
struct pids_cgroup *pids = css_pids(css);
return atomic64_read(&pids->counter);
}
static s64 pids_peak_read(struct cgroup_subsys_state *css,
struct cftype *cft)
{
struct pids_cgroup *pids = css_pids(css);
return READ_ONCE(pids->watermark);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/threads.h`, `linux/atomic.h`, `linux/cgroup.h`, `linux/slab.h`, `linux/sched/task.h`.
- Detected declarations: `struct pids_cgroup`, `enum pidcg_event`, `function pids_css_alloc`, `function pids_css_free`, `function pids_update_watermark`, `function pids_cancel`, `function pids_uncharge`, `function pids_charge`, `function pids_try_charge`, `function pids_can_attach`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.