From: tang.junhui@zte.com.cn
To: colyli@suse.de
Cc: mlyle@lyle.org, linux-bcache@vger.kernel.org,
linux-block@vger.kernel.org, tang.junhui@zte.com.cn
Subject: Re: Re: [PATCH v1 05/10] bcache: stop dc->writeback_rate_update if cache set is stopping
Date: Thu, 4 Jan 2018 02:54:53 +0800 [thread overview]
Message-ID: <1515005693-7113-1-git-send-email-tang.junhui@zte.com.cn> (raw)
From: Tang Junhui <tang.junhui@zte.com.cn>
Hi Coly,
>It is about an implicit and interesting ordering, a simple patch with a
>lot detail behind. Let me explain why it's safe,
>
>- cancel_delayed_work_sync() is called in bcache_device_detach() when
>dc->count is 0. But cancel_delayed_work_sync() is called before
>closure_put(&d->c->caching) in bcache_device_detach().
>
>- After closure_put(&d->c->caching) called in bcache_device_detach(),
>refcount of c->caching becomes 0, and cache_set_flush() set in
>__cache_set_unregister() continue to execute.
>
>- See continue_at() and closure_put_after_sub(), after c->caching
>refoucnt reaches 0, and c->caching->fn gets called, closure_put(parent)
>will be called. Here the parent of c->caching is c->cl, so refcount of
>c->cl will reach 0, and closure_put_after_sub() will be called again for
>c->cl and call its cl->fn which is cache_set_free(). It is set in
>bch_cache_set_alloc().
>
>- So before closure_put(&d->c->caching) is called in
>bcache_device_detach(), cache_set_flush() in __cache_set_unregister()
>won't be executed and memory of cache_set won't be freed.
>
>Now back to delayed worker routine update_writeback_rate(), I check
>c->flags inside it, in this moment cancel_delayed_work_sync() is still
>waiting for update_writeback_rate() to exit, so refcount of c->caching
>is still hold and cache set memory will only be freed after
>cancel_delayed_work_sync() returns and refcount of c->caching dropped.
>
>And in cached_dev_free(), bcache_device_free() and
>kobject_put(&dc->disk.kobj) are called after cancel_delayed_work_sync()
>returns. Therefore when update_writeback_rate() is executing and
>accessing c->flgas inside, memory of cache_set, bcache_device and
>cached_dev are all there.
OK, I got your mean. It is safe run work update_writeback_rate when
cancel_delayed_work_sync() is called, but it is not safe to re-arm itself
to workqueue again.
So, the first judgement "if (test_bit(CACHE_SET_STOPPING, &c->flags))"
is not very nessary, we only need the second one to prevent the work
from re-arming itself to workqueue.
Thanks,
Tang Junhui
next reply other threads:[~2018-01-04 8:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-03 18:54 tang.junhui [this message]
2018-01-04 9:05 ` [PATCH v1 05/10] bcache: stop dc->writeback_rate_update if cache set is stopping Coly Li
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=1515005693-7113-1-git-send-email-tang.junhui@zte.com.cn \
--to=tang.junhui@zte.com.cn \
--cc=colyli@suse.de \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=mlyle@lyle.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