]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: prefix rbd writes with CEPH_OSD_OP_SETALLOCHINT osd op
authorIlya Dryomov <ilya.dryomov@inktank.com>
Fri, 21 Feb 2014 14:34:14 +0000 (16:34 +0200)
committerIlya Dryomov <ilya.dryomov@inktank.com>
Mon, 3 Mar 2014 18:33:44 +0000 (20:33 +0200)
In an effort to reduce fragmentation, prefix every rbd write with
a CEPH_OSD_OP_SETALLOCHINT osd op with an expected_write_size value set
to the object size (1 << order).  Backwards compatibility is taken care
of on the osd side.

"The CEPH_OSD_OP_SETALLOCHINT hint is durable, in that it's enough to
do it once.  The reason every rbd write is prefixed is that rbd doesn't
explicitly create objects and relies on writes creating them
implicitly, so there is no place to stick a single hint op into.  To
get around that we decided to prefix every rbd write with a hint (just
like write and setattr ops, hint op will create an object implicitly if
it doesn't exist)."

Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
src/librbd/AioRequest.cc
src/librbd/AioRequest.h

index 6e4a05e6945c14f4fddf54b8fd874d811b756967..881f754a33cd6df903ad522770973a290107b456 100644 (file)
@@ -105,7 +105,7 @@ namespace librbd {
     return r;
   }
 
-  /** read **/
+  /** write **/
 
   AbstractWrite::AbstractWrite()
     : m_state(LIBRBD_AIO_WRITE_FLAT),
@@ -236,6 +236,7 @@ namespace librbd {
   }
 
   void AbstractWrite::send_copyup() {
+    ldout(m_ictx->cct, 20) << "send_copyup " << this << " " << m_oid << " " << m_object_off << "~" << m_object_len << dendl;
     if (!m_read_data.is_zero())
       m_copyup.exec("rbd", "copyup", m_read_data);
     add_copyup_ops();
@@ -246,4 +247,9 @@ namespace librbd {
                               m_snap_seq, m_snaps);
     rados_completion->release();
   }
+
+  void AioWrite::add_write_ops(librados::ObjectWriteOperation &wr) {
+    wr.set_alloc_hint(m_ictx->get_object_size(), m_ictx->get_object_size());
+    wr.write(m_object_off, m_write_data);
+  }
 }
index cf50ee2c049d30eb0e0b4bd7a8be075a94a10b25..d6103f9a195cfba50b992870b1ac5885139f314a 100644 (file)
@@ -160,16 +160,17 @@ namespace librbd {
                      completion, false),
        m_write_data(data) {
       guard_write();
-      m_write.write(m_object_off, data);
+      add_write_ops(m_write);
     }
     virtual ~AioWrite() {}
 
   protected:
     virtual void add_copyup_ops() {
-      m_copyup.write(m_object_off, m_write_data);
+      add_write_ops(m_copyup);
     }
 
   private:
+    void add_write_ops(librados::ObjectWriteOperation &wr);
     ceph::bufferlist m_write_data;
   };