Skip to content

Commit 5c4a234

Browse files
committed
blk: support bdev_async_discard_threads == 0
Signed-off-by: Matt Vandermeulen <[email protected]>
1 parent 671e126 commit 5c4a234

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/blk/kernel/KernelDevice.cc

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -778,30 +778,28 @@ void KernelDevice::_discard_thread(uint64_t tid)
778778
dout(10) << __func__ << " thread " << tid << " finish" << dendl;
779779
}
780780

781-
int KernelDevice::_queue_discard(interval_set<uint64_t> &to_release)
781+
// this is private and is expected that the caller checks that discard
782+
// threads are running via _discard_started()
783+
void KernelDevice::_queue_discard(interval_set<uint64_t> &to_release)
782784
{
783-
// if bdev_async_discard enabled on the fly, discard_thread is not started here, fallback to sync discard
784-
if (!_discard_started())
785-
return -1;
786-
787785
if (to_release.empty())
788-
return 0;
786+
return;
789787

790788
std::lock_guard l(discard_lock);
791789
discard_queued.insert(to_release);
792790
discard_cond.notify_one();
793-
return 0;
794791
}
795792

796-
// return true only if _queue_discard succeeded, so caller won't have to do alloc->release
797-
// otherwise false
793+
// return true only if discard was queued, so caller won't have to do
794+
// alloc->release, otherwise return false
798795
bool KernelDevice::try_discard(interval_set<uint64_t> &to_release, bool async)
799796
{
800797
if (!support_discard || !cct->_conf->bdev_enable_discard)
801798
return false;
802799

803-
if (async) {
804-
return 0 == _queue_discard(to_release);
800+
if (async && _discard_started()) {
801+
_queue_discard(to_release);
802+
return true;
805803
} else {
806804
for (auto p = to_release.begin(); p != to_release.end(); ++p) {
807805
_discard(p.get_start(), p.get_len());
@@ -1528,13 +1526,19 @@ void KernelDevice::handle_conf_change(const ConfigProxy& conf,
15281526
// Decrease? Signal threads after telling them to stop
15291527
dout(10) << __func__ << " stopping " << (oldval - newval) << " existing discard threads" << dendl;
15301528

1531-
// Signal the last threads to quit, and stop tracking them
1532-
for(uint64_t i = oldval - 1; i >= newval; i--)
1533-
{
1534-
// Also detach the thread so we no longer need to join
1535-
discard_threads[i]->stop = true;
1536-
discard_threads[i]->detach();
1537-
discard_threads.erase(discard_threads.begin() + i);
1529+
// Decreasing to zero is exactly the same as disabling async discard.
1530+
// Signal all threads to stop
1531+
if(newval == 0) {
1532+
_discard_stop();
1533+
} else {
1534+
// Signal the last threads to quit, and stop tracking them
1535+
for(uint64_t i = oldval - 1; i >= newval; i--)
1536+
{
1537+
// Also detach the thread so we no longer need to join
1538+
discard_threads[i]->stop = true;
1539+
discard_threads[i]->detach();
1540+
discard_threads.erase(discard_threads.begin() + i);
1541+
}
15381542
}
15391543

15401544
discard_cond.notify_all();

src/blk/kernel/KernelDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class KernelDevice : public BlockDevice,
8787

8888
void _aio_thread();
8989
void _discard_thread(uint64_t tid);
90-
int _queue_discard(interval_set<uint64_t> &to_release);
90+
void _queue_discard(interval_set<uint64_t> &to_release);
9191
bool try_discard(interval_set<uint64_t> &to_release, bool async = true) override;
9292

9393
int _aio_start();

0 commit comments

Comments
 (0)