kernel/bpf/bpf_lru_list.c
Source file repositories/reference/linux-study-clean/kernel/bpf/bpf_lru_list.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/bpf_lru_list.c- Extension
.c- Size
- 19098 bytes
- Lines
- 731
- 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
linux/cpumask.hlinux/spinlock.hlinux/percpu.hbpf_lru_list.h
Detected Declarations
function bpf_lru_node_is_reffunction bpf_lru_node_clear_reffunction bpf_lru_list_count_incfunction bpf_lru_list_count_decfunction __bpf_lru_node_move_to_freefunction __bpf_lru_node_move_infunction __bpf_lru_node_movefunction bpf_lru_list_inactive_lowfunction __bpf_lru_list_rotate_activefunction locationfunction __bpf_lru_list_shrink_inactivefunction list_for_each_entry_safe_reversefunction __bpf_lru_list_rotatefunction __bpf_lru_list_shrink_inactivefunction list_for_each_entry_safe_reversefunction __local_list_flushfunction list_for_each_entry_safe_reversefunction bpf_lru_list_push_freefunction bpf_lru_list_pop_free_to_localfunction list_for_each_entry_safefunction __local_list_add_pendingfunction __local_list_pop_freefunction __local_list_pop_pendingfunction bpf_common_lru_push_freefunction bpf_percpu_lru_push_freefunction bpf_lru_push_freefunction bpf_common_lru_populatefunction bpf_percpu_lru_populatefunction for_each_possible_cpufunction bpf_lru_populatefunction bpf_lru_locallist_initfunction bpf_lru_list_initfunction bpf_lru_initfunction for_each_possible_cpufunction for_each_possible_cpufunction bpf_lru_destroy
Annotated Snippet
if (cur == inactive) {
cur = cur->prev;
continue;
}
node = list_entry(cur, struct bpf_lru_node, list);
next = cur->prev;
if (bpf_lru_node_is_ref(node))
__bpf_lru_node_move(l, node, BPF_LRU_LIST_T_ACTIVE);
if (cur == last)
break;
cur = next;
i++;
}
l->next_inactive_rotation = next;
}
/* Shrink the inactive list. It starts from the tail of the
* inactive list and only move the nodes without the ref bit
* set to the designated free list.
*/
static unsigned int
__bpf_lru_list_shrink_inactive(struct bpf_lru *lru,
struct bpf_lru_list *l,
unsigned int tgt_nshrink,
struct list_head *free_list,
enum bpf_lru_list_type tgt_free_type)
{
struct list_head *inactive = &l->lists[BPF_LRU_LIST_T_INACTIVE];
struct bpf_lru_node *node, *tmp_node;
unsigned int nshrinked = 0;
unsigned int i = 0;
list_for_each_entry_safe_reverse(node, tmp_node, inactive, list) {
if (bpf_lru_node_is_ref(node) &&
!READ_ONCE(node->pending_free)) {
__bpf_lru_node_move(l, node, BPF_LRU_LIST_T_ACTIVE);
} else if (READ_ONCE(node->pending_free) ||
lru->del_from_htab(lru->del_arg, node)) {
__bpf_lru_node_move_to_free(l, node, free_list,
tgt_free_type);
if (++nshrinked == tgt_nshrink)
break;
}
if (++i == lru->nr_scans)
break;
}
return nshrinked;
}
/* 1. Rotate the active list (if needed)
* 2. Always rotate the inactive list
*/
static void __bpf_lru_list_rotate(struct bpf_lru *lru, struct bpf_lru_list *l)
{
if (bpf_lru_list_inactive_low(l))
__bpf_lru_list_rotate_active(lru, l);
__bpf_lru_list_rotate_inactive(lru, l);
}
/* Calls __bpf_lru_list_shrink_inactive() to shrink some
* ref-bit-cleared nodes and move them to the designated
* free list.
*
* If it cannot get a free node after calling
* __bpf_lru_list_shrink_inactive(). It will just remove
* one node from either inactive or active list without
* honoring the ref-bit. It prefers inactive list to active
* list in this situation.
*/
static unsigned int __bpf_lru_list_shrink(struct bpf_lru *lru,
struct bpf_lru_list *l,
unsigned int tgt_nshrink,
struct list_head *free_list,
enum bpf_lru_list_type tgt_free_type)
{
struct bpf_lru_node *node, *tmp_node;
struct list_head *force_shrink_list;
unsigned int nshrinked;
nshrinked = __bpf_lru_list_shrink_inactive(lru, l, tgt_nshrink,
free_list, tgt_free_type);
if (nshrinked)
return nshrinked;
Annotation
- Immediate include surface: `linux/cpumask.h`, `linux/spinlock.h`, `linux/percpu.h`, `bpf_lru_list.h`.
- Detected declarations: `function bpf_lru_node_is_ref`, `function bpf_lru_node_clear_ref`, `function bpf_lru_list_count_inc`, `function bpf_lru_list_count_dec`, `function __bpf_lru_node_move_to_free`, `function __bpf_lru_node_move_in`, `function __bpf_lru_node_move`, `function bpf_lru_list_inactive_low`, `function __bpf_lru_list_rotate_active`, `function location`.
- 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.