]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer.cc: add possibility to omit crc cache invalidation
authorPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Thu, 16 Jul 2015 09:04:34 +0000 (11:04 +0200)
committerPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Tue, 4 Aug 2015 07:59:11 +0000 (09:59 +0200)
In some cases, it might be worthwile to either not invalidate crc
cache at all, or postpone it until we're done with other tasks (for
example, after doing a lot of copy_in into single bufferptr instead
of invalid after each of copy_in). This reduces bufferptr lock usage
and in turn, decreases cpu utilization.
This change adds the optional crc_reset arg (which defaults to true)
so only new/aware code will use this feature.

Signed-off-by: Piotr Dałek <piotr.dalek@ts.fujitsu.com>
src/common/buffer.cc
src/include/buffer.h

index 2bf68934e03dcb2ec3e52a31903cd0a94102008d..dba06ee05d1e9a52fe6d85985ed0243157b9b52f 100644 (file)
@@ -941,28 +941,30 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
     return _len + _off;
   }
     
-  void buffer::ptr::copy_in(unsigned o, unsigned l, const char *src)
+  void buffer::ptr::copy_in(unsigned o, unsigned l, const char *src, bool crc_reset)
   {
     assert(_raw);
     assert(o <= _len);
     assert(o+l <= _len);
-    _raw->invalidate_crc();
+    if (crc_reset)
+        _raw->invalidate_crc();
     memcpy(c_str()+o, src, l);
   }
 
-  void buffer::ptr::zero()
+  void buffer::ptr::zero(bool crc_reset)
   {
-    _raw->invalidate_crc();
+    if (crc_reset)
+        _raw->invalidate_crc();
     memset(c_str(), 0, _len);
   }
 
-  void buffer::ptr::zero(unsigned o, unsigned l)
+  void buffer::ptr::zero(unsigned o, unsigned l, bool crc_reset)
   {
     assert(o+l <= _len);
-    _raw->invalidate_crc();
+    if (crc_reset)
+        _raw->invalidate_crc();
     memset(c_str()+o, 0, l);
   }
-
   bool buffer::ptr::can_zero_copy() const
   {
     return _raw->can_zero_copy();
@@ -1138,7 +1140,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
   
   // copy data in
 
-  void buffer::list::iterator::copy_in(unsigned len, const char *src)
+  void buffer::list::iterator::copy_in(unsigned len, const char *src, bool crc_reset)
   {
     // copy
     if (p == ls->end())
@@ -1150,7 +1152,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
       unsigned howmuch = p->length() - p_off;
       if (len < howmuch)
        howmuch = len;
-      p->copy_in(p_off, howmuch, src);
+      p->copy_in(p_off, howmuch, src, crc_reset);
        
       src += howmuch;
       len -= howmuch;
@@ -1462,14 +1464,14 @@ void buffer::list::rebuild_page_aligned()
     return last_p.copy(len, dest);
   }
     
-  void buffer::list::copy_in(unsigned off, unsigned len, const char *src)
+  void buffer::list::copy_in(unsigned off, unsigned len, const char *src, bool crc_reset)
   {
     if (off + len > length())
       throw end_of_buffer();
     
     if (last_p.get_off() != off) 
       last_p.seek(off);
-    last_p.copy_in(len, src);
+    last_p.copy_in(len, src, crc_reset);
   }
 
   void buffer::list::copy_in(unsigned off, unsigned len, const list& src)
index ad72d6a11ba6fbbe0b2cc4af859fee06ee6163cc..90a1716ea0497c8a08a6a1e449549e0e21eefeb7 100644 (file)
@@ -241,9 +241,9 @@ public:
 
     unsigned append(char c);
     unsigned append(const char *p, unsigned l);
-    void copy_in(unsigned o, unsigned l, const char *src);
-    void zero();
-    void zero(unsigned o, unsigned l);
+    void copy_in(unsigned o, unsigned l, const char *src, bool crc_reset = true);
+    void zero(bool crc_reset = true);
+    void zero(unsigned o, unsigned l, bool crc_reset = true);
 
   };
 
@@ -307,7 +307,7 @@ public:
       void copy_all(list &dest);
 
       // copy data in
-      void copy_in(unsigned len, const char *src);
+      void copy_in(unsigned len, const char *src, bool crc_reset = true);
       void copy_in(unsigned len, const list& otherl);
 
     };
@@ -442,7 +442,7 @@ public:
     void copy(unsigned off, unsigned len, char *dest) const;
     void copy(unsigned off, unsigned len, list &dest) const;
     void copy(unsigned off, unsigned len, std::string& dest) const;
-    void copy_in(unsigned off, unsigned len, const char *src);
+    void copy_in(unsigned off, unsigned len, const char *src, bool crc_reset = true);
     void copy_in(unsigned off, unsigned len, const list& src);
 
     void append(char c);