From: John Spray Date: Tue, 30 Sep 2014 18:14:38 +0000 (+0100) Subject: os: free space tracking for MemStore X-Git-Tag: v0.91~47^2~18 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7e8403411ed90e1dddaa660a66fb2455676df133;p=ceph.git os: free space tracking for MemStore 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 --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index a8be56922412..2cdd59e91b2c 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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) diff --git a/src/os/MemStore.cc b/src/os/MemStore.cc index 85c04aac457f..57296eacf54b 100644 --- a/src/os/MemStore.cc +++ b/src/os/MemStore.cc @@ -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; } diff --git a/src/os/MemStore.h b/src/os/MemStore.h index 078959781eed..8a99b99e81f6 100644 --- a/src/os/MemStore.h +++ b/src/os/MemStore.h @@ -123,6 +123,17 @@ public: DECODE_FINISH(p); } + uint64_t used_bytes() const { + uint64_t result = 0; + for (map::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 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; };