struct Page {int ref;// page frame's reference counteruint32_t flags;// array of flags that describe the status of the page frameunsignedint property;// the num of free block, used in first fit pm managerlist_entry_t page_link;// free list link};
/* Flags describing the status of a page frame */#define PG_reserved 0// the page descriptor is reserved for kernel or unusable#define PG_property 1// the member 'property' is valid
在本实验中,Page数据结构的成员变量property用来记录某连续内存空闲块的大小(即地址连续的空闲页的个数)。这里需要注意的是用到此成员变量的这个Page比较特殊,是这个连续内存空闲块地址最小的一页(即头一页, Head Page)。连续内存空闲块利用这个页的成员变量property来记录在此块内的空闲页的个数。这里去的名字property也不是很直观,原因与上面类似,在不同的页分配算法中,property有不同的含义。
Page数据结构的成员变量page_link是便于把多个连续内存空闲块链接在一起的双向链表指针(可回顾在lab0实验指导书中有关双向链表数据结构的介绍)。这里需要注意的是用到此成员变量的这个Page比较特殊,是这个连续内存空闲块地址最小的一页(即头一页, Head Page)。连续内存空闲块利用这个页的成员变量page_link来链接比它地址小和大的其他连续内存空闲块。
/* free_area_t - maintains a doubly linked list to record free (unused) pages */
typedef struct {
list_entry_t free_list; // the list header
unsigned int nr_free; // # of free pages in this free list
} free_area_t;