public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* RE: UBI memory leak after creating and removing volumes
@ 2009-02-17 14:33 John.Smith
  2009-02-17 15:24 ` Artem Bityutskiy
  2009-02-17 15:39 ` Artem Bityutskiy
  0 siblings, 2 replies; 8+ messages in thread
From: John.Smith @ 2009-02-17 14:33 UTC (permalink / raw)
  To: dedekind; +Cc: linux-mtd

Artem Bityutskiy wrote:
>
> On Tue, 2009-02-17 at 12:01 +0000, John.Smith@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

^ permalink raw reply	[flat|nested] 8+ messages in thread
* UBI memory leak after creating and removing volumes
@ 2009-02-17 12:01 John.Smith
  2009-02-17 12:23 ` Artem Bityutskiy
  0 siblings, 1 reply; 8+ messages in thread
From: John.Smith @ 2009-02-17 12:01 UTC (permalink / raw)
  To: linux-mtd


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:

( cat /proc/meminfo ; 
  i=0; 
  while [ ${i} -lt 100 ] ; do 
     ubimkvol -d 0 -n 15 -N ubi-vol -s 1000 ; 
     ubirmvol -d 0 -n 15 ; 
     i=$((i+1)) ; 
  done ; 
  cat /proc/meminfo ) | grep Slab

which shows slab memory increasing 80KB over 100 iterations.

Also:
 ( cat /proc/meminfo ; 
   i=0; 
   while [ ${i} -lt 100 ] ; do 
      ubimkvol -d 0 -n 15 -N ubi-vol1 -s 1000 ; 
      ubimkvol -d 0 -n 16 -N ubi-vol2 -s 1000 ; 
      ubirmvol -d 0 -n 16 ; 
      ubirmvol -d 0 -n 15 ; 
      i=$((i+1)) ; 
   done ; cat /proc/meminfo ) | grep Slab

which shows slab memory increasing 300KB for 100 iterations.

I encountered the second case first, and have explored. It seems there
is a single elevator queue associated with the mtdblock devices. The
sysfs items associated with the queue of the first ubi volume are not
being released.

I see a related effect by creating two ubi volumes, deleting the
first, and inspecting the entries in the /sys/block/mtdblock*
directories:

/ # ubimkvol -d 0 -n 15 -N ubi-vol-1 -s 10000
/ # ls  /sys/block/mtdblock7
dev        holders    queue      range      removable  ...

/ # ubimkvol -d 0 -n 16 -N ubi-vol-2 -s 10000
/ # ls  /sys/block/mtdblock8
dev        holders    queue      range      removable  ...

/ # ubirmvol -d 0 -n 15
/ # ls  /sys/block/mtdblock8
dev        holders    range      removable  ...

Notice that the "queue" entry has disappeared.

Have I introduced problems mixing and matching the kernel?

Can you give any hints as to how to fix the leak? I am guessing that
there are multiple copies of data structures associated with the
elevator queue, and this is a bit wrong.  But updating the kernel as a
whole is not really viable.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-02-21 22:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-17 14:33 UBI memory leak after creating and removing volumes John.Smith
2009-02-17 15:24 ` Artem Bityutskiy
2009-02-17 15:24   ` Artem Bityutskiy
2009-02-17 22:02   ` John Smith
2009-02-17 15:39 ` Artem Bityutskiy
2009-02-21 21:30   ` John Smith
  -- strict thread matches above, loose matches on Subject: below --
2009-02-17 12:01 John.Smith
2009-02-17 12:23 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox