几个BUDDY算法示意图:
参考内核实现的用户态BUDDY实现代码:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include "br_list.h"
#define MAX_ORDER 11
#define DBG(fmt, ...) do { \
printf("%s line %d, "fmt, __func__, __LINE__, ##__VA_ARGS__); \
} while (0)
struct page {
struct br_list_head list;
int page_idx;
int order;
};
struct br_list_head slab_list[MAX_ORDER];
struct page page_array[1024];