From: Gi-Oh Kim <gi-oh.kim@profitbricks.com>
To: Roman Pen <roman.penyaev@profitbricks.com>
Cc: Tejun Heo <tj@kernel.org>, Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] block: fix module reference leak on put_disk() call for cgroups throttle
Date: Wed, 3 Feb 2016 11:40:13 +0100 [thread overview]
Message-ID: <56B1D90D.9040502@profitbricks.com> (raw)
In-Reply-To: <1454338315-13465-2-git-send-email-roman.penyaev@profitbricks.com>
On 01.02.2016 15:51, Roman Pen wrote:
> get_disk(),get_gendisk() calls have non explicit side effect: they
> increase the reference on the disk owner module.
>
> The following is the correct sequence how to get a disk reference and
> to put it:
>
> disk = get_gendisk(...);
>
> /* use disk */
>
> owner = disk->fops->owner;
> put_disk(disk);
> module_put(owner);
>
> fs/block_dev.c is aware of this required module_put() call, but f.e.
> blkg_conf_finish(), which is located in block/blk-cgroup.c, does not put
> a module reference. To see a leakage in action cgroups throttle config
> can be used. In the following script I'm removing throttle for /dev/ram0
> (actually this is NOP, because throttle was never set for this device):
>
> # lsmod | grep brd
> brd 5175 0
> # i=100; while [ $i -gt 0 ]; do echo "1:0 0" > \
> /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device; i=$(($i - 1)); \
> done
> # lsmod | grep brd
> brd 5175 100
>
> Now brd module has 100 references.
I hope this patch would be merged into stable versions.
I've tested the patch with v3.12.45 on my server.
Before apply the patch, reference count was leaked.
# lsmod | grep loop
loop 16091 0
# echo "7:0 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
# lsmod | grep loop
loop 16091 1
# echo "7:0 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
# lsmod | grep loop
loop 16091 2
# echo "7:0 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
# lsmod | grep loop
loop 16091 3
# echo "7:0 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
# lsmod | grep loop
loop 16091 4
After apply the patch, reference count was still:
# lsmod | grep loop
loop 19171 0
# echo "7:0 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
# lsmod | grep loop
loop 19171 0
# echo "7:0 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
# lsmod | grep loop
loop 19171 0
# echo "7:0 1048576" > /sys/fs/cgroup/blkio/blkio.throttle.read_bps_device
# lsmod | grep loop
loop 19171 0
--
Best regards,
Gi-Oh Kim
next prev parent reply other threads:[~2016-02-03 10:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-01 14:51 [PATCH 0/4] introduce new put_getdisk() call Roman Pen
2016-02-01 14:51 ` [PATCH 1/4] block: fix module reference leak on put_disk() call for cgroups throttle Roman Pen
2016-02-03 10:40 ` Gi-Oh Kim [this message]
2016-02-01 14:51 ` [PATCH 2/4] block: introduce new call put_gendisk() in genhd.c Roman Pen
2016-02-01 14:51 ` [PATCH 3/4] block,fs: switch to a new put_gendisk() call Roman Pen
2016-02-01 14:51 ` [PATCH 4/4] hibernate: fix disk and module leak on successfull resume Roman Pen
2016-02-03 1:37 ` Rafael J. Wysocki
2016-02-01 17:16 ` [PATCH 0/4] introduce new put_getdisk() call Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56B1D90D.9040502@profitbricks.com \
--to=gi-oh.kim@profitbricks.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roman.penyaev@profitbricks.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).