i have just started paging. in the memory management, i am having some problems.
the very first thing : i have to keep track of all the pages in the usable/allocatable area, like to which process it is allocated, it's referance count [for swapping].
i can think of some ways to do so.
1. make a page allocation bitmap. every time, scan the entire bitmap [for the free page if allocating and for that occupied page when freeing]. i would never prefer this.
2. make a page allocation "array" of the foll. struct.
Code: Select all
/*
the page object
We maintain a pool[DLL] of free pages, and a pool
of the page_t[DLL] for each task. hence, the need of searching
a page in the allocation bitmap will virtually be eliminated.
it only needs to be searched in the pool of that specific task.
*/
typedef struct TAGpage_t{
bit32u pid; //PID of owner task
/*there is no need to keep a "allocated" flag, since the pid=0
doesn't point to any process*/
bool allocatable_to_user; //whether can be allocated to user tasks
bit32u phys_page_number; //the physical page number
struct TAGpage_t *prev, *next; //pointers for the linked list
/*other fields can be added as needed*/
}page_t;
the bitmap occupies nearly 4-5MB to keep track of 1GB memory.[not of major concern though]
for now, i have made it as a doubly linked list, i can [and will] reduce it to singly linked list.
problem with this, as we say, is the waste of time in traversing the linked list.
3. if we can create linked lists using static storage, we can also create BST or AVL trees[maybe heap?] which will save much of time for searching the pages, specially those ones which are allocated to some task and task wants to free it.
if i select any of these, how do i tackle shared pages/memory?
i find third one interesting. if anyone has tried it, or has read about it, please tell me.
one more thing, haven't started thinking about it, but in what way do you implement a kernel/task heap manager once the thing above is up? [ie. the basic functionality of page allocation - deallocation syscalls provided.]
thanx.