35
Go’LegOS Go’LegOS Alternative Memory Management Alternative Memory Management Schemes for LegOS Project Schemes for LegOS Project Hao Ji Hao Ji Yanhao Zhu Yanhao Zhu Gowri Mereddy Gowri Mereddy

Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Embed Size (px)

Citation preview

Page 1: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Go’LegOSGo’LegOS

Alternative Memory Management Alternative Memory Management Schemes for LegOS ProjectSchemes for LegOS Project

Hao JiHao Ji

Yanhao ZhuYanhao Zhu

Gowri MereddyGowri Mereddy

Page 2: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Problem StatementProblem Statement

To introduces a new system call mm_algoritTo introduces a new system call mm_algorithm_used() to allow the user to select the typhm_used() to allow the user to select the type of memory management required dependie of memory management required depending up to the type of user programs in order tng up to the type of user programs in order to have efficient memory management.o have efficient memory management.

Page 3: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

The Basic memory blockThe Basic memory block

Process IDProcess ID

SizeSize

Data FieldData Field

The unit of the memory is 2 byte word

4 bytes Head

Consisting of Process ID and Size

Size indicating the length of Data Field

&mm_start Free&mm_start Free

0xEf50 LCD DATA0xEf50 LCD DATA

0xef50 FREE0xef50 FREE

0xF000 Motor0xF000 Motor

0xF010 Free0xF010 Free

0xFB80 Vectors0xFB80 Vectors

0xFE00 Free0xFE00 Free

0xFF00 Onchip Register0xFF00 Onchip Register

Page 4: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Current MechanismCurrent Mechanism

Straightforward continuous allocation Straightforward continuous allocation schemescheme

No advanced memory schemes (which No advanced memory schemes (which imply more overheads)imply more overheads)

The kernel code and the kernel data starts The kernel code and the kernel data starts at the location 0x8000 up to the global at the location 0x8000 up to the global variable mm_start ( User memory space)variable mm_start ( User memory space)

The user memory starts from mm_start to The user memory starts from mm_start to 0xFFFF.0xFFFF.

Page 5: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

The Technique that is currently implemented is The Technique that is currently implemented is First fit. (i.e the first enough free block for The First fit. (i.e the first enough free block for The alternative schemes to be implemented is the alternative schemes to be implemented is the process)process)

The function mm_try_join takes the address of a The function mm_try_join takes the address of a free memory blocks as the parameters and free memory blocks as the parameters and merges with the following free memory blocks.merges with the following free memory blocks.

The merging requires locking of the The merging requires locking of the mm_semophore to stop the other process mm_semophore to stop the other process requesting memory space in multitasking mode requesting memory space in multitasking mode

Page 6: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

TechniquesTechniques BEST FIT:BEST FIT:

The Memory is searched from the mm_start till the end to The Memory is searched from the mm_start till the end to find a free memory which is of the nearest size to the find a free memory which is of the nearest size to the required size. This type of technique leads to minimize required size. This type of technique leads to minimize external fragmention,but may lead to lot of internal external fragmention,but may lead to lot of internal fragmentations.fragmentations.

WORST FIT:WORST FIT: The memory is searched to find the biggest whole available The memory is searched to find the biggest whole available

and the split into two parts so that the other process can use and the split into two parts so that the other process can use the space. May be a solution to internal fragmentation.the space. May be a solution to internal fragmentation.

Page 7: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

NEXT FIT:NEXT FIT:

The alteration of the First fit is the next fit. Never it finds the The alteration of the First fit is the next fit. Never it finds the hole it stores the location, and when requested for hole it stores the location, and when requested for allocation starts allocating from that positionallocation starts allocating from that position

Page 8: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Files modified:Files modified: stdlib.hstdlib.h

– declare function declare function mm_algorithm_usedmm_algorithm_used as an extern function. as an extern function.– declare function declare function mm_scanmm_scan as extern function as extern function

mm.cmm.c– Added Added #define FIRST_FIT 0#define FIRST_FIT 0, , #define NEXT_FIT 1#define NEXT_FIT 1,,

#define BEST_FIT 2#define BEST_FIT 2, , #define WORST_FIT 3#define WORST_FIT 3– Added kernel variable Added kernel variable mm_policymm_policy, which remember which algorithm , which remember which algorithm

should be used. During kernel startup, it is initialized to should be used. During kernel startup, it is initialized to FIRST_FITFIRST_FIT..– Added kernel variable Added kernel variable mm_next_freemm_next_free, which always points to the , which always points to the

next free block during the search. It is initialized to next free block during the search. It is initialized to &mm_start&mm_start at the at the very beginning.very beginning.

– Add function Add function mm_algorithm_used(int a)mm_algorithm_used(int a) as following: as following:

Page 9: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

void mm_algorithm_used(unsigned short policy){void mm_algorithm_used(unsigned short policy){ if(policy < FIRST_FIT || policy > WORST_FIT) return ;if(policy < FIRST_FIT || policy > WORST_FIT) return ; #ifdef CONF_TM#ifdef CONF_TM sem_wait(&mm_semaphore);sem_wait(&mm_semaphore); #endif#endif /*/* if current policy is not NEXT_FIT and we want to change it to if current policy is not NEXT_FIT and we want to change it to

NEXT_FIT, NEXT_FIT, we need to change the pointer mm_next_free to point to we need to change the pointer mm_next_free to point to

mm_first_freemm_first_free */*/ if (policy == NEXT_FIT )if (policy == NEXT_FIT ) if (mm_policy !=NEXT_FIT) mm_next_free = if (mm_policy !=NEXT_FIT) mm_next_free =

mm_first_free;mm_first_free; mm_policy = policy;mm_policy = policy; #ifdef CONF_TM#ifdef CONF_TM sem_post(&mm_semaphore);sem_post(&mm_semaphore); #endif#endif }}

Page 10: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

-Modified malloc function-Modified malloc function

void *malloc(size_t size)void *malloc(size_t size) {{

if (mm_policy == FIRST_FIT) return if (mm_policy == FIRST_FIT) return malloc_first_fit(size);malloc_first_fit(size);If (mm_policy == NEXT_FIT) return If (mm_policy == NEXT_FIT) return malloc_next_fit(size);malloc_next_fit(size);if (mm_policy == BEST_FIT) return if (mm_policy == BEST_FIT) return malloc_best_fit(size);malloc_best_fit(size);if (mm_policy == WORST_FIT) return if (mm_policy == WORST_FIT) return malloc_worst_fit(size);malloc_worst_fit(size);

}} malloc_best_fit() malloc_worst_fit()

malloc_first_fit() malloc_next_fit()

malloc()

Page 11: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Add function Add function malloc_next_fit()malloc_next_fit() as following as following

This algorithm search the free memory block from This algorithm search the free memory block from mm_next_fmm_next_freeree, which is the pointer pointing to the next free block. If it fo, which is the pointer pointing to the next free block. If it found one suitable free block, it will put the new block there. If tund one suitable free block, it will put the new block there. If the free block size is bigger than request size plus he free block size is bigger than request size plus MM_SPLITMM_SPLIT_THRESH (MM_HEADER_SIZE+8)_THRESH (MM_HEADER_SIZE+8), the block will be split. If , the block will be split. If memory block allocation is succeed, the pointer, memory block allocation is succeed, the pointer, mm_next_frmm_next_freeee, is updated to the addres of next free block if there is one. , is updated to the addres of next free block if there is one. Otherwise, Otherwise, mm_next_freemm_next_free is reset to is reset to &mm_start&mm_start

Page 12: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

void *malloc_next_fit(size_t size) {void *malloc_next_fit(size_t size) { size_t *ptr,*next;size_t *ptr,*next; size=(size+1)>>1;size=(size+1)>>1; // only multiples of 2// only multiples of 2 #ifdef CONF_TM#ifdef CONF_TM sem_wait(&mm_semaphore);sem_wait(&mm_semaphore); // tasksafe// tasksafe #endif#endif ptr=mm_next_free;ptr=mm_next_free; next = mm_next_free;next = mm_next_free; while(ptr>=&mm_start) {while(ptr>=&mm_start) { if(*(ptr++)==MM_FREE) {if(*(ptr++)==MM_FREE) { // free block?// free block? #ifdef CONF_TM#ifdef CONF_TM mm_try_join(ptr);mm_try_join(ptr); // unite with later blocks// unite with later blocks #endif#endif if(*ptr>=size) {if(*ptr>=size) { // big enough?// big enough? *(ptr-1)=(size_t)cpid; // set owner*(ptr-1)=(size_t)cpid; // set owner // split this block?// split this block? if((*ptr-size)>=MM_SPLIT_THRESH) {if((*ptr-size)>=MM_SPLIT_THRESH) { next=ptr+size+1;next=ptr+size+1; *(next++)=MM_FREE;*(next++)=MM_FREE; *(next)=*ptr-size-MM_HEADER_SIZE;*(next)=*ptr-size-MM_HEADER_SIZE; mm_try_join(next);mm_try_join(next); *ptr=size;*ptr=size;

Page 13: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

next--;next--; }else}else /* move mm_next_free pointer to next available free block*//* move mm_next_free pointer to next available free block*/ {{ next = ptr+MM_HEADER_SIZE+*(ptr)-1;next = ptr+MM_HEADER_SIZE+*(ptr)-1; }} // was it the first free one?// was it the first free one? if(ptr==mm_first_free+1)if(ptr==mm_first_free+1) mm_update_first_free(ptr+*ptr+1);mm_update_first_free(ptr+*ptr+1); while(*(next)!=MM_FREE && next >= ptr)while(*(next)!=MM_FREE && next >= ptr) next = next =

next+MM_HEADER_SIZE+*(next+1);next+MM_HEADER_SIZE+*(next+1); if (next < ptr) next = mm_first_free;if (next < ptr) next = mm_first_free; mm_next_free = next;mm_next_free = next; #ifdef CONF_TM#ifdef CONF_TM sem_post(&mm_semaphore);sem_post(&mm_semaphore); #endif#endif return (void*) (ptr+1);return (void*) (ptr+1); }} }} ptr+=(*ptr)+1;ptr+=(*ptr)+1; // find next block.// find next block.

Page 14: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

/* in case we didn't find a usable block between mm_next_free and 0xFFFF, /* in case we didn't find a usable block between mm_next_free and 0xFFFF, we need to go back from the pointer of mm_first_free to search from the we need to go back from the pointer of mm_first_free to search from the

beginning */ beginning */ ptr = mm_first_free ;ptr = mm_first_free ; while(ptr >= mm_first_free && ptr <mm_next_free ){while(ptr >= mm_first_free && ptr <mm_next_free ){ if(*(ptr++)==MM_FREE) {if(*(ptr++)==MM_FREE) { // free block?// free block? #ifdef CONF_TM#ifdef CONF_TM mm_try_join(ptr);mm_try_join(ptr); // unite with later blocks// unite with later blocks #endif#endif if(*ptr>=size) {if(*ptr>=size) { // big enough?// big enough? *(ptr-1)=(size_t)cpid;*(ptr-1)=(size_t)cpid; // set owner// set owner // split this block?// split this block? if((*ptr-size)>=MM_SPLIT_THRESH) {if((*ptr-size)>=MM_SPLIT_THRESH) { next=ptr+size+1;next=ptr+size+1; *(next++)=MM_FREE;*(next++)=MM_FREE; *(next)=*ptr-size-MM_HEADER_SIZE;*(next)=*ptr-size-MM_HEADER_SIZE; mm_try_join(next);mm_try_join(next); *ptr=size;*ptr=size; }else}else /* move mm_next_free pointer to next available free block*//* move mm_next_free pointer to next available free block*/ {{ next = ptr+MM_HEADER_SIZE+*(ptr)-1;next = ptr+MM_HEADER_SIZE+*(ptr)-1;

Page 15: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

// was it the first free one?// was it the first free one? if(ptr==mm_first_free+1)if(ptr==mm_first_free+1) mm_update_first_free(ptr+*ptr+1);mm_update_first_free(ptr+*ptr+1); while(*(next)!=MM_FREE && next >= ptr)while(*(next)!=MM_FREE && next >= ptr) next = next =

next+MM_HEADER_SIZE+*(next+1);next+MM_HEADER_SIZE+*(next+1); if (next < ptr) next = mm_first_free;if (next < ptr) next = mm_first_free; mm_next_free = next;mm_next_free = next; #ifdef CONF_TM#ifdef CONF_TM sem_post(&mm_semaphore);sem_post(&mm_semaphore); #endif#endif return (void*) (ptr+1);return (void*) (ptr+1); }} }} ptr+=(*ptr)+1;ptr+=(*ptr)+1; // find next block.// find next block. }} #ifdef CONF_TM#ifdef CONF_TM sem_post(&mm_semaphore);sem_post(&mm_semaphore); #endif#endif return NULL;return NULL; }} //find //find

Page 16: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Add function Add function malloc_best_fit()malloc_best_fit() as following: as following: //! allocate a block of memory using Best _fit POLICY//! allocate a block of memory using Best _fit POLICY /*! \param size requested block size/*! \param size requested block size \return 0 on error, else pointer to block.\return 0 on error, else pointer to block. */*/ void *malloc_best_fit(size_t size) {void *malloc_best_fit(size_t size) { size_t *ptr,*next,*bestptr;size_t *ptr,*next,*bestptr; size_t bestsize;size_t bestsize; size=(size+1)>>1;size=(size+1)>>1; // only multiples of 2// only multiples of 2 #ifdef CONF_TM#ifdef CONF_TM sem_wait(&mm_semaphore);sem_wait(&mm_semaphore); // tasksafe// tasksafe #endif#endif ptr=mm_first_free;ptr=mm_first_free; bestptr=ptr;bestptr=ptr; bestsize=0xFFFF;bestsize=0xFFFF; while(ptr>=&mm_start) {while(ptr>=&mm_start) { if(*(ptr++)==MM_FREE) {if(*(ptr++)==MM_FREE) { // free block?// free block? #ifdef CONF_TM#ifdef CONF_TM

Page 17: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

mm_try_join(ptr);mm_try_join(ptr); // unite with later blocks// unite with later blocks #endif#endif if(*ptr>=size) {if(*ptr>=size) { // big enough?// big enough? if(*ptr<bestsize){if(*ptr<bestsize){ bestsize=*ptr;bestsize=*ptr; bestptr=ptr-1;bestptr=ptr-1; }} }} }} ptr+=(*ptr)+1;ptr+=(*ptr)+1; // find next block.// find next block. }} if (bestsize != 0xFFFF) {if (bestsize != 0xFFFF) { ptr = bestptr +1;ptr = bestptr +1; *(ptr-1)=(size_t)cpid;*(ptr-1)=(size_t)cpid; // set owner// set owner // split this block?// split this block? if((*ptr-size)>=MM_SPLIT_THRESH) {if((*ptr-size)>=MM_SPLIT_THRESH) { next=ptr+size+1;next=ptr+size+1; *(next++)=MM_FREE;*(next++)=MM_FREE; *(next)=*ptr-size-MM_HEADER_SIZE;*(next)=*ptr-size-MM_HEADER_SIZE; mm_try_join(next);mm_try_join(next); *ptr=size;*ptr=size; }} // was it the first free one?// was it the first free one?

Page 18: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

if(ptr==mm_first_free+1)if(ptr==mm_first_free+1) mm_update_first_free(ptr+*ptr+1);mm_update_first_free(ptr+*ptr+1); #ifdef CONF_TM#ifdef CONF_TM sem_post(&mm_semaphore);sem_post(&mm_semaphore); #endif#endif return (void*) (bestptr);return (void*) (bestptr); }} #ifdef CONF_TM#ifdef CONF_TM sem_post(&mm_semaphore);sem_post(&mm_semaphore); #endif#endif return NULLreturn NULL;;

Page 19: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Add function Add function malloc_worst_fit()malloc_worst_fit() as following: as following: //! allocate a block of memory using Worst _fit POLICY//! allocate a block of memory using Worst _fit POLICY /*! \param size requested block size/*! \param size requested block size \return 0 on error, else pointer to block.\return 0 on error, else pointer to block. */*/ void *malloc_worst_fit(size_t size) {void *malloc_worst_fit(size_t size) { size_t *ptr,*next,*worstptr;size_t *ptr,*next,*worstptr; size_t worstsize;size_t worstsize; size=(size+1)>>1;size=(size+1)>>1; // only multiples of // only multiples of

22 #ifdef CONF_TM#ifdef CONF_TM sem_wait(&mm_semaphore);sem_wait(&mm_semaphore); // tasksafe// tasksafe #endif#endif ptr=mm_first_free;ptr=mm_first_free; worstptr=ptr;worstptr=ptr; worstsize=0;worstsize=0; while(ptr>=&mm_start) {while(ptr>=&mm_start) { if(*(ptr++)==MM_FREE) {if(*(ptr++)==MM_FREE) { // free // free

block?block?

Page 20: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

while(ptr>=&mm_start) {while(ptr>=&mm_start) { if(*(ptr++)==MM_FREE) {if(*(ptr++)==MM_FREE) { // free block?// free block? #ifdef CONF_TM#ifdef CONF_TM mm_try_join(ptr);mm_try_join(ptr); // unite with later blocks// unite with later blocks #endif#endif if(*ptr>=size) {if(*ptr>=size) { // big enough?// big enough? if(*ptr>worstsize){if(*ptr>worstsize){ worstsize=*ptr;worstsize=*ptr; worstptr=ptr-1;worstptr=ptr-1; }} }} }} ptr+=(*ptr)+1;ptr+=(*ptr)+1; // find next block.// find next block. }} if (worstsize != 0) {if (worstsize != 0) { ptr = worstptr +1;ptr = worstptr +1; *(ptr-1)=(size_t)cpid;*(ptr-1)=(size_t)cpid; // set owner// set owner // split this block?// split this block? if((*ptr-size)>=MM_SPLIT_THRESH) {if((*ptr-size)>=MM_SPLIT_THRESH) { next=ptr+size+1;next=ptr+size+1; *(next++)=MM_FREE;*(next++)=MM_FREE; *(next)=*ptr-size-MM_HEADER_SIZE;*(next)=*ptr-size-MM_HEADER_SIZE; mm_try_join(next);mm_try_join(next); *ptr=size;*ptr=size; }}

Page 21: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

if(ptr==mm_first_free+1)if(ptr==mm_first_free+1) mm_update_first_free(ptr+*ptr+1);mm_update_first_free(ptr+*ptr+1); #ifdef CONF_TM#ifdef CONF_TM sem_post(&mm_semaphore);sem_post(&mm_semaphore); #endif#endif return (void*) (worstptr);return (void*) (worstptr); }} #ifdef CONF_TM#ifdef CONF_TM sem_post(&mm_semaphore);sem_post(&mm_semaphore); #endif#endif return NULL;return NULL; }}

Page 22: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

TestingTesting (1). First Fit(1). First Fit

Testing Program:Testing Program: mm_algorithm_used(FIRST_FIT);mm_algorithm_used(FIRST_FIT); cputs("malloc0");cputs("malloc0"); mm_scan(); mm_scan(); sleep(1);sleep(1); n=(char*)malloc(sizeof(char)*15388); //15388 bytes = 0x1E0E wordsn=(char*)malloc(sizeof(char)*15388); //15388 bytes = 0x1E0E words m= (char*)malloc(sizeof(char)*160); //160 bytes = 0x50 wordsm= (char*)malloc(sizeof(char)*160); //160 bytes = 0x50 words o= (char*)malloc(sizeof(char)*16); //16 bytes = 0x08 wordso= (char*)malloc(sizeof(char)*16); //16 bytes = 0x08 words mm_scan();mm_scan(); free(n);free(n); free(m);free(m); free(o);free(o); cputs("free0");cputs("free0"); sleep(1);sleep(1); mm_scan();mm_scan();

Page 23: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Before malloc();Before malloc();

Page 24: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

After malloc();After malloc();

Page 25: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

(2). Next Fit(2). Next Fit Testing program:Testing program: mm_algorithm_used(NEXT_FIT);mm_algorithm_used(NEXT_FIT); mm_scan();mm_scan(); // sleep(1);// sleep(1); n=(char*)malloc(sizeof(char)*15394); //15394 bytes = n=(char*)malloc(sizeof(char)*15394); //15394 bytes =

0x1E11 words0x1E11 words m= (char*)malloc(sizeof(char)*160);//160 bytes = 0x50 m= (char*)malloc(sizeof(char)*160);//160 bytes = 0x50

words// words// o= (char*)malloc(sizeof(char)*16); //16 bytes = 0x08 wordso= (char*)malloc(sizeof(char)*16); //16 bytes = 0x08 words mm_scan();mm_scan(); free(n);free(n); free(m);free(m); free(o);free(o); cputs("free1");cputs("free1"); sleep(1);sleep(1); mm_scan();mm_scan();

Page 26: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Before malloc();Before malloc();

Page 27: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

After malloc();After malloc();

Page 28: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

(3) Best_FIT(3) Best_FIT

mm_algorithm_used(BEST_FIT);mm_algorithm_used(BEST_FIT); cputs("malloc2");cputs("malloc2"); mm_scan();mm_scan(); sleep(1);sleep(1); n=(char*)malloc(sizeof(char)*170); //170 bytes = 0x0055 n=(char*)malloc(sizeof(char)*170); //170 bytes = 0x0055

wordswords m= (char*)malloc(sizeof(char)*8); //8 bytes = 0x0004 wordsm= (char*)malloc(sizeof(char)*8); //8 bytes = 0x0004 words mm_scan();mm_scan(); free(n);free(n); cputs("free2");cputs("free2"); sleep(1);sleep(1); mm_scan();mm_scan();

Page 29: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Before malloc();Before malloc();

Page 30: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

After malloc();After malloc();

Page 31: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

(4)worst_fit(4)worst_fit

mm_algorithm_used(3);mm_algorithm_used(3); cputs("malloc3");cputs("malloc3"); mm_scan();mm_scan(); sleep(1);sleep(1); n=(char*)malloc(sizeof(char)*12878); //12878 bytes = 0x1927 n=(char*)malloc(sizeof(char)*12878); //12878 bytes = 0x1927

wordswords m= (char*)malloc(sizeof(char)*1024); //1024 bytes = 0x0200 m= (char*)malloc(sizeof(char)*1024); //1024 bytes = 0x0200

wordswords mm_scan();mm_scan(); free(n);free(n); cputs("free3");cputs("free3"); sleep(1);sleep(1); mm_scan();mm_scan();

Page 32: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Before malloc();Before malloc();

Page 33: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

After malloc();After malloc();

Page 34: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Test ConclusionTest Conclusion

We keep the same interface to We keep the same interface to programmer so that they don’t need programmer so that they don’t need to modify any of their source codes .to modify any of their source codes .(Seamless hacking) (Seamless hacking)

The new memory allocation The new memory allocation mechanism we developed works mechanism we developed works fine.fine.

LNP may save a lot of test time and LNP may save a lot of test time and be more straightforward. be more straightforward. /*/*

we got crazy when pressing the button for we got crazy when pressing the button for hundreds of times to keep record of our hundreds of times to keep record of our testing result.testing result.

*/*/

Page 35: Go’LegOS Alternative Memory Management Schemes for LegOS Project Hao Ji Yanhao Zhu Gowri Mereddy

Thank you and Merry XmasThank you and Merry Xmas