]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: support compression allocation hints to the OSD
authorJason Dillaman <dillaman@redhat.com>
Thu, 16 Jan 2020 19:53:37 +0000 (14:53 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 16 Jan 2020 19:53:37 +0000 (14:53 -0500)
A new "rbd_compression_hint" configuration option can be applied
globally, at the pool level, or to individual images to send
the associated compression allocation hint to the OSD on write
operations.

Fixes: https://tracker.ceph.com/issues/42097
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/common/options.cc
src/librbd/ImageCtx.cc
src/librbd/ImageCtx.h
src/librbd/io/ObjectRequest.cc
src/test/librados_test_stub/LibradosTestStub.cc
src/test/librados_test_stub/TestIoCtxImpl.cc
src/test/librados_test_stub/TestIoCtxImpl.h
src/test/librados_test_stub/TestMemIoCtxImpl.cc
src/test/librados_test_stub/TestMemIoCtxImpl.h
src/test/librbd/mock/MockImageCtx.h

index cf0bc134e2063afb9b419c284336ffef86032621..51d5d48080f10058b335cd3db486e6e0ed3ede6e 100644 (file)
@@ -7164,6 +7164,12 @@ static std::vector<Option> get_rbd_options() {
     .set_default(true)
     .set_description("when writing a object, it will issue a hint to osd backend to indicate the expected size object need"),
 
+    Option("rbd_compression_hint", Option::TYPE_STR, Option::LEVEL_BASIC)
+    .set_enum_allowed({"none", "compressible", "incompressible"})
+    .set_default("none")
+    .set_description("Compression hint to send to the OSDs during writes")
+    .set_flag(Option::FLAG_RUNTIME),
+
     Option("rbd_tracing", Option::TYPE_BOOL, Option::LEVEL_ADVANCED)
     .set_default(false)
     .set_description("true if LTTng-UST tracepoints should be enabled"),
index 070233e095486b8a8e79a0a9be15fa390314300c..28b6c795d88937fad6c4aa575f12c57efd4d0f4b 100644 (file)
@@ -787,6 +787,14 @@ public:
       discard_granularity_bytes = 0;
     }
 
+    alloc_hint_flags = 0;
+    auto compression_hint = config.get_val<std::string>("rbd_compression_hint");
+    if (compression_hint == "compressible") {
+      alloc_hint_flags |= librados::ALLOC_HINT_FLAG_COMPRESSIBLE;
+    } else if (compression_hint == "incompressible") {
+      alloc_hint_flags |= librados::ALLOC_HINT_FLAG_INCOMPRESSIBLE;
+    }
+
     io_work_queue->apply_qos_schedule_tick_min(
       config.get_val<uint64_t>("rbd_qos_schedule_tick_min"));
 
index 95be9f488800c0f79f90a56e300ef1de6bc4cbd2..53d14452043b9439729a2c6bd64b36d89dc21c07 100644 (file)
@@ -195,6 +195,7 @@ namespace librbd {
     uint64_t readahead_disable_after_bytes;
     bool clone_copy_on_read;
     bool enable_alloc_hint;
+    uint32_t alloc_hint_flags = 0U;
     uint32_t discard_granularity_bytes = 0;
     bool blkin_trace_all;
     uint64_t mirroring_replay_delay;
index d3dd77bc21cfd5d01b3be948e7703c912de4490b..3966dd2e725b5f01a8ca0fbdf16b6e4169eccfa0 100644 (file)
@@ -115,8 +115,11 @@ template <typename I>
 void ObjectRequest<I>::add_write_hint(I& image_ctx,
                                       librados::ObjectWriteOperation *wr) {
   if (image_ctx.enable_alloc_hint) {
-    wr->set_alloc_hint(image_ctx.get_object_size(),
-                       image_ctx.get_object_size());
+    wr->set_alloc_hint2(image_ctx.get_object_size(),
+                        image_ctx.get_object_size(),
+                        image_ctx.alloc_hint_flags);
+  } else if (image_ctx.alloc_hint_flags != 0U) {
+    wr->set_alloc_hint2(0, 0, image_ctx.alloc_hint_flags);
   }
 }
 
index c80dd6fe52b107c3006ed23230b7d83682824894..92f1541eaf3128e45ff1d3be10ff4ea61c4612ab 100644 (file)
@@ -938,9 +938,18 @@ void ObjectWriteOperation::set_alloc_hint(uint64_t expected_object_size,
                                           uint64_t expected_write_size) {
   TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
   o->ops.push_back(boost::bind(&TestIoCtxImpl::set_alloc_hint, _1, _2,
-                              expected_object_size, expected_write_size, _4));
+                              expected_object_size, expected_write_size, 0,
+                               _4));
 }
 
+void ObjectWriteOperation::set_alloc_hint2(uint64_t expected_object_size,
+                                           uint64_t expected_write_size,
+                                           uint32_t flags) {
+  TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
+  o->ops.push_back(boost::bind(&TestIoCtxImpl::set_alloc_hint, _1, _2,
+                              expected_object_size, expected_write_size, flags,
+                               _4));
+}
 
 void ObjectWriteOperation::tmap_update(const bufferlist& cmdbl) {
   TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
index 500df993574df80ae9483b3e152a528cdd1d1b0e..31a60ae2621ffcecb58634e8e01128f77994ef42 100644 (file)
@@ -256,6 +256,7 @@ int TestIoCtxImpl::selfmanaged_snap_set_write_ctx(snap_t seq,
 int TestIoCtxImpl::set_alloc_hint(const std::string& oid,
                                   uint64_t expected_object_size,
                                   uint64_t expected_write_size,
+                                  uint32_t flags,
                                   const SnapContext &snapc) {
   return 0;
 }
index ad79a2986c75c52f11e155c71e672182a95d03ae..0bd3e6fb0c248ae25d00ab1d20beab86458f30ea 100644 (file)
@@ -146,6 +146,7 @@ public:
   virtual int set_alloc_hint(const std::string& oid,
                              uint64_t expected_object_size,
                              uint64_t expected_write_size,
+                             uint32_t flags,
                              const SnapContext &snapc);
   virtual void set_snap_read(snap_t seq);
   virtual int sparse_read(const std::string& oid, uint64_t off, uint64_t len,
index 94b8c5aadf51654584334f8cd8034465159d18f0..9914f5a953b87a9dc5f7545b575bee15ceefcacb 100644 (file)
@@ -445,6 +445,7 @@ int TestMemIoCtxImpl::selfmanaged_snap_rollback(const std::string& oid,
 int TestMemIoCtxImpl::set_alloc_hint(const std::string& oid,
                                      uint64_t expected_object_size,
                                      uint64_t expected_write_size,
+                                     uint32_t flags,
                                      const SnapContext &snapc) {
   if (get_snap_read() != CEPH_NOSNAP) {
     return -EROFS;
index 22e4fc7eb88fe7ea077782ffa4128939a3fd5f42..712c57f8cc871e09f9d18300cb24ceb50d09ccd7 100644 (file)
@@ -54,7 +54,7 @@ public:
   int selfmanaged_snap_rollback(const std::string& oid,
                                 uint64_t snapid) override;
   int set_alloc_hint(const std::string& oid, uint64_t expected_object_size,
-                     uint64_t expected_write_size,
+                     uint64_t expected_write_size, uint32_t flags,
                      const SnapContext &snapc) override;
   int sparse_read(const std::string& oid, uint64_t off, uint64_t len,
                   std::map<uint64_t,uint64_t> *m, bufferlist *data_bl) override;
index 092b90f40a49a296b7548266f1b3f2fcc7794155..0e7616227134bc75f607d500a8ff70c4586c5458 100644 (file)
@@ -97,6 +97,7 @@ struct MockImageCtx {
       non_blocking_aio(image_ctx.non_blocking_aio),
       blkin_trace_all(image_ctx.blkin_trace_all),
       enable_alloc_hint(image_ctx.enable_alloc_hint),
+      alloc_hint_flags(image_ctx.alloc_hint_flags),
       ignore_migrating(image_ctx.ignore_migrating),
       enable_sparse_copyup(image_ctx.enable_sparse_copyup),
       mtime_update_interval(image_ctx.mtime_update_interval),
@@ -303,6 +304,7 @@ struct MockImageCtx {
   bool non_blocking_aio;
   bool blkin_trace_all;
   bool enable_alloc_hint;
+  uint32_t alloc_hint_flags;
   bool ignore_migrating;
   bool enable_sparse_copyup;
   uint64_t mtime_update_interval;