Skip to content

Commit

Permalink
osd/OSDMap: cache get_up_osd_features
Browse files Browse the repository at this point in the history
This method is O(n) and called from in a few places for each IO operation.
Cache the value since it does not change over the lifetime of a single
epoch.  Invalidate on apply_incremental() and decode.

Signed-off-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Feb 23, 2015
1 parent ec922a6 commit e0e765f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/osd/OSDMap.cc
Expand Up @@ -1090,22 +1090,26 @@ uint64_t OSDMap::get_features(int entity_type, uint64_t *pmask) const
return features;
}

uint64_t OSDMap::get_up_osd_features() const
void OSDMap::_calc_up_osd_features()
{
bool first = true;
uint64_t features = 0;
cached_up_osd_features = 0;
for (int osd = 0; osd < max_osd; ++osd) {
if (!is_up(osd))
continue;
const osd_xinfo_t &xi = get_xinfo(osd);
if (first) {
features = xi.features;
cached_up_osd_features = xi.features;
first = false;
} else {
features &= xi.features;
cached_up_osd_features &= xi.features;
}
}
return features;
}

uint64_t OSDMap::get_up_osd_features() const
{
return cached_up_osd_features;
}

void OSDMap::dedup(const OSDMap *o, OSDMap *n)
Expand Down Expand Up @@ -1258,6 +1262,7 @@ int OSDMap::apply_incremental(const Incremental &inc)
return -EINVAL;

assert(inc.epoch == epoch+1);

epoch++;
modified = inc.modified;

Expand Down Expand Up @@ -1439,6 +1444,7 @@ int OSDMap::apply_incremental(const Incremental &inc)
}

calc_num_osds();
_calc_up_osd_features();
return 0;
}

Expand Down Expand Up @@ -2196,6 +2202,7 @@ void OSDMap::post_decode()
}

calc_num_osds();
_calc_up_osd_features();
}

void OSDMap::dump_erasure_code_profiles(const map<string,map<string,string> > &profiles,
Expand Down
5 changes: 5 additions & 0 deletions src/osd/OSDMap.h
Expand Up @@ -245,9 +245,13 @@ class OSDMap {
string cluster_snapshot;
bool new_blacklist_entries;

mutable uint64_t cached_up_osd_features;

mutable bool crc_defined;
mutable uint32_t crc;

void _calc_up_osd_features();

public:
bool have_crc() const { return crc_defined; }
uint32_t get_crc() const { return crc; }
Expand All @@ -269,6 +273,7 @@ class OSDMap {
osd_uuid(new vector<uuid_d>),
cluster_snapshot_epoch(0),
new_blacklist_entries(false),
cached_up_osd_features(0),
crc_defined(false), crc(0),
crush(new CrushWrapper) {
memset(&fsid, 0, sizeof(fsid));
Expand Down

0 comments on commit e0e765f

Please sign in to comment.