]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
fragtree_t: define fragtree_t::_splits as compact_map
authorYan, Zheng <zyan@redhat.com>
Fri, 6 Feb 2015 11:11:53 +0000 (19:11 +0800)
committerYan, Zheng <zyan@redhat.com>
Wed, 25 Feb 2015 12:12:13 +0000 (20:12 +0800)
In most case, directory inode only contain one dirfrag. So fragtree_t
for most directory inode is empty. define fragtree_t::_splits as
compact_map can reduce memory usage of CInode.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/include/frag.h
src/mds/CInode.cc
src/messages/MClientReply.h

index 60bb0cd9b265c03860ebd31926520f82212cdeea..1b4716422de5f125eb86e382f206a0d524171850 100644 (file)
 #define CEPH_FRAG_H
 
 #include <stdint.h>
-#include <map>
 #include <list>
 #include <iostream>
 #include <stdio.h>
 
 #include "buffer.h"
+#include "compact_map.h"
 
 #include "ceph_frag.h"
 #include "include/assert.h"
@@ -177,7 +177,7 @@ class fragtree_t {
   //  frag_t f is split by b bits.
   //  if child frag_t does not appear, it is not split.
 public:
-  std::map<frag_t,int32_t> _splits;  
+  compact_map<frag_t,int32_t> _splits;
 
 public:
   // -------------
@@ -195,7 +195,7 @@ public:
     return _splits.empty();
   }
   int get_split(const frag_t hb) const {
-    std::map<frag_t,int32_t>::const_iterator p = _splits.find(hb);
+    compact_map<frag_t,int32_t>::const_iterator p = _splits.find(hb);
     if (p == _splits.end())
       return 0;
     else
@@ -459,6 +459,22 @@ public:
   void decode(bufferlist::iterator& p) {
     ::decode(_splits, p);
   }
+  void encode_nohead(bufferlist& bl) const {
+    for (compact_map<frag_t,int32_t>::const_iterator p = _splits.begin();
+        p != _splits.end();
+        ++p) {
+      ::encode(p->first, bl);
+      ::encode(p->second, bl);
+    }
+  }
+  void decode_nohead(int n, bufferlist::iterator& p) {
+    _splits.clear();
+    while (n-- > 0) {
+      frag_t f;
+      ::decode(f, p);
+      ::decode(_splits[f], p);
+    }
+  }
 
   void print(std::ostream& out) {
     out << "fragtree_t(";
@@ -496,9 +512,9 @@ inline std::ostream& operator<<(std::ostream& out, const fragtree_t& ft)
 {
   out << "fragtree_t(";
   
-  for (std::map<frag_t,int32_t>::const_iterator p = ft._splits.begin();
+  for (compact_map<frag_t,int32_t>::const_iterator p = ft._splits.begin();
        p != ft._splits.end();
-       p++) {
+       ++p) {
     if (p != ft._splits.begin())
       out << " ";
     out << p->first << "^" << p->second;
index 779efbf4611161a8edc37f364ab1dee79129d490..e98c74af08b72b9468da7d86968a2c2dd8c5c513 100644 (file)
@@ -3202,12 +3202,9 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
   // encode
   e.fragtree.nsplits = dirfragtree._splits.size();
   ::encode(e, bl);
-  for (map<frag_t,int32_t>::iterator p = dirfragtree._splits.begin();
-       p != dirfragtree._splits.end();
-       ++p) {
-    ::encode(p->first, bl);
-    ::encode(p->second, bl);
-  }
+
+  dirfragtree.encode_nohead(bl);
+
   ::encode(symlink, bl);
   if (session->connection->has_feature(CEPH_FEATURE_DIRLAYOUTHASH)) {
     i = pfile ? pi : oi;
index 0a28a63c7c3f6481734901264c7d5637f8ff56fb..d3ee05e9537b75240778dc8bd2cbb0561e5354fc 100644 (file)
@@ -159,13 +159,8 @@ struct InodeStat {
     rstat.rfiles = e.rfiles;
     rstat.rsubdirs = e.rsubdirs;
 
-    int n = e.fragtree.nsplits;
-    while (n) {
-      ceph_frag_tree_split s;
-      ::decode(s, p);
-      dirfragtree._splits[(__u32)s.frag] = s.by;
-      n--;
-    }
+    dirfragtree.decode_nohead(e.fragtree.nsplits, p);
+
     ::decode(symlink, p);
     
     if (features & CEPH_FEATURE_DIRLAYOUTHASH)