kernel/bpf/bpf_lru_list.h

Source file repositories/reference/linux-study-clean/kernel/bpf/bpf_lru_list.h

File Facts

System
Linux kernel
Corpus path
kernel/bpf/bpf_lru_list.h
Extension
.h
Size
2323 bytes
Lines
94
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct bpf_lru_node {
	/*
	 * A node is in at most one list at a time. The free path on the
	 * per-CPU locallist uses an llist, so share storage via a union.
	 */
	union {
		struct list_head list;
		struct llist_node llist;
	};
	u16 cpu;
	u8 type;
	u8 ref;
	/*
	 * Marks nodes whose *_push_free() lock acquire failed; reclaimed
	 * by flush/shrink which honor the flag instead of del_from_htab().
	 */
	u8 pending_free;
};

struct bpf_lru_list {
	struct list_head lists[NR_BPF_LRU_LIST_T];
	unsigned int counts[NR_BPF_LRU_LIST_COUNT];
	/* The next inactive list rotation starts from here */
	struct list_head *next_inactive_rotation;

	rqspinlock_t lock ____cacheline_aligned_in_smp;
};

struct bpf_lru_locallist {
	struct list_head pending_list;
	struct llist_head free_llist;
	u16 next_steal;
	rqspinlock_t lock;
};

struct bpf_common_lru {
	struct bpf_lru_list lru_list;
	struct bpf_lru_locallist __percpu *local_list;
};

typedef bool (*del_from_htab_func)(void *arg, struct bpf_lru_node *node);

struct bpf_lru {
	union {
		struct bpf_common_lru common_lru;
		struct bpf_lru_list __percpu *percpu_lru;
	};
	del_from_htab_func del_from_htab;
	void *del_arg;
	unsigned int hash_offset;
	unsigned int target_free;
	unsigned int nr_scans;
	bool percpu;
};

static inline void bpf_lru_node_set_ref(struct bpf_lru_node *node)
{
	if (!READ_ONCE(node->ref))
		WRITE_ONCE(node->ref, 1);
}

int bpf_lru_init(struct bpf_lru *lru, bool percpu, u32 hash_offset,
		 del_from_htab_func del_from_htab, void *delete_arg);
void bpf_lru_populate(struct bpf_lru *lru, void *buf, u32 node_offset,
		      u32 elem_size, u32 nr_elems);
void bpf_lru_destroy(struct bpf_lru *lru);
struct bpf_lru_node *bpf_lru_pop_free(struct bpf_lru *lru, u32 hash);
void bpf_lru_push_free(struct bpf_lru *lru, struct bpf_lru_node *node);

#endif

Annotation

Implementation Notes