public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: nardelli <jnardelli@infosciences.com>
To: Ian Abbott <abbotti@mev.co.uk>
Cc: linux-kernel@vger.kernel.org, linux-usb-devel@lists.sourceforge.net
Subject: Re: [PATCH] Memory leak in visor.c and ftdi_sio.c
Date: Fri, 04 Jun 2004 13:25:22 -0400	[thread overview]
Message-ID: <40C0B082.5020509@infosciences.com> (raw)
In-Reply-To: <c9q8a6$hga$1@sea.gmane.org>

Ian Abbott wrote:
> On 04/06/2004 15:59, nardelli wrote:
> 
>> Note that I have not verified any of the below on
>> hardware associated with drivers/usb/serial/ftdi_sio.c,
>> only with drivers/usb/serial/visor.c.  If anyone has
>> hardware for this device, I would appreciate your comments.
>>
>> A memory leak occurs in both drivers/usb/serial/ftdi_sio.c
>> and drivers/usb/serial/visor.c when the usb device is
>> unplugged while data is being written to the device.  This
>> patch should clear that up.
> 
> 
> The change to ftdi_sio.c looks correct to me.
> 
> I made the original change to ftdi_sio.c to allocate the write urbs and 
> their transfer buffers dynamically (instead of using a preallocated 
> pool) and I copied that technique from visor.c!
> 
> A related problem with the current implementation is that is easy to run 
> out of memory by running something similar to this:
> 
>  # cat /dev/zero > /dev/ttyUSB0
> 
> That affects both the ftdi_sio and visor drivers.
> 

I believe that I have seen something similiar, but possibly not identical.
When writing alot (I used /dev/urandom instead of /dev/zero), it looks
like a very large percentage of buffers that are being allocated during
writes are not being freed.  One test I did indicated that 95% of buffers
were not being freed!  I briefly mention some info in
http://lkml.org/lkml/2004/5/25/72, but I wasn't going to go into detail
until I'd found out more info, and verified that my test procedure was
adequate.

My test is pretty simple, print out the address every time a buffer is
allocated, and print out the address every time a buffer is freed.  In
this case there is only one location where it is being allocated, but 3
(4 with patch I submitted) where it is being freed.  It's simply a matter
of running a command like the one below, and looking to see which addresses
are in there an odd number of times (i.e. allocated, but not freed).  Not a
perfect test, but hopefully not embarrassingly bad either.

cat /var/log/messages | egrep 'Allocated|Freed' | tr -s ' ' | cut -d ' ' -f 7 | sort | uniq -c | sort -n

I'm not sure why such a high percentage would not be freed, but hopefully I'll
figure it out in the next week or two, time permitting.

-- 
Joe Nardelli
jnardelli@infosciences.com

  reply	other threads:[~2004-06-04 17:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-04 14:59 [PATCH] Memory leak in visor.c and ftdi_sio.c nardelli
2004-06-04 16:34 ` Ian Abbott
2004-06-04 17:25   ` nardelli [this message]
2004-06-04 18:04   ` Pete Zaitcev
2004-06-04 23:16   ` [linux-usb-devel] " Peter Horton
2004-06-05  0:18   ` Greg KH
2004-06-07  9:58     ` Ian Abbott
2004-06-07 14:19     ` nardelli
2004-06-07 15:43       ` Richard B. Johnson
2004-06-07 15:56         ` nardelli
2004-06-04 18:12 ` Greg KH
2004-06-04 18:47   ` nardelli
2004-06-04 22:02     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40C0B082.5020509@infosciences.com \
    --to=jnardelli@infosciences.com \
    --cc=abbotti@mev.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox