]> git-server-git.apps.pok.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)
committerNathan Cutler <ncutler@suse.com>
Fri, 24 Jan 2020 16:18:14 +0000 (17:18 +0100)
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>
(cherry picked from commit 200fc5b2f24859109a79002e30927d457971b939)

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 2bee6e90fd60c1a37a322463b0be73d27f2ee163..bbba2492bea2a4512db01c473de37d406db698d4 100644 (file)
@@ -7338,6 +7338,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 c64302d802f180e712ccc6a40295ab8e374494a9..8375d1a6390647ff63d4e552c5a70861b69612b2 100644 (file)
@@ -802,6 +802,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 f60dec9886406c259a2fe6ef6452fdc9625821fa..df5271e8efae7fde70291916129b30feb037caa8 100644 (file)
@@ -182,6 +182,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 58b1708455eb09bd1e55d21e5d618464c29ca3d0..60f53df1f0b10b5dc811724231b55b0ad5bd0079 100644 (file)
@@ -126,8 +126,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 66152990cae20365cbe5eaf976da6122e7f8d666..f84642507f4c452309e095c97906911c415634ba 100644 (file)
@@ -937,9 +937,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 0788d9f5b30aae8a685c1192e645b66788b68c4e..7e6fa4eef82b34d300e8a15851963900ed22f847 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 e92d7dfa505f669f4dfdc89e249bbe99298a9346..972dd44da51167757b391208f23ef94e59755997 100644 (file)
@@ -145,6 +145,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 4f60e435987f44465d40a1375c017507b4208f0f..ac73e950d145a9edd6d3a95747795328299b2c18 100644 (file)
@@ -444,6 +444,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 f083230c89ebd04dd372be5c7ea3c31d30b21a9d..ebe3a46e5c790eda71120d1f5b80dd4845ea9a21 100644 (file)
@@ -53,7 +53,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 5c0db6a8fc164c9968e0a4c6216bc577298b484d..2a46c89a44fdc579b061c575410f29850c8cfcb5 100644 (file)
@@ -98,6 +98,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),
       mtime_update_interval(image_ctx.mtime_update_interval),
       atime_update_interval(image_ctx.atime_update_interval),
@@ -304,6 +305,7 @@ struct MockImageCtx {
   bool non_blocking_aio;
   bool blkin_trace_all;
   bool enable_alloc_hint;
+  uint32_t alloc_hint_flags;
   bool ignore_migrating;
   uint64_t mtime_update_interval;
   uint64_t atime_update_interval;