tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c- Extension
.c- Size
- 4404 bytes
- Lines
- 210
- 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.
- 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
libarena/common.hlibarena/asan.hlibarena/buddy.h
Detected Declarations
struct segarr_entryfunction test_buddy_createfunction test_buddy_allocfunction test_buddy_alloc_freefunction test_buddy_alloc_multiplefunction test_buddy_alignment
Annotated Snippet
struct segarr_entry {
u8 __arena *block;
size_t sz;
u8 poison;
};
#define SEGARRLEN (512)
static struct segarr_entry __arena segarr[SEGARRLEN];
static void __arena *ptrs[17];
size_t __arena alloc_sizes[] = { 3, 17, 1025, 129, 16350, 333, 9, 517 };
size_t __arena alloc_multiple_sizes[] = { 3, 17, 1025, 129, 16350, 333, 9, 517, 2099 };
size_t __arena alloc_free_sizes[] = { 3, 17, 64, 129, 256, 333, 512, 517 };
size_t __arena alignment_sizes[] = { 1, 3, 7, 8, 9, 15, 16, 17, 31,
32, 64, 100, 128, 255, 256, 512, 1000 };
SEC("syscall")
__weak int test_buddy_create(void)
{
const int iters = 10;
int ret, i;
for (i = zero; i < iters && can_loop; i++) {
ret = buddy_init(&buddy);
if (ret)
return ret;
ret = buddy_destroy(&buddy);
if (ret)
return ret;
}
return 0;
}
SEC("syscall")
__weak int test_buddy_alloc(void)
{
void __arena *mem;
int ret, i;
for (i = zero; i < 8 && can_loop; i++) {
ret = buddy_init(&buddy);
if (ret)
return ret;
mem = buddy_alloc(&buddy, alloc_sizes[i]);
if (!mem) {
buddy_destroy(&buddy);
return -ENOMEM;
}
buddy_destroy(&buddy);
}
return 0;
}
SEC("syscall")
__weak int test_buddy_alloc_free(void)
{
const int iters = 800;
void __arena *mem;
int ret, i;
ret = buddy_init(&buddy);
if (ret)
return ret;
for (i = zero; i < iters && can_loop; i++) {
mem = buddy_alloc(&buddy, alloc_free_sizes[(i * 5) % 8]);
if (!mem) {
buddy_destroy(&buddy);
return -ENOMEM;
}
buddy_free(&buddy, mem);
}
buddy_destroy(&buddy);
return 0;
}
SEC("syscall")
__weak int test_buddy_alloc_multiple(void)
{
int ret, j;
u32 i, idx;
u8 __arena *mem;
size_t sz;
Annotation
- Immediate include surface: `libarena/common.h`, `libarena/asan.h`, `libarena/buddy.h`.
- Detected declarations: `struct segarr_entry`, `function test_buddy_create`, `function test_buddy_alloc`, `function test_buddy_alloc_free`, `function test_buddy_alloc_multiple`, `function test_buddy_alignment`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.