]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Revert "blk: support bdev_async_discard_threads == 0"
authorskanta <skanta@redhat.com>
Tue, 5 Nov 2024 10:50:39 +0000 (16:20 +0530)
committerskanta <skanta@redhat.com>
Tue, 5 Nov 2024 10:50:39 +0000 (16:20 +0530)
This reverts commit a776b6e9250808be7b8d4ac945352ad0ffe09791.
The commit was merged prematurely without testing.

Signed-off-by: Srinivasa Bharath Kanta <skanta@redhat.com>
src/blk/kernel/KernelDevice.cc
src/blk/kernel/KernelDevice.h

index f6edaf98e8304b673481137bd03a434cbbc6f945..e17c4b6dcf6d5e2e7f4b37d1ca64ed968ef526a0 100644 (file)
@@ -778,28 +778,30 @@ void KernelDevice::_discard_thread(uint64_t tid)
   dout(10) << __func__ << " thread " << tid << " finish" << dendl;
 }
 
-// this is private and is expected that the caller checks that discard
-// threads are running via _discard_started()
-void KernelDevice::_queue_discard(interval_set<uint64_t> &to_release)
+int KernelDevice::_queue_discard(interval_set<uint64_t> &to_release)
 {
+  // if bdev_async_discard enabled on the fly, discard_thread is not started here, fallback to sync discard
+  if (!_discard_started())
+    return -1;
+
   if (to_release.empty())
-    return;
+    return 0;
 
   std::lock_guard l(discard_lock);
   discard_queued.insert(to_release);
   discard_cond.notify_one();
+  return 0;
 }
 
-// return true only if discard was queued, so caller won't have to do
-// alloc->release, otherwise return false
+// return true only if _queue_discard succeeded, so caller won't have to do alloc->release
+// otherwise false
 bool KernelDevice::try_discard(interval_set<uint64_t> &to_release, bool async)
 {
   if (!support_discard || !cct->_conf->bdev_enable_discard)
     return false;
 
-  if (async && _discard_started()) {
-    _queue_discard(to_release);
-    return true;
+  if (async) {
+    return 0 == _queue_discard(to_release);
   } else {
     for (auto p = to_release.begin(); p != to_release.end(); ++p) {
       _discard(p.get_start(), p.get_len());
@@ -1530,19 +1532,13 @@ void KernelDevice::handle_conf_change(const ConfigProxy& conf,
       // Decrease? Signal threads after telling them to stop
       dout(10) << __func__ << " stopping " << (oldval - newval) << " existing discard threads" << dendl;
 
-      // Decreasing to zero is exactly the same as disabling async discard.
-      // Signal all threads to stop
-      if(newval == 0) {
-        _discard_stop();
-      } else {
-        // Signal the last threads to quit, and stop tracking them
-        for(uint64_t i = oldval - 1; i >= newval; i--)
-        {
-          // Also detach the thread so we no longer need to join
-          discard_threads[i]->stop = true;
-          discard_threads[i]->detach();
-          discard_threads.erase(discard_threads.begin() + i);
-        }
+      // Signal the last threads to quit, and stop tracking them
+      for(uint64_t i = oldval - 1; i >= newval; i--)
+      {
+        // Also detach the thread so we no longer need to join
+        discard_threads[i]->stop = true;
+        discard_threads[i]->detach();
+        discard_threads.erase(discard_threads.begin() + i);
       }
 
       discard_cond.notify_all();
index 914f05e64c43ddc647234c30f336bf8f5d93c6c8..326a94339915f9a7e3e4f39601a40bfce8792eb0 100644 (file)
@@ -87,7 +87,7 @@ private:
 
   void _aio_thread();
   void _discard_thread(uint64_t tid);
-  void _queue_discard(interval_set<uint64_t> &to_release);
+  int _queue_discard(interval_set<uint64_t> &to_release);
   bool try_discard(interval_set<uint64_t> &to_release, bool async = true) override;
 
   int _aio_start();