]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: add task pool / work queue for requests
authorJason Dillaman <dillaman@redhat.com>
Wed, 8 Apr 2015 21:24:08 +0000 (17:24 -0400)
committerKen Dreyer <kdreyer@redhat.com>
Wed, 24 Jun 2015 16:41:07 +0000 (10:41 -0600)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit afb896d91f886b647baf38f7ec94cc3739f6d2a9)
(cherry picked from commit e61974aed09a3f81e1f65a4bbaed43e3f22b27b4)

src/common/config_opts.h
src/librbd/ImageCtx.cc
src/librbd/ImageCtx.h
src/librbd/internal.cc

index 8e817e140347679a1c00953e46fd3ba4b4dc06e9..1b7c959c6264e791568b536a4e8eebdc87980a7c 100644 (file)
@@ -857,6 +857,8 @@ OPTION(journal_discard, OPT_BOOL, false) //using ssd disk as journal, whether su
 OPTION(rados_mon_op_timeout, OPT_DOUBLE, 0) // how many seconds to wait for a response from the monitor before returning an error from a rados operation. 0 means on limit.
 OPTION(rados_osd_op_timeout, OPT_DOUBLE, 0) // how many seconds to wait for a response from osds before returning an error from a rados operation. 0 means no limit.
 
+OPTION(rbd_op_threads, OPT_INT, 1)
+OPTION(rbd_op_thread_timeout, OPT_INT, 60)
 OPTION(rbd_cache, OPT_BOOL, true) // whether to enable caching (writeback unless rbd_cache_max_dirty is 0)
 OPTION(rbd_cache_writethrough_until_flush, OPT_BOOL, true) // whether to make writeback caching writethrough until flush is called, to be sure the user of librbd will send flushs so that writeback is safe
 OPTION(rbd_cache_size, OPT_LONGLONG, 32<<20)         // cache size in bytes
index 564f3437f0bd981a420362f87b1fbcd01cc75486..b9580824f99c1cdf782dab6940c85f142d873f0e 100644 (file)
@@ -6,6 +6,7 @@
 #include "common/dout.h"
 #include "common/errno.h"
 #include "common/perf_counters.h"
+#include "common/WorkQueue.h"
 
 #include "librbd/AsyncOperation.h"
 #include "librbd/AsyncRequest.h"
@@ -32,6 +33,23 @@ using librados::snap_t;
 using librados::IoCtx;
 
 namespace librbd {
+
+namespace {
+
+class ThreadPoolSingleton : public ThreadPool {
+public:
+  ThreadPoolSingleton(CephContext *cct)
+    : ThreadPool(cct, "librbd::thread_pool", cct->_conf->rbd_op_threads,
+                 "rbd_op_threads") {
+    start();
+  }
+  virtual ~ThreadPoolSingleton() {
+    stop();
+  }
+};
+
+} // anonymous namespace
+
   ImageCtx::ImageCtx(const string &image_name, const string &image_id,
                     const char *snap, IoCtx& p, bool ro)
     : cct((CephContext*)p.cct()),
@@ -63,7 +81,7 @@ namespace librbd {
       object_cacher(NULL), writeback_handler(NULL), object_set(NULL),
       readahead(),
       total_bytes_read(0), copyup_finisher(NULL),
-      object_map(*this)
+      object_map(*this), aio_work_queue(NULL)
   {
     md_ctx.dup(p);
     data_ctx.dup(p);
@@ -113,6 +131,13 @@ namespace librbd {
       copyup_finisher = new Finisher(cct);
       copyup_finisher->start();
     }
+
+    ThreadPoolSingleton *thread_pool_singleton;
+    cct->lookup_or_create_singleton_object<ThreadPoolSingleton>(
+      thread_pool_singleton, "librbd::thread_pool");
+    aio_work_queue = new ContextWQ("librbd::aio_work_queue",
+                                   cct->_conf->rbd_op_thread_timeout,
+                                   thread_pool_singleton);
   }
 
   ImageCtx::~ImageCtx() {
@@ -134,6 +159,8 @@ namespace librbd {
       copyup_finisher = NULL;
     }
     delete[] format_string;
+
+    delete aio_work_queue;
   }
 
   int ImageCtx::init() {
index 22f3b80449919af6ab9543259d7ecdc683585748..47134e2f19115b861cc83ad17d215ea623e78817 100644 (file)
@@ -31,6 +31,7 @@
 #include "librbd/parent_types.h"
 
 class CephContext;
+class ContextWQ;
 class Finisher;
 class PerfCounters;
 
@@ -130,6 +131,8 @@ namespace librbd {
 
     xlist<AsyncResizeRequest*> async_resize_reqs;
 
+    ContextWQ *aio_work_queue;
+
     /**
      * Either image_name or image_id must be set.
      * If id is not known, pass the empty std::string,
index c356c79fe3b5efc1b372a60617df6be85f9cd24e..74f8c62b9e5129b10559e26a6c891049cf2bb0f2 100644 (file)
@@ -10,6 +10,7 @@
 #include "common/errno.h"
 #include "common/ContextCompletion.h"
 #include "common/Throttle.h"
+#include "common/WorkQueue.h"
 #include "cls/lock/cls_lock_client.h"
 #include "include/stringify.h"
 
@@ -2424,6 +2425,8 @@ reprotect_and_return_err:
       }
     }
 
+    ictx->aio_work_queue->drain();
+
     ictx->cancel_async_requests();
     ictx->readahead.wait_for_pending();
     if (ictx->object_cacher) {