X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/dbfc095e6e2db3fd17d5406c1ec30a478194ad4d..a136ca38d83fae60994a54f5da88120e545895e1:/lunaix-os/kernel/mm/valloc.c?ds=sidebyside diff --git a/lunaix-os/kernel/mm/valloc.c b/lunaix-os/kernel/mm/valloc.c index 67c8eac..d2baa35 100644 --- a/lunaix-os/kernel/mm/valloc.c +++ b/lunaix-os/kernel/mm/valloc.c @@ -5,6 +5,9 @@ #define CLASS_LEN(class) (sizeof(class) / sizeof(class[0])) +// threshold to use external cake metadata +#define EXTERN_THRESHOLD 128 + static char piles_names[][PILE_NAME_MAXLEN] = { "valloc_8", "valloc_16", "valloc_32", "valloc_64", @@ -12,6 +15,24 @@ static char piles_names[][PILE_NAME_MAXLEN] = "valloc_2k", "valloc_4k", "valloc_8k" }; +#define M128 (4) +#define M1K (M128 + 3) + +static int page_counts[] = +{ + [0] = 1, + [1] = 1, + [2] = 1, + [3] = 1, + [M128 ] = 1, + [M128 + 1] = 2, + [M128 + 2] = 2, + [M1K ] = 4, + [M1K + 1 ] = 4, + [M1K + 2 ] = 8, + [M1K + 3 ] = 8 +}; + static char piles_names_dma[][PILE_NAME_MAXLEN] = { "valloc_dma_128", "valloc_dma_256", "valloc_dma_512", @@ -24,16 +45,24 @@ static struct cake_pile* piles_dma[CLASS_LEN(piles_names_dma)]; void valloc_init() { + int opts = 0; for (size_t i = 0; i < CLASS_LEN(piles_names); i++) { int size = 1 << (i + 3); - piles[i] = cake_new_pile(piles_names[i], size, size > 1024 ? 8 : 1, 0); + if (size >= EXTERN_THRESHOLD) { + opts |= PILE_FL_EXTERN; + } + piles[i] = cake_new_pile(piles_names[i], size, page_counts[i], opts); } + opts = PILE_ALIGN_CACHE; // DMA 内存保证128字节对齐 for (size_t i = 0; i < CLASS_LEN(piles_names_dma); i++) { int size = 1 << (i + 7); + if (size >= EXTERN_THRESHOLD) { + opts |= PILE_FL_EXTERN; + } piles_dma[i] = cake_new_pile( - piles_names_dma[i], size, size > 1024 ? 4 : 1, PILE_ALIGN_CACHE); + piles_names_dma[i], size, page_counts[M128 + i], opts); } }