]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
new hash function
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Fri, 31 Aug 2007 17:09:03 +0000 (17:09 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Fri, 31 Aug 2007 17:09:03 +0000 (17:09 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1759 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/ebofs/Ebofs.h
trunk/ceph/ebofs/nodes.h
trunk/ceph/include/blobhash.h
trunk/ceph/include/hash.h [new file with mode: 0644]
trunk/ceph/include/object.h
trunk/ceph/include/types.h
trunk/ceph/msg/SimpleMessenger.cc
trunk/ceph/osd/FakeStore.cc
trunk/ceph/osd/OSD.h
trunk/ceph/osd/OSDMap.h
trunk/ceph/osd/osd_types.h

index 1bcccafe055670cf9f4096dd7c6c1b75efa8cbad..13eebabd93aadff01db072268dba563420db8c80 100644 (file)
@@ -21,6 +21,7 @@ using namespace __gnu_cxx;
 
 #include "include/Context.h"
 #include "include/buffer.h"
+#include "include/hash.h"
 
 #include "types.h"
 #include "Onode.h"
@@ -137,7 +138,7 @@ protected:
   void write_onode(Onode *on);
 
   // ** cnodes **
-  hash_map<coll_t, Cnode*>    cnode_map;
+  hash_map<coll_t, Cnode*, rjhash<coll_t> >    cnode_map;
   LRU                         cnode_lru;
   set<Cnode*>                 dirty_cnodes;
   map<coll_t, list<Cond*> >   waitfor_cnode;
index d5ce06c2eefc6908712f6f110a7bf21d18222448..60fb5d364044141af8879eb5ae6ca1abc7638470 100644 (file)
@@ -131,7 +131,7 @@ class Node {
 
 class NodePool {
  protected:
-  hash_map<nodeid_t, Node*>  node_map;      // open node map
+  hash_map<nodeid_t, Node*, rjhash<uint64_t> >  node_map;      // open node map
   
  public:
   vector<Extent> region_loc;    // region locations
@@ -517,7 +517,7 @@ class NodePool {
 
   void release_all() {
     while (!node_map.empty()) {
-      hash_map<nodeid_t,Node*>::iterator i = node_map.begin();
+      hash_map<nodeid_t,Node*,rjhash<uint64_t> >::iterator i = node_map.begin();
       debofs(2) << "ebofs.nodepool.release_all leftover " << i->first << " " << i->second << std::endl;
       release( i->second );
     }
index 30ae0e74c013be0c699a59080d4fa193b1f91b34..41c6dc53b45a76f390edddfba210f5af78372d33 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef __BLOBHASH_H
 #define __BLOBHASH_H
 
+#include "hash.h"
+
 /*
 - this is to make some of the STL types work with 64 bit values, string hash keys, etc.
 - added when i was using an old STL.. maybe try taking these out and see if things 
@@ -23,7 +25,7 @@
 class blobhash {
 public:
   size_t operator()(const char *p, unsigned len) {
-    static hash<long> H;
+    static rjhash<unsigned long> H;
     long acc = 0;
     while (len >= sizeof(long)) {
       acc ^= *(long*)p;
diff --git a/trunk/ceph/include/hash.h b/trunk/ceph/include/hash.h
new file mode 100644 (file)
index 0000000..0c27d35
--- /dev/null
@@ -0,0 +1,70 @@
+#ifndef __CEPHHASH_H
+#define __CEPHHASH_H
+
+// Robert Jenkins' function for mixing 32-bit values
+// http://burtleburtle.net/bob/hash/evahash.html
+// a, b = random bits, c = input and output
+
+#define hashmix(a,b,c) \
+        a=a-b;  a=a-c;  a=a^(c>>13); \
+        b=b-c;  b=b-a;  b=b^(a<<8);  \
+        c=c-a;  c=c-b;  c=c^(b>>13); \
+        a=a-b;  a=a-c;  a=a^(c>>12); \
+        b=b-c;  b=b-a;  b=b^(a<<16); \
+        c=c-a;  c=c-b;  c=c^(b>>5);  \
+        a=a-b;  a=a-c;  a=a^(c>>3); \
+        b=b-c;  b=b-a;  b=b^(a<<10); \
+        c=c-a;  c=c-b;  c=c^(b>>15); 
+
+
+//namespace ceph {
+
+template <class _Key> struct rjhash { };
+
+inline uint64_t rjhash64(uint64_t key) {
+  key = (~key) + (key << 21); // key = (key << 21) - key - 1;
+  key = key ^ (key >> 24);
+  key = (key + (key << 3)) + (key << 8); // key * 265
+  key = key ^ (key >> 14);
+  key = (key + (key << 2)) + (key << 4); // key * 21
+  key = key ^ (key >> 28);
+  key = key + (key << 31);
+  return key;
+}
+
+inline uint32_t rjhash32(uint32_t a) {
+  a = (a+0x7ed55d16) + (a<<12);
+  a = (a^0xc761c23c) ^ (a>>19);
+  a = (a+0x165667b1) + (a<<5);
+  a = (a+0xd3a2646c) ^ (a<<9);
+  a = (a+0xfd7046c5) + (a<<3);
+  a = (a^0xb55a4f09) ^ (a>>16);
+  return a;
+}
+
+
+template<> struct rjhash<uint32_t> {
+  inline size_t operator()(const uint32_t x) const {
+#ifdef __LP64__
+    return rjhash64(x);
+#else
+    return rjhash32(x);
+#endif
+  }
+};
+
+template<> struct rjhash<uint64_t> {
+  inline size_t operator()(const uint64_t x) const {
+#ifdef __LP64__
+    return rjhash64(x);
+#else
+    return rjhash32(x) ^ rjhash32(x >> 32);
+#endif
+  }
+};
+  
+//}
+
+
+
+#endif
index 955a024c0dea6c2426d4621abfc7f1ab18abb1f9..a1382626f7cae5cf754835f16c104eb0817be521 100644 (file)
@@ -24,6 +24,7 @@ using namespace std;
 #include <ext/hash_map>
 using namespace __gnu_cxx;
 
+#include "hash.h"
 
 typedef uint32_t objectrev_t;
 
@@ -80,24 +81,41 @@ inline ostream& operator<<(ostream& out, const object_t o) {
 }
 
 
+
+
+
 namespace __gnu_cxx {
 #ifndef __LP64__
   template<> struct hash<uint64_t> {
     size_t operator()(uint64_t __x) const { 
       static hash<uint32_t> H;
       return H((__x >> 32) ^ (__x & 0xffffffff)); 
+      //static rjhash<uint64_t> H;
+      //return H(__x);
     }
   };
 #endif
 
   template<> struct hash<object_t> {
     size_t operator()(const object_t &r) const { 
-      static hash<uint64_t> H;
-      static hash<uint32_t> I;
-      return H(r.ino) ^ I(r.bno);
+      static rjhash<uint64_t> H;
+      static rjhash<uint32_t> I;
+      //static hash<uint64_t> H;
+      //static hash<uint32_t> I;
+      return H(r.ino) ^ I(r.bno) ^ I(r.rev);
     }
   };
+
 }
 
+/*
+  template<> struct rjhash<object_t> {
+    size_t operator()(const object_t &r) const { 
+      static rjhash<uint64_t> H;
+      static rjhash<uint32_t> I;
+      return H(r.ino) ^ I(r.bno) ^ I(r.rev);
+    }
+  };
+*/
 
 #endif
index 42a0416211c9745c31a46ae7b432a8aafda6de18..088417acc20ac3bce9da5832e19eaace5a248a41 100644 (file)
@@ -193,7 +193,7 @@ namespace __gnu_cxx {
   {
     size_t operator()( const inodeno_t& x ) const
     {
-      static hash<uint64_t> H;
+      static rjhash<uint64_t> H;
       return H(x.val);
     }
   };
index dfcd505c738336b496de15c2d4251001b444107c..048f3a5c9db74cbb7276e4362b769c2abf1064a4 100644 (file)
@@ -715,7 +715,7 @@ int Rank::Pipe::write_message(Message *m)
              << " writing " << donow 
              << dendl;
 
-      if (msg.msg_iovlen == IOV_MAX-1) {
+      if (msg.msg_iovlen >= IOV_MAX-1) {
        // send what we have so far...
        int r = sendmsg(sd, &msg, 0);
        if (r < 0) { 
index b28311f7415781ba461d619a152bccc6c1aba052..e7c77f3eab5585733a94b05a29578231c82d9c16 100644 (file)
@@ -47,8 +47,7 @@
 #include "include/buffer.h"
 
 #include <map>
-#include <ext/hash_map>
-using namespace __gnu_cxx;
+
 
 // crap-a-crap hash
 //#define HASH_DIRS       0x80
@@ -174,7 +173,7 @@ int FakeStore::mount()
   struct stat st;
   int r = ::stat(basedir.c_str(), &st);
   if (r != 0) {
-    derr(0) << "unable to stat basedir " << basedir << ", r = " << r << dendl;
+    derr(0) << "unable to stat basedir " << basedir << ", " << strerror(errno) << dendl;
     return r;
   }
   
index fce8968ffe3f1cf7f690f1c5674eec342e960992..297a5f09a6fa0d8ff1e6962fb2d2d0d84eef7048 100644 (file)
@@ -115,8 +115,8 @@ private:
 
   Mutex peer_stat_lock;
   osd_peer_stat_t my_stat;
-  hash_map<int, osd_peer_stat_t> peer_stat;
-  hash_map<int, osd_peer_stat_t> my_stat_on_peer;  // what the peer thinks of me
+  hash_map<int, osd_peer_stat_t, rjhash<uint32_t> > peer_stat;
+  hash_map<int, osd_peer_stat_t, rjhash<uint32_t> > my_stat_on_peer;  // what the peer thinks of me
 
   void _refresh_my_stat(utime_t now);
   osd_peer_stat_t get_my_stat_for(utime_t now, int peer);
index b8b0caee7e9cb8869408b331f8f9f3a5da3a9c1a..59e108c937aaf29eee5ccc289455d6289a442f0b 100644 (file)
@@ -327,12 +327,15 @@ private:
       break;
       
     case OBJECT_LAYOUT_HASHINO:
+      //ps = stable_mod(oid.bno + H(oid.bno+oid.ino)^H(oid.ino>>32), num, num_mask);
       ps = stable_mod(oid.bno + H(oid.ino)^H(oid.ino>>32), num, num_mask);
       break;
 
     case OBJECT_LAYOUT_HASH:
       //ps = stable_mod(H( (oid.bno & oid.ino) ^ ((oid.bno^oid.ino) >> 32) ), num, num_mask);
-      ps = stable_mod(H(oid.bno) ^ H(oid.ino)^H(oid.ino>>32), num, num_mask);
+      //ps = stable_mod(H(oid.bno) + H(oid.ino)^H(oid.ino>>32), num, num_mask);
+      //ps = stable_mod(oid.bno + H(oid.bno+oid.ino)^H(oid.bno+oid.ino>>32), num, num_mask);
+      ps = stable_mod(oid.bno + H(oid.ino)^H(oid.ino>>32), num, num_mask);
       break;
 
     default:
index 87431c2ec4a72f82b2070a767a03347040a7e70f..8a0d0f146fa2c06df4d8ce99811884d90053af82 100644 (file)
@@ -156,7 +156,7 @@ namespace __gnu_cxx {
   {
     size_t operator()( const pg_t& x ) const
     {
-      static hash<uint64_t> H;
+      static rjhash<uint64_t> H;
       return H(x);
     }
   };