custom memory manager.. - Linux

This is a discussion on custom memory manager.. - Linux ; Hello, I am developing a user level memory manager for a protocol stack. It will replace the usual malloc() by something like my_malloc() and free by my_free(). The basic idea is to minimize the chances of memory non- avaliabiltiy, minimize ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: custom memory manager..

  1. custom memory manager..

    Hello,

    I am developing a user level memory manager for a protocol stack. It
    will replace the usual malloc() by something like my_malloc() and free
    by my_free(). The basic idea is to minimize the chances of memory non-
    avaliabiltiy, minimize system calls at run time thereby minimizing
    risk for failure, and use the memeory in an effcient way.

    The problem is i donot want to change the prototype of my_malloc which
    is currently same as malloc() but I also want to associate debug
    information along wth every buffer allocated.

    For example, if function f1() from task T1 calls my_malloc(), then I
    want to associate things like

    1. task_id,
    2. regiser counetrs,
    3. stack trace or any other relevant debug info that would help me
    debug any memory crash.

    Can any one suggest how can I do it? I mean which system call will hel
    me and whatother info (other then the one i have mentioned) can be
    used?



  2. Re: custom memory manager..

    Hi,

    > I am developing a user level memory manager for a protocol stack. It
    > will replace the usual malloc() by something like my_malloc() and free
    > by my_free(). The basic idea is to minimize the chances of memory non-
    > avaliabiltiy, minimize system calls at run time thereby minimizing
    > risk for failure, and use the memeory in an effcient way.


    To say somthing stupid: use Malloc and Free. They're really good ;-)

    > The problem is i donot want to change the prototype of my_malloc which
    > is currently same as malloc() but I also want to associate debug
    > information along wth every buffer allocated.


    OK, here's a sample solution:
    In your Memory manager keep track of things. You can add some data to
    each memory block by malloc'ing a few (sizeof int) bytes more, writing
    the size of the chunk to those bytes and returning the pointer to the
    chunk, increased by the few bytes. In your Free, decrease the pointer,
    read the info and release the memory.

    See it as a finger exercise ;-)

    Ciao...

  3. Re: custom memory manager..

    On Apr 17, 2:24*pm, Bernhard Agthe wrote:
    > Hi,
    >
    > > I am developing a user level memory manager for a protocol stack. It
    > > will replace the usual malloc() by something like my_malloc() and free
    > > by my_free(). The basic idea is to minimize the chances of memory non-
    > > avaliabiltiy, minimize system calls at run time thereby minimizing
    > > risk for failure, and use the memeory in an effcient way.

    >
    > To say somthing stupid: use Malloc and Free. They're really good ;-)
    >
    > > The problem is i donot want to change the prototype of my_malloc which
    > > is currently same as malloc() but I also want to associate debug
    > > information along wth every buffer allocated.

    >
    > OK, here's a sample solution:
    > In your Memory manager keep track of things. You can add some data to
    > each memory block by malloc'ing a few (sizeof int) bytes more, writing
    > the size of the chunk to those bytes and returning the pointer to the
    > chunk, increased by the few bytes. In your Free, decrease the pointer,
    > read the info and release the memory.
    >
    > See it as a finger exercise ;-)
    >
    > Ciao...


    hello,

    That I am in anyways doing to keep track of each memory buffer. I am
    using a proper header and a small trailer to acheive this pupose but I
    want to add specfic info of the task which is allocating the buffer so
    that it will be helpful in debugging. That specific info, I want.

  4. Re: custom memory manager..

    Hi,

    > That I am in anyways doing to keep track of each memory buffer. I am
    > using a proper header and a small trailer to acheive this pupose but I
    > want to add specfic info of the task which is allocating the buffer so
    > that it will be helpful in debugging. That specific info, I want.


    I'm not sure if I understand what you're trying to do.. You want to keep
    track of all memory? Then your Malloc'er should work like that:

    - allocate a LARGE chunk of memory at startup, satisfy all getMem
    requests out of that and keep track of the areas you "lease out". You'll
    know how much memory is in use, how much is free and that's it. You can
    also free all memory at shutdown reliably.

    - you can gather any information you want inside that.

    - do this for each application separately.

    On the other hand, if you're only trying to keep track of malloc and
    free, you can simply wrap the system-defined malloc and free with some
    counting code (memory used) and some logging.

    On the third hand, however, this is exactly what "valgrind" does for
    you... Give it a try ;-) It can even find stuff you won't find otherwise
    ;-) Like use of uninitialised memory...

    Or use libduma (the former libefence). It adds write-protected memory
    before or after each malloc'd block and will chrash your program once
    you try to write into that...

    Good luck...


+ Reply to Thread