lkml.org 
[lkml]   [2004]   [Oct]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Gigantic memory leak in linux-2.6.[789]!
On Fri, 22 Oct 2004, [ISO-8859-15] Kristian Sørensen wrote:

> Richard B. Johnson wrote:
>
>> On Fri, 22 Oct 2004, [ISO-8859-15] Kristian Sørensen wrote:
>>
>>> Richard B. Johnson wrote:
>>>
>>>> On Fri, 22 Oct 2004, Kasper Sandberg wrote:
>>>>
>>>>> On Fri, 2004-10-22 at 16:13 +0200, Kristian Sørensen wrote:
>>>>>
>>>>>> Hi all!
>>>>>>
>>>>>> After some more testing after the previous post of the OOPS in
>>>>>> generic_delete_inode, we have now found a gigantic memory leak in Linux
>>>>>> 2.6.
>>>>>> [789]. The scenario is the same:
>>>>>>
>>>>>> File system: EXT3
>>>>>> Unpack and delete linux-2.6.8.1.tar.bz2 with this Bash while loop:
>>>>>>
>>>>>> let "i = 0"
>>>>>> while [ "$i" -lt 10 ]; do
>>>>>> tar jxf linux-2.6.8.1.tar.bz2;
>>>>>> rm -fr linux-2.6.8.1;
>>>>>> let "i = i + 1"
>>>>>> done
>>>>>>
>>>>>> When the loop has completed, the system use 124 MB memory more _each_
>>>>>> time....
>>>>>> so it is pretty easy to make a denial-of-service attack :-(
>>>>>
>>>>
>>>>
>>>>
>>>> Do something like this with your favorite kernel version.....
>>>>
>>>> while true ; do tar -xzf linux-2.6.9.tar.gz ; rm -rf linux-2.6.9 ; vmstat
>>>> ; done
>>>>
>>>> You can watch this for as long as you want. If there is no other
>>>> activity, the values reported by vmstat remain, on the average, stable.
>>>> If you throw in a `sync` command, the values rapidly converge to
>>>> little memory usage as the disk-data gets flused to disk.
>>>
>>> The problem is, that the free memory reported by vmstat is decresing by
>>> 124mb for each 10-iterations....
>>>
>>> The allocated memory does not get freed even if the system has been left
>>> alone for three hours!
>>>
>>
>> Yes. So? Why would it be freed? It's left how it was until it
>> is needed. Freeing it would waste CPU cycles.
>
> Okay :-) So it looks like two of you says we have been mistaken :-D (and the
> behaviour has been changed since linux-2.4)
>
> Anyway - How does this work in practice? Does the file system implementation
> use a wrapper for kfree or?
> Is there any way to force instant free of kernel memory - when freed? Else it
> is quite hard testing for possible memory leaks in our Umbrella kernel module
> ... :-/
>
>
> Best regards,
>

First, you can always execute sync() and flush most of the file-buffers
to disk. This frees up a lot.

In the kernel....
If you are doing a lot of kmalloc() allocation and free(), you
can write out the pointer values using printk(). I use '0' before
such ... printk("0 %p\n", ptr); do `dmesg | sort >xxx.xxx`. Now
you can look at the file and see the sorted pointer values. If
they repeat, chances are pretty good that you are not leaking
memory.

In user space...
Periodically look at the break address.
If it keeps going up, you may have a leak. If it's stable
you probably are okay.

The only sure way of detecting a memory leak is to use
some substitute code (maybe a macro) that substitutes
for (intercepts) the allocator and deallocator. It eventually
executes the allocator and deallocator after saving information
somewhere you define (array, file, etc). You can sort that
information and determine if there are as many (k)mallocs() as
there are for (z)frees() (for instance) of the same pointer values.


Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 GrumpyMips).
98.36% of all statistics are fiction.
\
 
 \ /
  Last update: 2005-03-22 14:07    [W:0.052 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site