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 / 2723
2722  |  2724
Subject: 
Re: detecting memory leaks
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Fri, 12 Jul 2002 23:58:36 GMT
Viewed: 
2057 times
  
Jason,

Excellent points!  I like where this is going.

"Jason Clark" wrote
<snip>
Please, post.

See below.

I'm guessing you defrag using mm_try_join()?  malloc() uses this to defrag
the beginning of the pool until it finds a big enough block (which can • then
be split again if its too big);

Yes, it uses mm_try_join() --- here it is:

//! defragment free blocks
/*! use mm_try_join on each free block of memory
*/
void mm_defrag() {
size_t *ptr = &mm_start;
#ifdef CONF_TM
sem_wait(&mm_semaphore);   // tasksafe
#endif
while(ptr >= &mm_start) {
  if(*ptr == MM_FREE)
   mm_try_join(ptr+1);
  ptr += *(ptr+1);
  ptr += MM_HEADER_SIZE;
}
#ifdef CONF_TM
sem_post(&mm_semaphore);   // tasksafe
#endif
}


Defragging during idle would save this
overhead on every malloc if malloc is rewired to only mm_try_join() • *after*
checking for a big enough block (and failing to get one).

I had done that with an older version of LegOS.  It works fine (as one might
expect)  but doesn't really improve performance much.

Another thought... defrag is meaningless if no malloc() or free() has
occurred since last defrag (calloc() calls malloc() internally)... might • be
worth having a flag in mm.c that mm_defrag() clears and malloc/free set.
Not only do extraneous calls to mm_defrag() cost less by checking the flag
and exiting, you can auto-defrag with a thread of PRIO_MIN that sleeps • until
the flag is set, defrags, repeats.  No need to insert code before the
idle.

You hit the nail on the head.  I will give this a try.

// Joe

That reminds me, there was a bug in mm.c concerning mm_try_join() attempting
to join the last block of memory.  I will try to find that solution as well
(so it can be included)



Message has 1 Reply:
  Re: detecting memory leaks
 
In case anyone attempts to use the mm_defrag() posted previously... you will need the following update to mm_try_join() //! check for free blocks after this one and join them if possible /* \param ptr pointer to size field of current block \return (...) (22 years ago, 13-Jul-02, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: detecting memory leaks
 
(...) Please, post. (...) I'm guessing you defrag using mm_try_join()? malloc() uses this to defrag the beginning of the pool until it finds a big enough block (which can then be split again if its too big); Defragging during idle would save this (...) (22 years ago, 12-Jul-02, to lugnet.robotics.rcx.legos)

5 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