samples/bpf/test_lru_dist.c
Source file repositories/reference/linux-study-clean/samples/bpf/test_lru_dist.c
File Facts
- System
- Linux kernel
- Corpus path
samples/bpf/test_lru_dist.c- Extension
.c- Size
- 12095 bytes
- Lines
- 535
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hstdio.hunistd.hlinux/bpf.herrno.hstring.hassert.hsched.hsys/wait.hsys/stat.hfcntl.hstdlib.htime.hbpf/bpf.hbpf_util.h
Detected Declarations
struct list_headstruct pfect_lru_nodestruct pfect_lrufunction INIT_LIST_HEADfunction __list_addfunction list_addfunction __list_delfunction __list_del_entryfunction list_movefunction pfect_lru_initfunction pfect_lru_destroyfunction pfect_lru_lookup_or_insertfunction read_keysfunction create_mapfunction sched_next_onlinefunction run_parallelfunction do_test_lru_distfunction test_parallel_lru_distfunction test_lru_loss0function test_lru_loss1function do_test_parallel_lru_lossfunction test_parallel_lru_lossfunction main
Annotated Snippet
struct list_head {
struct list_head *next, *prev;
};
static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->next = list;
list->prev = list;
}
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
next->prev = prev;
prev->next = next;
}
static inline void __list_del_entry(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
}
static inline void list_move(struct list_head *list, struct list_head *head)
{
__list_del_entry(list);
list_add(list, head);
}
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
#define list_last_entry(ptr, type, member) \
list_entry((ptr)->prev, type, member)
struct pfect_lru_node {
struct list_head list;
unsigned long long key;
};
struct pfect_lru {
struct list_head list;
struct pfect_lru_node *free_nodes;
unsigned int cur_size;
unsigned int lru_size;
unsigned int nr_unique;
unsigned int nr_misses;
unsigned int total;
int map_fd;
};
static void pfect_lru_init(struct pfect_lru *lru, unsigned int lru_size,
unsigned int nr_possible_elems)
{
lru->map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,
sizeof(unsigned long long),
sizeof(struct pfect_lru_node *),
nr_possible_elems, NULL);
assert(lru->map_fd != -1);
lru->free_nodes = malloc(lru_size * sizeof(struct pfect_lru_node));
assert(lru->free_nodes);
INIT_LIST_HEAD(&lru->list);
lru->cur_size = 0;
lru->lru_size = lru_size;
lru->nr_unique = lru->nr_misses = lru->total = 0;
}
static void pfect_lru_destroy(struct pfect_lru *lru)
{
close(lru->map_fd);
free(lru->free_nodes);
}
static int pfect_lru_lookup_or_insert(struct pfect_lru *lru,
unsigned long long key)
Annotation
- Immediate include surface: `linux/types.h`, `stdio.h`, `unistd.h`, `linux/bpf.h`, `errno.h`, `string.h`, `assert.h`, `sched.h`.
- Detected declarations: `struct list_head`, `struct pfect_lru_node`, `struct pfect_lru`, `function INIT_LIST_HEAD`, `function __list_add`, `function list_add`, `function __list_del`, `function __list_del_entry`, `function list_move`, `function pfect_lru_init`.
- Atlas domain: Support Tooling And Documentation / samples.
- 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.