kernel/bpf/percpu_freelist.c
Source file repositories/reference/linux-study-clean/kernel/bpf/percpu_freelist.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/percpu_freelist.c- Extension
.c- Size
- 3125 bytes
- Lines
- 138
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
percpu_freelist.h
Detected Declarations
function pcpu_freelist_initfunction for_each_possible_cpufunction pcpu_freelist_destroyfunction pcpu_freelist_push_nodefunction ___pcpu_freelist_pushfunction __pcpu_freelist_pushfunction pcpu_freelist_pushfunction pcpu_freelist_populatefunction for_each_cpu_wrap
Annotated Snippet
for_each_cpu_wrap(cpu, cpu_possible_mask, raw_smp_processor_id()) {
if (cpu == raw_smp_processor_id())
continue;
head = per_cpu_ptr(s->freelist, cpu);
if (raw_res_spin_lock(&head->lock))
continue;
pcpu_freelist_push_node(head, node);
raw_res_spin_unlock(&head->lock);
return;
}
}
}
void pcpu_freelist_push(struct pcpu_freelist *s,
struct pcpu_freelist_node *node)
{
unsigned long flags;
local_irq_save(flags);
__pcpu_freelist_push(s, node);
local_irq_restore(flags);
}
void pcpu_freelist_populate(struct pcpu_freelist *s, void *buf, u32 elem_size,
u32 nr_elems)
{
struct pcpu_freelist_head *head;
unsigned int cpu, cpu_idx, i, j, n, m;
n = nr_elems / num_possible_cpus();
m = nr_elems % num_possible_cpus();
cpu_idx = 0;
for_each_possible_cpu(cpu) {
head = per_cpu_ptr(s->freelist, cpu);
j = n + (cpu_idx < m ? 1 : 0);
for (i = 0; i < j; i++) {
/* No locking required as this is not visible yet. */
pcpu_freelist_push_node(head, buf);
buf += elem_size;
}
cpu_idx++;
}
}
static struct pcpu_freelist_node *___pcpu_freelist_pop(struct pcpu_freelist *s)
{
struct pcpu_freelist_node *node = NULL;
struct pcpu_freelist_head *head;
int cpu;
for_each_cpu_wrap(cpu, cpu_possible_mask, raw_smp_processor_id()) {
head = per_cpu_ptr(s->freelist, cpu);
if (!READ_ONCE(head->first))
continue;
if (raw_res_spin_lock(&head->lock))
continue;
node = head->first;
if (node) {
WRITE_ONCE(head->first, node->next);
raw_res_spin_unlock(&head->lock);
return node;
}
raw_res_spin_unlock(&head->lock);
}
return node;
}
struct pcpu_freelist_node *__pcpu_freelist_pop(struct pcpu_freelist *s)
{
return ___pcpu_freelist_pop(s);
}
struct pcpu_freelist_node *pcpu_freelist_pop(struct pcpu_freelist *s)
{
struct pcpu_freelist_node *ret;
unsigned long flags;
local_irq_save(flags);
ret = __pcpu_freelist_pop(s);
local_irq_restore(flags);
return ret;
}
Annotation
- Immediate include surface: `percpu_freelist.h`.
- Detected declarations: `function pcpu_freelist_init`, `function for_each_possible_cpu`, `function pcpu_freelist_destroy`, `function pcpu_freelist_push_node`, `function ___pcpu_freelist_push`, `function __pcpu_freelist_push`, `function pcpu_freelist_push`, `function pcpu_freelist_populate`, `function for_each_cpu_wrap`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source 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.