tools/testing/selftests/bpf/libarena/include/libarena/buddy.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/libarena/include/libarena/buddy.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/libarena/include/libarena/buddy.h
Extension
.h
Size
2821 bytes
Lines
82
Domain
Support Tooling And Documentation
Bucket
tools
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct buddy_header {
	u32 prev_index;	/* "Pointer" to the previous available allocation of the same size. */
	u32 next_index; /* Same for the next allocation. */
};

/*
 * We bring memory into the allocator 1 MiB at a time.
 */
struct buddy_chunk {
	/* The order of the current allocation for a item. 4 bits per order. */
	u8		orders[BUDDY_CHUNK_ITEMS / 2];
	/*
	 * Bit to denote whether chunk is allocated. Size of the allocated/free
	 * chunk found from the orders array.
	 */
	u8		allocated[BUDDY_CHUNK_ITEMS / 8];
	/* Freelists for O(1) allocation. */
	u64		freelists[BUDDY_CHUNK_NUM_ORDERS];
	struct buddy_chunk __arena	*next;
};

struct buddy {
	struct buddy_chunk __arena *first_chunk;		/* Pointer to the chunk linked list. */
	arena_spinlock_t lock;			/* Allocator lock */
	u64 vaddr;				/* Allocation into reserved vaddr */
};

#ifdef __BPF__

int buddy_init(struct buddy __arena *buddy);
int buddy_destroy(struct buddy __arena *buddy);
int buddy_free(struct buddy __arena *buddy, void __arena *free);
void __arena *buddy_alloc(struct buddy __arena *buddy, size_t size);

#endif /* __BPF__  */

Annotation

Implementation Notes