* [PATCH] UBI: fix memory leak when use fastmap
@ 2013-04-16 8:53 wang.bo116
2013-04-28 22:12 ` richard -rw- weinberger
0 siblings, 1 reply; 4+ messages in thread
From: wang.bo116 @ 2013-04-16 8:53 UTC (permalink / raw)
To: artem.bityutskiy, richard.weinberger
Cc: linux-mtd, linux-kernel, liu.dong3, cui.yunfeng, wang.bo116
Hello,
Sorry, there is still something wrong with the previous patch's
format, try to submit it again. When use ubi fastmap, there is a memory
leak which will make destroy_ai() fail to free the slab alloced in
scan_fast(). The following patch fix this problem by use a temporary
"ubi_attach_info" variable in scan_fast().
diff -uprN a/linux-3.9-rc6/drivers/mtd/ubi/attach.c
b/linux-3.9-rc6/drivers/mtd/ubi/attach.c
--- a/linux-3.9-rc6/drivers/mtd/ubi/attach.c 2013-04-08
03:49:54.000000000 +0000
+++ b/linux-3.9-rc6/drivers/mtd/ubi/attach.c 2013-04-16
03:22:47.343750000 +0000
@@ -1212,6 +1212,30 @@ static void destroy_ai(struct ubi_attach
kfree(ai);
}
+static struct ubi_attach_info *alloc_ai(const char *slab_name)
+{
+ struct ubi_attach_info *ai;
+
+ ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
+ if (!ai)
+ return ai;
+
+ INIT_LIST_HEAD(&ai->corr);
+ INIT_LIST_HEAD(&ai->free);
+ INIT_LIST_HEAD(&ai->erase);
+ INIT_LIST_HEAD(&ai->alien);
+ ai->volumes = RB_ROOT;
+ ai->aeb_slab_cache = kmem_cache_create(slab_name,
+ sizeof(struct ubi_ainf_peb),
+ 0, 0, NULL);
+ if (!ai->aeb_slab_cache) {
+ kfree(ai);
+ ai = NULL;
+ }
+
+ return ai;
+}
+
/**
* scan_all - scan entire MTD device.
* @ubi: UBI device description object
@@ -1315,8 +1339,13 @@ static int scan_fast(struct ubi_device *
int err, pnum, fm_anchor = -1;
unsigned long long max_sqnum = 0;
+ struct ubi_attach_info *fm_temp_ai = NULL;
err = -ENOMEM;
+ fm_temp_ai = alloc_ai("ubi_scan_fastmap_slab_cache");
+ if (!fm_temp_ai)
+ goto out;
+
ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
if (!ech)
goto out;
@@ -1331,7 +1360,7 @@ static int scan_fast(struct ubi_device *
cond_resched();
dbg_gen("process PEB %d", pnum);
- err = scan_peb(ubi, ai, pnum, &vol_id, &sqnum);
+ err = scan_peb(ubi, fm_temp_ai, pnum, &vol_id, &sqnum);
if (err < 0)
goto out_vidh;
@@ -1343,6 +1372,7 @@ static int scan_fast(struct ubi_device *
ubi_free_vid_hdr(ubi, vidh);
kfree(ech);
+ destroy_ai(fm_temp_ai);
if (fm_anchor < 0)
return UBI_NO_FASTMAP;
@@ -1351,6 +1381,7 @@ static int scan_fast(struct ubi_device *
out_vidh:
ubi_free_vid_hdr(ubi, vidh);
+ destroy_ai(fm_temp_ai);
out_ech:
kfree(ech);
out:
@@ -1359,29 +1390,6 @@ out:
#endif
-static struct ubi_attach_info *alloc_ai(const char *slab_name)
-{
- struct ubi_attach_info *ai;
-
- ai = kzalloc(sizeof(struct ubi_attach_info), GFP_KERNEL);
- if (!ai)
- return ai;
-
- INIT_LIST_HEAD(&ai->corr);
- INIT_LIST_HEAD(&ai->free);
- INIT_LIST_HEAD(&ai->erase);
- INIT_LIST_HEAD(&ai->alien);
- ai->volumes = RB_ROOT;
- ai->aeb_slab_cache = kmem_cache_create(slab_name,
- sizeof(struct ubi_ainf_peb),
- 0, 0, NULL);
- if (!ai->aeb_slab_cache) {
- kfree(ai);
- ai = NULL;
- }
-
- return ai;
-}
/**
* ubi_attach - attach an MTD device.
@@ -1419,7 +1427,7 @@ int ubi_attach(struct ubi_device *ubi, i
return -ENOMEM;
}
- err = scan_all(ubi, ai, UBI_FM_MAX_START);
+ err = scan_all(ubi, ai, 0);
}
}
#else
diff -uprN a/linux-3.9-rc6/drivers/mtd/ubi/fastmap.c
b/linux-3.9-rc6/drivers/mtd/ubi/fastmap.c
--- a/linux-3.9-rc6/drivers/mtd/ubi/fastmap.c 2013-04-08
03:49:54.000000000 +0000
+++ b/linux-3.9-rc6/drivers/mtd/ubi/fastmap.c 2013-04-16
03:22:17.468750000 +0000
@@ -552,21 +552,8 @@ static int ubi_attach_fastmap(struct ubi
INIT_LIST_HEAD(&used);
INIT_LIST_HEAD(&free);
INIT_LIST_HEAD(&eba_orphans);
- INIT_LIST_HEAD(&ai->corr);
- INIT_LIST_HEAD(&ai->free);
- INIT_LIST_HEAD(&ai->erase);
- INIT_LIST_HEAD(&ai->alien);
- ai->volumes = RB_ROOT;
ai->min_ec = UBI_MAX_ERASECOUNTER;
- ai->aeb_slab_cache = kmem_cache_create("ubi_ainf_peb_slab",
- sizeof(struct ubi_ainf_peb),
- 0, 0, NULL);
- if (!ai->aeb_slab_cache) {
- ret = -ENOMEM;
- goto fail;
- }
-
fmsb = (struct ubi_fm_sb *)(fm_raw);
ai->max_sqnum = fmsb->sqnum;
fm_pos += sizeof(struct ubi_fm_sb);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] UBI: fix memory leak when use fastmap
2013-04-16 8:53 [PATCH] UBI: fix memory leak when use fastmap wang.bo116
@ 2013-04-28 22:12 ` richard -rw- weinberger
2013-04-29 16:08 ` Placing ext3 journal on mtd device d.soumyajit
0 siblings, 1 reply; 4+ messages in thread
From: richard -rw- weinberger @ 2013-04-28 22:12 UTC (permalink / raw)
To: wang.bo116; +Cc: artem.bityutskiy, linux-mtd, LKML, liu.dong3, cui.yunfeng
Hi!
On Tue, Apr 16, 2013 at 10:53 AM, <wang.bo116@zte.com.cn> wrote:
> Hello,
> Sorry, there is still something wrong with the previous patch's
> format, try to submit it again. When use ubi fastmap, there is a memory
> leak which will make destroy_ai() fail to free the slab alloced in
> scan_fast(). The following patch fix this problem by use a temporary
> "ubi_attach_info" variable in scan_fast().
Thanks a lot for your patch!
Did you test it well?
We need to make sure that it does the right thing for the following cases:
1. fastmap disabled, attaching a non-fastmap volume
1. fastmap disabled, attaching a fastmap volume
3. fastmap enabled, attaching a non-fastmap volume
4. fastmap enablled, attaching a fastmap volume
--
Thanks,
//richard
^ permalink raw reply [flat|nested] 4+ messages in thread
* Placing ext3 journal on mtd device
2013-04-28 22:12 ` richard -rw- weinberger
@ 2013-04-29 16:08 ` d.soumyajit
2013-04-29 16:25 ` richard -rw- weinberger
0 siblings, 1 reply; 4+ messages in thread
From: d.soumyajit @ 2013-04-29 16:08 UTC (permalink / raw)
To: richard -rw- weinberger
Cc: wang.bo116, liu.dong3, artem.bityutskiy, linux-mtd, LKML, cui.yunfeng
Hi,
In Ext3 performance can be improved by placing journal on SSD. I am able
to place ext3 journal on an external device. Can you please help me
placing ext3 journal on mtd device.
Thanks in Advance!
Soumyajit
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Placing ext3 journal on mtd device
2013-04-29 16:08 ` Placing ext3 journal on mtd device d.soumyajit
@ 2013-04-29 16:25 ` richard -rw- weinberger
0 siblings, 0 replies; 4+ messages in thread
From: richard -rw- weinberger @ 2013-04-29 16:25 UTC (permalink / raw)
To: d.soumyajit
Cc: wang.bo116, liu.dong3, artem.bityutskiy, linux-mtd, LKML, cui.yunfeng
On Mon, Apr 29, 2013 at 6:08 PM, <d.soumyajit@iitg.ernet.in> wrote:
> Hi,
>
> In Ext3 performance can be improved by placing journal on SSD. I am able
> to place ext3 journal on an external device. Can you please help me
> placing ext3 journal on mtd device.
*very* bad idea.
--
Thanks,
//richard
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-04-29 16:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-16 8:53 [PATCH] UBI: fix memory leak when use fastmap wang.bo116
2013-04-28 22:12 ` richard -rw- weinberger
2013-04-29 16:08 ` Placing ext3 journal on mtd device d.soumyajit
2013-04-29 16:25 ` richard -rw- weinberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®