Screen Version
School of Computer Science & Engineering
University of New South Wales

 Advanced Operating Systems 
 COMP9242 2011/S2 

M2: Memory manager

The aim of this milestone is to design and implement simple memory management. You will need to set up a frame table so that you can keep track of the system's physical memory and the capabilities you have to that memory (om_frame_t objects). You should extend the current implementation in apps/sos/src/frametable.c. The comments in the provided file explain the existing interface. Note that your frametable implementation has no need to stick with the stub interface, you may change it as you see fit.

You should also read the comments in the om_server interface for handling frames. Specifically note that to access a frame, sos itself needs to map the frame into a virtual address.

Design alternatives

Some things you should think of are what information you need to store in the frame table. You may want to take into account the fact that you will later be using this frame table to support virtual memory, swapping and multiple processes. You should take this into account when designing your data structures.

You should also take into account which operations you want to perform on the frame table, and the required algorithms to fulfill these. For example, you don't want an order n-square O(n^2) search to find the next free frame.

Of course it is easy to change these data structures later as you gain a better understanding of the issues involved, so don't spend too much time designing the perfect structure now.

Your design should take into account the space and time complexity and bounds of your data structures.

Assessment

The demonstration of this solution should show the execution of some example code using the allocation routine. For example:

/* Allocate 10 pages and make sure you can touch them all */
for (i = 0; i < 10; i++) {
    /* Allocate a page */
    seL4_Word vaddr;
    frame_alloc(&vaddr);
    assert(vaddr);

    /* Test you can touch the page */
    *vaddr = 0x37;
    assert(*vaddr == 0x37);

    printf("Page #%d allocated at %p\n",  i, (void *) vaddr);
}
/* Test that you eventually run out of memory gracefully,
   and doesn't crash */
for (;;) {
     /* Allocate a page */
     seL4_Word vaddr;
     frame_alloc(&vaddr);
     if (!vaddr) {
	  printf("Out of memory!\n");
	  break;
     }

     /* Test you can touch the page */
     *vaddr = 0x37;
     assert(*vaddr == 0x37);
}
/* Test that you never run out of memory if you always free frames. 
    This loop should never finish */
for (int i = 0;; i++) {
     /* Allocate a page */
     seL4_Word vaddr;
     page = frame_alloc(&vaddr);
     assert(vaddr != 0);

     /* Test you can touch the page */
     *vaddr = 0x37;
     assert(*vaddr == 0x37);

     printf("Page #%d allocated at %p\n",  i, vaddr);

     frame_free(page);
}

You should also be able to explain to the tutor the structure of your frame table, how your code works and any design decisions you took.


Last modified: 03 Aug 2011.