Pārlūkot izejas kodu

完成实验2

修复了测试代码中的bug。
x86-32
423A35C7 pirms 7 mēnešiem
vecāks
revīzija
dce49e4420
1 mainītis faili ar 56 papildinājumiem un 2 dzēšanām
  1. +56
    -2
      labcodes_answer/lab2_result/kern/mm/default_pmm.c

+ 56
- 2
labcodes_answer/lab2_result/kern/mm/default_pmm.c Parādīt failu

@ -59,6 +59,8 @@ free_area_t free_area;
#define free_list (free_area.free_list)
#define nr_free (free_area.nr_free)
list_entry_t *alloc_le = &free_list;
static void
default_init(void) {
list_init(&free_list);
@ -184,6 +186,7 @@ basic_check(void) {
list_entry_t free_list_store = free_list;
list_init(&free_list);
assert(list_empty(&free_list));
alloc_le = &free_list; //
unsigned int nr_free_store = nr_free;
nr_free = 0;
@ -211,6 +214,7 @@ basic_check(void) {
assert(nr_free == 0);
free_list = free_list_store;
nr_free = nr_free_store;
alloc_le = &free_list; //
free_page(p);
free_page(p1);
@ -239,6 +243,7 @@ default_check(void) {
list_entry_t free_list_store = free_list;
list_init(&free_list);
assert(list_empty(&free_list));
alloc_le = &free_list; // nr_free是不正常的nr_free次了
assert(alloc_page() == NULL);
unsigned int nr_free_store = nr_free;
@ -271,6 +276,9 @@ default_check(void) {
nr_free = nr_free_store;
free_list = free_list_store;
alloc_le = &free_list;
// default_alloc_pages里的le也恢复
//
free_pages(p0, 5);
le = &free_list;
@ -282,11 +290,57 @@ default_check(void) {
assert(total == 0);
}
static struct Page *
next_fit_alloc_pages(size_t n) {
assert(n > 0);
if (n > nr_free) {
return NULL;
}
list_entry_t *len;
if (alloc_le == &free_list)
alloc_le = list_next(&free_list);
list_entry_t *start = alloc_le;
// nr_free次lele
list_entry_t *end = &free_list;
while(1) {
if (alloc_le == end) { //
if (end != start) { // le == end的时候这里就不满足了
end = start; //
alloc_le = list_next(alloc_le); // &free_list不应该被分配
continue;
}
break; //
}
struct Page *p = le2page(alloc_le, page_link);
if(p->property >= n){
int i;
for(i=0;i<n;i++){
len = list_next(alloc_le); // len是list_entry_next的意思不是length的意思
struct Page *pp = le2page(alloc_le, page_link);
SetPageReserved(pp);
ClearPageProperty(pp);
list_del(alloc_le);
alloc_le = len;
}
if(p->property>n){
(le2page(alloc_le,page_link))->property = p->property - n;
}
ClearPageProperty(p);
SetPageReserved(p);
nr_free -= n;
return p;
}
alloc_le = list_next(alloc_le);
}
return NULL;
}
const struct pmm_manager default_pmm_manager = {
.name = "default_pmm_manager",
.name = "next_fit_pmm_manager",
.init = default_init,
.init_memmap = default_init_memmap,
.alloc_pages = default_alloc_pages,
.alloc_pages = next_fit_alloc_pages,
.free_pages = default_free_pages,
.nr_free_pages = default_nr_free_pages,
.check = default_check,

Notiek ielāde…
Atcelt
Saglabāt