From a1329f092b23d0632cbb0825a414bb184732cd31 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Fri, 14 Apr 2023 12:50:56 -0400 Subject: [PATCH] mem: add comment explaining buddy allocator concept --- mem/buddy.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mem/buddy.c b/mem/buddy.c index 1624a57..40ea477 100644 --- a/mem/buddy.c +++ b/mem/buddy.c @@ -89,7 +89,12 @@ static paddr_t buddy_get_slab(struct buddy_region_header *head, size_t depth, si * Conceptually, the bitmap is a tree, where each node has two children, and is * laid out flat in memory. * - * The buddy allocator + * The buddy allocator checks within a pre-defined power-of-2 region for a free + * region of the requested size. If the region is the correct size, it allocates + * it, and if it finds one that is too small, it skips it. If the region found + * is too large, instead of skipping to the next, the allocator splits the + * region in half recursively until it is of the correct size, and marks the + * bitmap accordingly. */ static paddr_t buddy_alloc_helper(struct buddy_region_header *head, size_t size) {