Query regarding Kmemleak

Smital Desai Smital.Desai at lntinfotech.com
Wed Feb 1 14:33:11 EST 2012


_______________________
From: Viral Mehta [viral.vkm at gmail.com]
Sent: Wednesday, February 01, 2012 10:49 PM
To: Smital Desai
Cc: Jeff Haran; Kernel Newbies
Subject: Re: Query regarding Kmemleak

Hi,

On Tue, Jan 31, 2012 at 8:47 PM, Smital Desai
<Smital.Desai at lntinfotech.com> wrote:
>>
>>          I am  just trying to understand Kmemleak support.
>>
>>          In a test program ,  allocating some memory using and vmalloc
> () and
>> freeing it in exit () routine.
>>          But when i run a kmemleak , It reports this as a leak.
>>
>>          But isn't it a generic reuirement to allocate something for
> the lifetime of
>> the module and free when we remove the module. ?   Can somebody
>> explain ?

Can you give a real time example ?

More specifically, why a driver needs to allocate virtual memory
when still there is no user for that driver.

If driver is just loaded at boot time and unloaded at shutdown,
you cant keep memory allocated w/o any use.

>>>[ Smital ] :    Well , If you are talking about only this example , I mentioned that it was a test program :-)  and i agree on not allocating memory if nobody is going to use it. :-)
        I am not only talking about allocations done by vmalloc ()  but basically any allocation .

>>>Lets take an example   "drivers/video/w100fb.c"

>>>Driver allocates  in   w100fb_probe ()

       info->pseudo_palette = kmalloc(sizeof (u32) * MAX_PALETTES, GFP_KERNEL);
        if (!info->pseudo_palette) {
                err = -ENOMEM;
                goto out;
        }

>>>and releases this memory  in  w100fb_remove ()
>>> kfree(info->pseudo_palette);


>>>      So this memory remained allocated for the lifetime of the driver.
>>>      So basically i am talking about allocations done in   foo_probe ()  and freeing done in foo_remove ()


>>>      One more need for such allocations could be driver implementing internal ring buffer mechanism for it's operation , so in such cases
>>>      the allocation for ring buffer will be done only once and will remain allocated for driver's life time.



Howsoever, false positives are possible in kmemleak case,
See,
http://lwn.net/Articles/187979/

"There are various other special cases which must be handled. For
example, memory obtained from vmalloc() will be pointed to by the
memory allocation code itself, but might still be leaked. In other
cases, memory is allocated which cannot be found by the scanning
algorithm; a number of special annotations are added to the kernel to
suppress the resulting false positive reports. The detector can also
be fooled by pointers which are left behind in disused memory, or by
random data which happens to look like a pointer to an allocated
block; in these cases, false-negatives will result. "



--
Thanks,
Viral Mehta

The contents of this e-mail and any attachment(s) may contain confidential or privileged information for the intended recipient(s). Unintended recipients are prohibited from taking action on the basis of information in this e-mail and  using or disseminating the information,  and must notify the sender and delete it from their system. L&T Infotech will not accept responsibility or liability for the accuracy or completeness of, or the presence of any virus or disabling code in this e-mail"



More information about the Kernelnewbies mailing list