From: Yan, Zheng Date: Mon, 9 Feb 2015 12:11:01 +0000 (+0800) Subject: mds: use compact_map/compact_set to optimize memory usage of CDir X-Git-Tag: v9.0.0~201^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=96a85e7868bfbbe5aa80c527b4f959aeb04daa98;p=ceph.git mds: use compact_map/compact_set to optimize memory usage of CDir define some rarely used containers as compact_map/compact_set. Each replacement can save 40 bytes for 64 bits program. Signed-off-by: Yan, Zheng --- diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index 903b1916c45..50e645ed2ae 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -1166,7 +1166,7 @@ void CDir::take_dentry_waiting(const string& dname, snapid_t first, snapid_t las string_snap_t lb(dname, first); string_snap_t ub(dname, last); - map >::iterator p = waiting_on_dentry.lower_bound(lb); + compact_map >::iterator p = waiting_on_dentry.lower_bound(lb); while (p != waiting_on_dentry.end() && !(ub < p->first)) { dout(10) << "take_dentry_waiting dentry " << dname @@ -1185,7 +1185,7 @@ void CDir::take_sub_waiting(list& ls) { dout(10) << "take_sub_waiting" << dendl; if (!waiting_on_dentry.empty()) { - for (map >::iterator p = waiting_on_dentry.begin(); + for (compact_map >::iterator p = waiting_on_dentry.begin(); p != waiting_on_dentry.end(); ++p) ls.splice(ls.end(), p->second); @@ -1232,7 +1232,7 @@ void CDir::take_waiting(uint64_t mask, list& ls) if ((mask & WAIT_DENTRY) && !waiting_on_dentry.empty()) { // take all dentry waiters while (!waiting_on_dentry.empty()) { - map >::iterator p = waiting_on_dentry.begin(); + compact_map >::iterator p = waiting_on_dentry.begin(); dout(10) << "take_waiting dentry " << p->first.name << " snap " << p->first.snapid << " on " << *this << dendl; ls.splice(ls.end(), p->second); @@ -2142,9 +2142,9 @@ void CDir::_committed(int r, version_t v) // finishers? bool were_waiters = !waiting_for_commit.empty(); - map >::iterator p = waiting_for_commit.begin(); + compact_map >::iterator p = waiting_for_commit.begin(); while (p != waiting_for_commit.end()) { - map >::iterator n = p; + compact_map >::iterator n = p; ++n; if (p->first > committed_version) { dout(10) << " there are waiters for " << p->first << ", committing again" << dendl; diff --git a/src/mds/CDir.h b/src/mds/CDir.h index 75ddd12d8b0..b25ea2ab65f 100644 --- a/src/mds/CDir.h +++ b/src/mds/CDir.h @@ -170,7 +170,7 @@ public: fnode_t fnode; snapid_t first; - std::map dirty_old_rstat; // [value.first,key] + compact_map dirty_old_rstat; // [value.first,key] // my inodes with dirty rstat data elist dirty_rstat_inodes; @@ -258,7 +258,7 @@ protected: // cache control (defined for authority; hints for replicas) __s32 dir_rep; - std::set<__s32> dir_rep_by; // if dir_rep == REP_LIST + compact_set<__s32> dir_rep_by; // if dir_rep == REP_LIST // popularity dirfrag_load_vec_t pop_me; @@ -502,7 +502,7 @@ protected: void _tmap_fetched(bufferlist &bl, const std::string& want_dn, int r); // -- commit -- - std::map > waiting_for_commit; + compact_map > waiting_for_commit; void _commit(version_t want, int op_prio); void _omap_commit(int op_prio); void _encode_dentry(CDentry *dn, bufferlist& bl, const std::set *snaps); @@ -539,7 +539,7 @@ public: // -- waiters -- protected: - std::map< string_snap_t, std::list > waiting_on_dentry; + compact_map< string_snap_t, std::list > waiting_on_dentry; public: bool is_waiting_for_dentry(const std::string& dname, snapid_t snap) { diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 4569234116f..d87c11d0df3 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -1649,7 +1649,7 @@ void CInode::decode_lock_state(int type, bufferlist& bl) snapid_t fgfirst; nest_info_t rstat; nest_info_t accounted_rstat; - map dirty_old_rstat; + compact_map dirty_old_rstat; ::decode(fg, p); ::decode(fgfirst, p); ::decode(rstat, p); @@ -2032,7 +2032,7 @@ void CInode::finish_scatter_gather_update(int type) dout(20) << fg << " dirty_old_rstat " << dir->dirty_old_rstat << dendl; mdcache->project_rstat_frag_to_inode(pf->rstat, pf->accounted_rstat, dir->first, CEPH_NOSNAP, this, true); - for (map::iterator q = dir->dirty_old_rstat.begin(); + for (compact_map::iterator q = dir->dirty_old_rstat.begin(); q != dir->dirty_old_rstat.end(); ++q) mdcache->project_rstat_frag_to_inode(q->second.rstat, q->second.accounted_rstat, diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 2cac326924b..84d47b00949 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -1794,7 +1794,7 @@ void MDCache::_project_rstat_inode_to_frag(inode_t& inode, snapid_t ofirst, snap first = ofirst; // find any intersection with last - map::iterator p = parent->dirty_old_rstat.lower_bound(last); + compact_map::iterator p = parent->dirty_old_rstat.lower_bound(last); if (p == parent->dirty_old_rstat.end()) { dout(20) << " no dirty_old_rstat with last >= last " << last << dendl; if (!parent->dirty_old_rstat.empty() && parent->dirty_old_rstat.rbegin()->first >= first) { @@ -2241,7 +2241,7 @@ void MDCache::predirty_journal_parents(MutationRef mut, EMetaBlob *blob, // first, if the frag is stale, bring it back in sync. parent->resync_accounted_rstat(); - for (map::iterator p = parent->dirty_old_rstat.begin(); + for (compact_map::iterator p = parent->dirty_old_rstat.begin(); p != parent->dirty_old_rstat.end(); ++p) project_rstat_frag_to_inode(p->second.rstat, p->second.accounted_rstat, p->second.first, p->first, pin, true);//false); diff --git a/src/messages/MDirUpdate.h b/src/messages/MDirUpdate.h index 39ea23b64ce..727db238d31 100644 --- a/src/messages/MDirUpdate.h +++ b/src/messages/MDirUpdate.h @@ -23,14 +23,14 @@ class MDirUpdate : public Message { dirfrag_t dirfrag; int32_t dir_rep; int32_t discover; - set dir_rep_by; + compact_set dir_rep_by; filepath path; public: mds_rank_t get_source_mds() const { return from_mds; } dirfrag_t get_dirfrag() const { return dirfrag; } int get_dir_rep() const { return dir_rep; } - const set& get_dir_rep_by() const { return dir_rep_by; } + const compact_set& get_dir_rep_by() const { return dir_rep_by; } bool should_discover() const { return discover > 0; } const filepath& get_path() const { return path; } @@ -42,7 +42,7 @@ class MDirUpdate : public Message { MDirUpdate(mds_rank_t f, dirfrag_t dirfrag, int dir_rep, - set& dir_rep_by, + compact_set& dir_rep_by, filepath& path, bool discover = false) : Message(MSG_MDS_DIRUPDATE) {