kernel/acct.c
Source file repositories/reference/linux-study-clean/kernel/acct.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/acct.c- Extension
.c- Size
- 16946 bytes
- Lines
- 628
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/slab.hlinux/acct.hlinux/capability.hlinux/tty.hlinux/statfs.hlinux/jiffies.hlinux/syscalls.hlinux/namei.hlinux/sched/cputime.hasm/div64.hlinux/pid_namespace.hlinux/fs_pin.h
Detected Declarations
syscall acctstruct bsd_acct_structfunction kernel_acct_sysctls_initfunction check_free_spacefunction acct_putfunction acct_pin_killfunction close_workfunction acct_onfunction sys_acctfunction acct_exit_nsfunction encode_comp_tfunction comp2_tfunction encode_floatfunction acct_processfunction acct_write_processfunction do_acct_processfunction acct_collectfunction slow_acct_processfunction acct_process
Annotated Snippet
SYSCALL_DEFINE1(acct, const char __user *, name)
{
int error = 0;
if (!capable(CAP_SYS_PACCT))
return -EPERM;
if (name) {
mutex_lock(&acct_on_mutex);
error = acct_on(name);
mutex_unlock(&acct_on_mutex);
} else {
rcu_read_lock();
pin_kill(task_active_pid_ns(current)->bacct);
}
return error;
}
void acct_exit_ns(struct pid_namespace *ns)
{
rcu_read_lock();
pin_kill(ns->bacct);
}
/*
* encode an u64 into a comp_t
*
* This routine has been adopted from the encode_comp_t() function in
* the kern_acct.c file of the FreeBSD operating system. The encoding
* is a 13-bit fraction with a 3-bit (base 8) exponent.
*/
#define MANTSIZE 13 /* 13 bit mantissa. */
#define EXPSIZE 3 /* Base 8 (3 bit) exponent. */
#define MAXFRACT ((1 << MANTSIZE) - 1) /* Maximum fractional value. */
static comp_t encode_comp_t(u64 value)
{
int exp, rnd;
exp = rnd = 0;
while (value > MAXFRACT) {
rnd = value & (1 << (EXPSIZE - 1)); /* Round up? */
value >>= EXPSIZE; /* Base 8 exponent == 3 bit shift. */
exp++;
}
/*
* If we need to round up, do it (and handle overflow correctly).
*/
if (rnd && (++value > MAXFRACT)) {
value >>= EXPSIZE;
exp++;
}
if (exp > (((comp_t) ~0U) >> MANTSIZE))
return (comp_t) ~0U;
/*
* Clean it up and polish it off.
*/
exp <<= MANTSIZE; /* Shift the exponent into place */
exp += value; /* and add on the mantissa. */
return exp;
}
#if ACCT_VERSION == 1 || ACCT_VERSION == 2
/*
* encode an u64 into a comp2_t (24 bits)
*
* Format: 5 bit base 2 exponent, 20 bits mantissa.
* The leading bit of the mantissa is not stored, but implied for
* non-zero exponents.
* Largest encodable value is 50 bits.
*/
#define MANTSIZE2 20 /* 20 bit mantissa. */
#define EXPSIZE2 5 /* 5 bit base 2 exponent. */
#define MAXFRACT2 ((1ul << MANTSIZE2) - 1) /* Maximum fractional value. */
#define MAXEXP2 ((1 << EXPSIZE2) - 1) /* Maximum exponent. */
static comp2_t encode_comp2_t(u64 value)
{
int exp, rnd;
exp = (value > (MAXFRACT2>>1));
rnd = 0;
while (value > MAXFRACT2) {
rnd = value & 1;
value >>= 1;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/acct.h`, `linux/capability.h`, `linux/tty.h`, `linux/statfs.h`, `linux/jiffies.h`, `linux/syscalls.h`, `linux/namei.h`.
- Detected declarations: `syscall acct`, `struct bsd_acct_struct`, `function kernel_acct_sysctls_init`, `function check_free_space`, `function acct_put`, `function acct_pin_kill`, `function close_work`, `function acct_on`, `function sys_acct`, `function acct_exit_ns`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.