2002-02-21 15:30:04

by Joe Wong

[permalink] [raw]
Subject: detect memory leak tools?

Hi,

Is there any tools that can detect memory leak in kernel loadable
module?

TIA.

- Joe


2002-02-21 15:46:54

by Richard B. Johnson

[permalink] [raw]
Subject: Re: detect memory leak tools?

On Thu, 21 Feb 2002, Joe Wong wrote:

> Hi,
>
> Is there any tools that can detect memory leak in kernel loadable
> module?
>
> TIA.
>
> - Joe

How would it know? If you can answer that question, you have made
the tool. It would be specific to your module. FYI, in designing
such a tool, you often the find the leak, which means you don't
need the tool anymore.

I would start by temporarily putting a wrapper around whatever you
use for memory allocation and deallocation. The wrapper code keeps
track of pointer values and outstanding allocations. If the outstanding
allocations grow or if the pointers to whatever_free() are different
than the pointers to whatever_alloc(), you have a leak. You can read
the results from a private ioctl().

Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (797.90 BogoMips).

111,111,111 * 111,111,111 = 12,345,678,987,654,321

2002-02-21 17:26:25

by Mike Galbraith

[permalink] [raw]
Subject: Re: detect memory leak tools?

On Thu, 21 Feb 2002, Joe Wong wrote:

> Hi,
>
> Is there any tools that can detect memory leak in kernel loadable
> module?

Depends which kernel version.. <= 2.4.9, you can use IKD, which
contains Ingo's memleak detector. Sadly, it's unmaintained atm.

See /pub/linux/kernel/people/andrea/ikd of your favorite mirror
to see if there's a canned version that fits your needs. (If not,
it's likely easier to rip memleak out of ikd and hand patch than
to try fixing the zillion rejects you'd have if you try to wedge
ikd into a recent tree:)

-Mike

2002-02-21 18:00:27

by Mike Galbraith

[permalink] [raw]
Subject: Re: detect memory leak tools?

On Thu, 21 Feb 2002, Richard B. Johnson wrote:

> On Thu, 21 Feb 2002, Joe Wong wrote:
>
> > Hi,
> >
> > Is there any tools that can detect memory leak in kernel loadable
> > module?
> >
> > TIA.
> >
> > - Joe
>
> How would it know? If you can answer that question, you have made
> the tool. It would be specific to your module. FYI, in designing
> such a tool, you often the find the leak, which means you don't
> need the tool anymore.
>
> I would start by temporarily putting a wrapper around whatever you
> use for memory allocation and deallocation. The wrapper code keeps
> track of pointer values and outstanding allocations. If the outstanding
> allocations grow or if the pointers to whatever_free() are different
> than the pointers to whatever_alloc(), you have a leak. You can read
> the results from a private ioctl().

Close to how memleak works. Wrap all allocators, and maintain a 1/32
scale model of memory consisting of tags showing who allocated that
ram-clod when. Read allocation array via proc.

For most leaks, you're right.. the tool is too much horsepower for
the problem. Memleak has found some very non-trivial leaks though.
It found one that was irritating Ingo quite a bit, and he designed
memleak :)

-Mike

2002-02-22 06:17:15

by Joe Wong

[permalink] [raw]
Subject: Re: detect memory leak tools?

Hi Mike,

Thanks for the suggestions. :)

- Joe

On Thu, 21 Feb 2002, Mike Galbraith wrote:

> On Thu, 21 Feb 2002, Richard B. Johnson wrote:
>
> > On Thu, 21 Feb 2002, Joe Wong wrote:
> >
> > > Hi,
> > >
> > > Is there any tools that can detect memory leak in kernel loadable
> > > module?
> > >
> > > TIA.
> > >
> > > - Joe
> >
> > How would it know? If you can answer that question, you have made
> > the tool. It would be specific to your module. FYI, in designing
> > such a tool, you often the find the leak, which means you don't
> > need the tool anymore.
> >
> > I would start by temporarily putting a wrapper around whatever you
> > use for memory allocation and deallocation. The wrapper code keeps
> > track of pointer values and outstanding allocations. If the outstanding
> > allocations grow or if the pointers to whatever_free() are different
> > than the pointers to whatever_alloc(), you have a leak. You can read
> > the results from a private ioctl().
>
> Close to how memleak works. Wrap all allocators, and maintain a 1/32
> scale model of memory consisting of tags showing who allocated that
> ram-clod when. Read allocation array via proc.
>
> For most leaks, you're right.. the tool is too much horsepower for
> the problem. Memleak has found some very non-trivial leaks though.
> It found one that was irritating Ingo quite a bit, and he designed
> memleak :)
>
> -Mike
>
>

--