UBI memory leak after creating and removing volumes

John.Smith at pace.com John.Smith at pace.com
Tue Feb 17 09:33:20 EST 2009


Artem Bityutskiy wrote:
>
> On Tue, 2009-02-17 at 12:01 +0000, John.Smith at pace.com wrote:
> 
> > Hello, 
> 
> > I am using a 2.6.18 Kernel, patched with MTD from Kernel 2.6.21, and
> > UBI from the mainline kernel a few days later on 1 May 2007.  The
> > whole is running on an embedded MIPS device.
> >
> > I have NAND, and UBI, and gluebi, and jffs2.  I use jffs2, mounted
> > on an mtdblock device. Broadly, it all works.
> > 
> > I am experiencing a memory leak revealed in recent stress tests.
The
> > stress tests create and delete many UBI volumes, and are are broadly
> > equivelent to the following:
> 
> Can you please enable /proc/slab_allocators - it tracks all allocators
> and if we have a leak - it may point to the function which is guilty.
> 
> Recompile the kernel, and you will have a nice instrumentation to find
> memory leak - the /proc/slab_allocators file. Please, play with this.

After 0, 1000 and 2000 iterations of a test of creating 2 UBI volumes,
then removing them, /proc/slab_allocators shows these three items
obviously increasing:

inode_cache: 327 alloc_inode+0x140/0x148         
inode_cache: 3329 alloc_inode+0x140/0x148        
inode_cache: 6329 alloc_inode+0x140/0x148        
(3 objects per iteration)

sysfs_dir_cache: 1402 sysfs_new_dirent+0x2c/0xa0 
sysfs_dir_cache: 15402 sysfs_new_dirent+0x2c/0xa0
sysfs_dir_cache: 29402 sysfs_new_dirent+0x2c/0xa0
(14 objects per iteration)

dentry_cache: 669 d_alloc+0x30/0x214             
dentry_cache: 3823 d_alloc+0x30/0x214            
dentry_cache: 6823 d_alloc+0x30/0x214            
(3 objects per iteration)

I don't know how to track these things down fully. But I 
believe they relate to the elevator queue.

I added some printks to elv_register_queue and __elv_unregister_queue
so the functions are like:

int elv_register_queue(struct request_queue *q)
{
   elevator_t *e = q->elevator;

   printk("elv_register_queue: e->kobj.dentry at %p val %p\n", 
          &e->kobj.dentry, e->kobj.dentry );
 
   kobject_add(&e->kobj);
   /* Do more stuff */  

   printk("elv_register_queue: e->kobj.dentry at %p val %p AFTER\n", 
          &e->kobj.dentry, e->kobj.dentry );
}

static void __elv_unregister_queue(elevator_t *e)
{
   printk("__elv_unregister_queue: e->kobj.dentry at %p val %p\n", 
          &e->kobj.dentry, e->kobj.dentry );

   kobject_uevent(&e->kobj, KOBJ_REMOVE);
   kobject_del(&e->kobj);

   printk("__elv_unregister_queue: e->kobj.dentry at %p val %p AFTER\n",

          &e->kobj.dentry, e->kobj.dentry );
}

When creating and deleting volumes, e->kobj.dentry is always at the
same address. 

After the register_queue operation, e->kobj.dentry points to a new
dentry. So e->kobj.dentry is getting over-written.

After the unregister_queue operation, e->kobj.dentry is NULL.  The
kobject_del calls sysfs_remove_dir which either does or does not
delete memory according to whether e->kobj.dentry is NULL. So
the second ubi fails.

But I don't know what to do plug the leak.

Regards,
John

John Smith
 
This E-mail and any attachments hereto are strictly confidential and intended solely for the addressee. If you are not the intended addressee please notify the sender by return and delete the message. You must not disclose, forward or copy this E-mail or attachments to any third party without the prior consent of the sender. Pace plc is registered in England and Wales (Company no. 1672847) and our Registered Office is at Victoria Road, Saltaire, West Yorkshire, BD18 3LF, UK. Tel +44 (0) 1274 532000 Fax +44 (0) 1274 532010. <http://www.pace.com>
Save where otherwise agreed in writing between you and Pace (i) all orders for goods and/or services placed by you are made pursuant to Pace's standard terms and conditions of sale which may have been provided to you, or in any event are available at http://www.pace.com/uktcsale.pdf (ii) all orders for goods and/or services placed by Pace are subject to Pace's standard terms and conditions of purchase which may have been provided to you, or in any event are available at http://www.pace.com/uktcpurch.pdf. All other inconsistent terms in any other documentation including without limitation any purchase order, reschedule instruction, order acknowledgement, delivery note or invoice are hereby excluded.



This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com



More information about the linux-mtd mailing list