-
Notifications
You must be signed in to change notification settings - Fork 7
/
mm.c
57 lines (52 loc) · 1.61 KB
/
mm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "page.h"
#include "mm.h"
#include "radix.h"
#include "lib.h"
struct address_space *address_space_array;
unsigned int address_space_index;
struct radix_tree *radix_buffer[RADIX_THRESHOLD];
unsigned int radix_buffer_index;
int radix_buffer_array_index;
unsigned int radix_buffer_cur_max;
void init_address_space()
{
address_space_array = (struct address_space*)page_malloc(CACHE_ENTRY * sizeof(struct address_space));
address_space_index = 0;
}
void init_radix_allocator()
{
radix_buffer[0] =
any_malloc(RADIX_SIZE_LV2 * sizeof(struct radix_tree) / RADIX_THRESHOLD);
memset(radix_buffer[0], 0, RADIX_SIZE_LV2 * sizeof(struct radix_tree) / RADIX_THRESHOLD);
radix_buffer_index = 0;
radix_buffer_array_index = 0;
radix_buffer_cur_max = RADIX_SIZE_LV2 / RADIX_THRESHOLD;
}
struct radix_tree *alloc_radix_tree()
{
if (unlikely(radix_buffer_index >= radix_buffer_cur_max)) {
BUG_ON(radix_buffer_array_index >= RADIX_THRESHOLD - 1);
radix_buffer[++radix_buffer_array_index] =
any_malloc(RADIX_SIZE_LV2 * sizeof(struct radix_tree) / RADIX_THRESHOLD);
memset(radix_buffer[radix_buffer_array_index], 0, RADIX_SIZE_LV2 * sizeof(struct radix_tree) / RADIX_THRESHOLD);
radix_buffer_cur_max = RADIX_SIZE_LV2 / RADIX_THRESHOLD;
radix_buffer_index = 0;
}
return radix_buffer[radix_buffer_array_index] + radix_buffer_index++;
}
#if 0
int test_radix_main()
{
init_radix_allocator();
int i;
struct radix_tree *ra[cluster_size];
for (i = 0; i < cluster_size; ++i) {
ra[i] = alloc_radix_tree();
ra[i]->next[0] = i;
}
for (i = 0; i < cluster_size; ++i) {
printf("%d\n", ra[i]->next[0]);
}
return 0;
}
#endif