To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 3547
3546  |  3548
Subject: 
Re: My problems with adding a Best Fit algorithm for memory management to kernel/mm.c
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sun, 7 Dec 2003 04:15:43 GMT
Viewed: 
3945 times
  
Well,

I have another problem - this time with Worst Fit.  It may be becuase I have
been looking at this code for so much time over the past few months, but I have
encountered this problem with my implementation and my mind is boggled (as well
as other's).

Here is my code (it is of course very similar to Best Fit):

===============================================
void *malloc(size_t size)
{
      size_t *ptr,*next, worstSize, *mm_worst_free;

      size=(size+1)>>1;

   #ifdef CONF_TM
   ENTER_KERNEL_CRITICAL_SECTION();
   #endif

      ptr=mm_first_free;
      worstSize=0;

      while(ptr>=mm_first_free)
      {
         if(*(ptr++)==MM_FREE)
         {
         #ifdef CONF_TM
         mm_try_join(ptr);
         #endif

            if(*ptr>=size)
            {
               if(worstSize<(*ptr))
               {
                  mm_worst_free=ptr;
                  worstSize=*(ptr);
               }
            }
         }
         ptr+=(*ptr)+1;
      }
      if(worstSize!=0)
      {
         ptr=mm_worst_free;
         *(ptr-1)=(size_t)ctid;

         if((*ptr-size)>=MM_SPLIT_THRESH)
         {
            next=ptr+size+1;
            *(next++)=MM_FREE;
            *(next)=*ptr-size-MM_HEADER_SIZE;
            mm_try_join(next);

            *ptr=size;
         }
         if(ptr==mm_first_free+1)
            mm_update_first_free(ptr+*ptr+1);

      #ifdef CONF_TM
      LEAVE_KERNEL_CRITICAL_SECTION();
      #endif

         return (void*) (mm_worst_free+1); //or (ptr+1)
      }
   #ifdef CONF_TM
   LEAVE_KERNEL_CRITICAL_SECTION();
   #endif

      return NULL;
   }
===============================================

The results I am getting a very odd.

If I load this version of the OS and then load my testing program (one which
mallocs a few blocks, then frees some, and then mallocs a few more and then
finally scans user memory and prints out the memory layout, i.e. the address,
PID, size of each block) then it seems to allocate everything fine, except for
one random block of memory which is size 7 in the after all the of OS tasks are
allocated.

But if I turn the RCX off then on either:
(a) after downloading the program or
(b)after just running the program
and then run the program again, all of the OS tasks that were allocated now
somehow must have their PID set to MM_FREE and then they are all joined together
as 1 free block of memory beginning at mm_start.  And then after that the user
program is allocated (and is fine throughout the whole process, nothing happens
to it, its PID is fine) the OS tasks get allocated again, and then from any time
after that the memory layout remains the same (i.e. no other blocks get reset
and joined to create a giant free block of memory).

Does anyone have any idea what is going on? And why?

The rest of my mm.c file is the same as the original and the same as my Best Fit
version which worls perfectly.

Thanks,
Mike



Message has 2 Replies:
  Re: My problems with adding a Best Fit algorithm for memory management to kernel/mm.c
 
(...) Hi Mike, It would be helpful to see each of the memory block dumps and some notation as to what actions you took between each dump (i.e. RCX on/off, program downloaded, etc...) Mark (21 years ago, 7-Dec-03, to lugnet.robotics.rcx.legos)
  Re: My problems with adding a Best Fit algorithm for memory management to kernel/mm.c
 
(...) So, if I understand you correctly, your concern is that the OS tasks move around the first time you power off & on, but not anytime thereafter? Assuming this to be the case, then: 1) When you first download BrickOS, there is a large chunk of (...) (21 years ago, 7-Dec-03, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  My problems with adding a Best Fit algorithm for memory management to kernel/mm.c
 
Well, my senior project is almost due (Monday) and I am having problems with one of the last algorithms to be added. My senior project is adding the 3 other algorithms to the memory management facitlity (mm.c), the algorithsm are best, worst, and (...) (21 years ago, 6-Dec-03, to lugnet.robotics.rcx.legos)

14 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR