Skip to content

Commit 813e693

Browse files
htejunaxboe
authored andcommitted
blk-iolatency: Fix memory leak on add_disk() failures
When a gendisk is successfully initialized but add_disk() fails such as when a loop device has invalid number of minor device numbers specified, blkcg_init_disk() is called during init and then blkcg_exit_disk() during error handling. Unfortunately, iolatency gets initialized in the former but doesn't get cleaned up in the latter. This is because, in non-error cases, the cleanup is performed by del_gendisk() calling rq_qos_exit(), the assumption being that rq_qos policies, iolatency being one of them, can only be activated once the disk is fully registered and visible. That assumption is true for wbt and iocost, but not so for iolatency as it gets initialized before add_disk() is called. It is desirable to lazy-init rq_qos policies because they are optional features and add to hot path overhead once initialized - each IO has to walk all the registered rq_qos policies. So, we want to switch iolatency to lazy init too. However, that's a bigger change. As a fix for the immediate problem, let's just add an extra call to rq_qos_exit() in blkcg_exit_disk(). This is safe because duplicate calls to rq_qos_exit() become noop's. Signed-off-by: Tejun Heo <[email protected]> Reported-by: [email protected] Cc: Josef Bacik <[email protected]> Cc: Linus Torvalds <[email protected]> Fixes: d706751 ("block: introduce blk-iolatency io controller") Cc: [email protected] # v4.19+ Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 85c5019 commit 813e693

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

block/blk-cgroup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "blk-cgroup.h"
3434
#include "blk-ioprio.h"
3535
#include "blk-throttle.h"
36+
#include "blk-rq-qos.h"
3637

3738
/*
3839
* blkcg_pol_mutex protects blkcg_policy[] and policy [de]activation.
@@ -1322,6 +1323,7 @@ int blkcg_init_disk(struct gendisk *disk)
13221323
void blkcg_exit_disk(struct gendisk *disk)
13231324
{
13241325
blkg_destroy_all(disk);
1326+
rq_qos_exit(disk->queue);
13251327
blk_throtl_exit(disk);
13261328
}
13271329

0 commit comments

Comments
 (0)