kernel/cgroup/misc.c
Source file repositories/reference/linux-study-clean/kernel/cgroup/misc.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/cgroup/misc.c- Extension
.c- Size
- 11092 bytes
- Lines
- 479
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/limits.hlinux/cgroup.hlinux/errno.hlinux/atomic.hlinux/slab.hlinux/misc_cgroup.h
Detected Declarations
function parent_miscfunction valid_typefunction misc_cg_set_capacityfunction misc_cg_cancel_chargefunction misc_cg_update_watermarkfunction misc_cg_eventfunction misc_cg_try_chargefunction misc_cg_unchargefunction misc_cg_max_showfunction misc_cg_max_writefunction misc_cg_current_showfunction misc_cg_peak_showfunction misc_cg_capacity_showfunction __misc_events_showfunction misc_events_showfunction misc_events_local_showfunction misc_cg_allocfunction misc_cg_freeexport misc_cg_set_capacityexport misc_cg_try_chargeexport misc_cg_uncharge
Annotated Snippet
if (READ_ONCE(misc_res_capacity[i])) {
max = READ_ONCE(cg->res[i].max);
if (max == MAX_NUM)
seq_printf(sf, "%s max\n", misc_res_name[i]);
else
seq_printf(sf, "%s %llu\n", misc_res_name[i],
max);
}
}
return 0;
}
/**
* misc_cg_max_write() - Update the maximum limit of the cgroup.
* @of: Handler for the file.
* @buf: Data from the user. It should be either "max", 0, or a positive
* integer.
* @nbytes: Number of bytes of the data.
* @off: Offset in the file.
*
* User can pass data like:
* echo sev 23 > misc.max, OR
* echo sev max > misc.max
*
* Context: Any context.
* Return:
* * >= 0 - Number of bytes processed in the input.
* * -EINVAL - If buf is not valid.
* * -ERANGE - If number is bigger than the u64 capacity.
*/
static ssize_t misc_cg_max_write(struct kernfs_open_file *of, char *buf,
size_t nbytes, loff_t off)
{
struct misc_cg *cg;
u64 max;
int ret = 0, i;
enum misc_res_type type = MISC_CG_RES_TYPES;
char *token;
buf = strstrip(buf);
token = strsep(&buf, " ");
if (!token || !buf)
return -EINVAL;
for (i = 0; i < MISC_CG_RES_TYPES; i++) {
if (!strcmp(misc_res_name[i], token)) {
type = i;
break;
}
}
if (type == MISC_CG_RES_TYPES)
return -EINVAL;
if (!strcmp(MAX_STR, buf)) {
max = MAX_NUM;
} else {
ret = kstrtou64(buf, 0, &max);
if (ret)
return ret;
}
cg = css_misc(of_css(of));
if (READ_ONCE(misc_res_capacity[type]))
WRITE_ONCE(cg->res[type].max, max);
else
ret = -EINVAL;
return ret ? ret : nbytes;
}
/**
* misc_cg_current_show() - Show the current usage of the misc cgroup.
* @sf: Interface file
* @v: Arguments passed
*
* Context: Any context.
* Return: 0 to denote successful print.
*/
static int misc_cg_current_show(struct seq_file *sf, void *v)
{
int i;
u64 usage;
struct misc_cg *cg = css_misc(seq_css(sf));
for (i = 0; i < MISC_CG_RES_TYPES; i++) {
usage = atomic64_read(&cg->res[i].usage);
Annotation
- Immediate include surface: `linux/limits.h`, `linux/cgroup.h`, `linux/errno.h`, `linux/atomic.h`, `linux/slab.h`, `linux/misc_cgroup.h`.
- Detected declarations: `function parent_misc`, `function valid_type`, `function misc_cg_set_capacity`, `function misc_cg_cancel_charge`, `function misc_cg_update_watermark`, `function misc_cg_event`, `function misc_cg_try_charge`, `function misc_cg_uncharge`, `function misc_cg_max_show`, `function misc_cg_max_write`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.