]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os: free space tracking for MemStore
authorJohn Spray <john.spray@redhat.com>
Tue, 30 Sep 2014 18:14:38 +0000 (19:14 +0100)
committerJohn Spray <john.spray@redhat.com>
Mon, 15 Dec 2014 12:15:33 +0000 (12:15 +0000)
Allow users to set an artificial upper bound
on size of the memstore OSD, and report actual
usage information in fsstat.

This is a useful tool for simulating nearly-full
systems.

Signed-off-by: John Spray <john.spray@redhat.com>
src/common/config_opts.h
src/os/MemStore.cc
src/os/MemStore.h

index a8be56922412a10e2223571dbbe4159fbc761ec5..2cdd59e91b2c0177526af3b6f14156310c318565 100644 (file)
@@ -673,6 +673,8 @@ OPTION(osd_bench_large_size_max_throughput, OPT_U64, 100 << 20) // 100 MB/s
 OPTION(osd_bench_max_block_size, OPT_U64, 64 << 20) // cap the block size at 64MB
 OPTION(osd_bench_duration, OPT_U32, 30) // duration of 'osd bench', capped at 30s to avoid triggering timeouts
 
+OPTION(memstore_device_bytes, OPT_U32, 1024*1024*1024)
+
 OPTION(filestore_omap_backend, OPT_STR, "leveldb")
 
 OPTION(filestore_debug_disable_sharded_check, OPT_BOOL, false)
index 85c04aac457fb3571fab3ecd3bf263762af2e2bd..57296eacf54bcaec06fbbb43f89b1eab9deef4e3 100644 (file)
@@ -174,6 +174,7 @@ int MemStore::_load()
     bufferlist::iterator p = cbl.begin();
     c->decode(p);
     coll_map[*q] = c;
+    used_bytes += c->used_bytes();
   }
 
   fn = path + "/sharded";
@@ -234,11 +235,14 @@ int MemStore::mkfs()
 int MemStore::statfs(struct statfs *st)
 {
   dout(10) << __func__ << dendl;
-  // make some shit up.  these are the only fields that matter.
   st->f_bsize = 1024;
-  st->f_blocks = 1000000;
-  st->f_bfree =  1000000;
-  st->f_bavail = 1000000;
+
+  // Device size is a configured constant
+  st->f_blocks = g_conf->memstore_device_bytes / st->f_bsize;
+
+  dout(10) << __func__ << ": used_bytes: " << used_bytes << "/" << g_conf->memstore_device_bytes << dendl;
+  st->f_bfree = st->f_bavail = MAX((st->f_blocks - used_bytes / st->f_bsize), 0);
+
   return 0;
 }
 
@@ -1072,7 +1076,10 @@ int MemStore::_write(coll_t cid, const ghobject_t& oid,
     c->object_hash[oid] = o;
   }
 
+  int old_size = o->data.length();
   _write_into_bl(bl, offset, &o->data);
+  used_bytes += (o->data.length() - old_size);
+
   return 0;
 }
 
@@ -1130,12 +1137,14 @@ int MemStore::_truncate(coll_t cid, const ghobject_t& oid, uint64_t size)
   if (o->data.length() > size) {
     bufferlist bl;
     bl.substr_of(o->data, 0, size);
+    used_bytes -= o->data.length() - size;
     o->data.claim(bl);
   } else if (o->data.length() == size) {
     // do nothing
   } else {
     bufferptr bp(size - o->data.length());
     bp.zero();
+    used_bytes += bp.length();
     o->data.append(bp);
   }
   return 0;
@@ -1154,6 +1163,9 @@ int MemStore::_remove(coll_t cid, const ghobject_t& oid)
     return -ENOENT;
   c->object_map.erase(oid);
   c->object_hash.erase(oid);
+
+  used_bytes -= o->data.length();
+
   return 0;
 }
 
@@ -1225,6 +1237,7 @@ int MemStore::_clone(coll_t cid, const ghobject_t& oldoid,
     c->object_map[newoid] = no;
     c->object_hash[newoid] = no;
   }
+  used_bytes += oo->data.length() - no->data.length();
   no->data = oo->data;
   no->omap_header = oo->omap_header;
   no->omap = oo->omap;
@@ -1260,7 +1273,11 @@ int MemStore::_clone_range(coll_t cid, const ghobject_t& oldoid,
     len = oo->data.length() - srcoff;
   bufferlist bl;
   bl.substr_of(oo->data, srcoff, len);
+
+  int old_size = no->data.length();
   _write_into_bl(bl, dstoff, &no->data);
+  used_bytes += (no->data.length() - old_size);
+
   return len;
 }
 
@@ -1372,6 +1389,7 @@ int MemStore::_destroy_collection(coll_t cid)
     if (!cp->second->object_map.empty())
       return -ENOTEMPTY;
   }
+  used_bytes -= cp->second->used_bytes();
   coll_map.erase(cp);
   return 0;
 }
index 078959781eed59d893c1f446612060d8ec09624d..8a99b99e81f685ab3ccf071b0f2832072d5e6eb3 100644 (file)
@@ -123,6 +123,17 @@ public:
       DECODE_FINISH(p);
     }
 
+    uint64_t used_bytes() const {
+      uint64_t result = 0;
+      for (map<ghobject_t, ObjectRef>::const_iterator p = object_map.begin();
+          p != object_map.end();
+          ++p) {
+        result += p->second->data.length();
+      }
+
+      return result;
+    }
+
     Collection() : lock("MemStore::Collection::lock") {}
   };
   typedef ceph::shared_ptr<Collection> CollectionRef;
@@ -182,6 +193,8 @@ private:
 
   Finisher finisher;
 
+  uint64_t used_bytes;
+
   void _do_transaction(Transaction& t);
 
   void _write_into_bl(const bufferlist& src, unsigned offset, bufferlist *dst);
@@ -232,7 +245,8 @@ public:
       coll_lock("MemStore::coll_lock"),
       apply_lock("MemStore::apply_lock"),
       finisher(cct),
-      sharded(false) { }
+      used_bytes(0),
+      sharded(false) {}
   ~MemStore() { }
 
   bool need_journal() { return false; };