From: Yu Kuai yukuai3@huawei.com
If cfqq is merged with another cfqq(assume that no cfqq is merged to this cfqq) and then user thread is moved to another cgroup, then check_blkcg_changed() will set cic->cfqq[1] to NULL. However, this cfqq is still merged and no one will referece this cfqq, which will cause following kmemleak:
comm "cgexec", pid 2541110, jiffies 4317578508 (age 5728.064s) hex dump (first 32 bytes): 03 00 00 00 90 03 00 00 80 8d 0f be 20 80 ff ff ............ ... a0 16 c6 a1 21 80 ff ff 00 00 00 00 00 00 00 00 ....!........... backtrace: [<0000000071d2775e>] kmem_cache_alloc_node+0x13c/0x660 [<00000000e827e6fd>] cfq_get_queue+0x318/0x6f0 [<00000000945249ee>] cfq_set_request+0x724/0xe38 [<00000000af64d5a9>] elv_set_request+0x84/0xd0 [<0000000047344f0d>] __get_request+0x970/0xf90 [<00000000d016bd51>] get_request+0x278/0x970 [<0000000052512d36>] blk_queue_bio+0x278/0xcc0 [<0000000085282101>] generic_make_request+0x3c0/0x778 [<0000000089f69c24>] submit_bio+0xdc/0x408 [<00000000748509ae>] ext4_mpage_readpages+0xc84/0x13b8 [ext4] [<0000000078bfc705>] ext4_readpages+0x80/0xc0 [ext4] [<00000000317f2ed7>] read_pages+0xd0/0x610 [<00000000e7ab01d2>] __do_page_cache_readahead+0x36c/0x430 [<0000000071df2285>] ondemand_readahead+0x24c/0x6b0 [<00000000124a824a>] page_cache_sync_readahead+0x188/0x448 [<00000000bca561ae>] generic_file_buffered_read+0x648/0x2b58 unreferenced object 0xffffa028411d4720 (size 240):
Fix the problem by put cooperator in check_blkcg_changed(), so that old cfqq can be freed.
Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/cfq-iosched.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c index 2eb87444b157..88bae553ece3 100644 --- a/block/cfq-iosched.c +++ b/block/cfq-iosched.c @@ -3778,6 +3778,7 @@ static void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio) if (cfqq) { cfq_log_cfqq(cfqd, cfqq, "changed cgroup"); cic_set_cfqq(cic, NULL, true); + cfq_put_cooperator(cfqq); cfq_put_queue(cfqq); }