]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/OSD: preallocate for _get_pgs/_get_pgids to avoid reallocate. 25434/head
authorJianpeng Ma <jianpeng.ma@intel.com>
Fri, 7 Dec 2018 03:13:09 +0000 (11:13 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Fri, 7 Dec 2018 03:13:09 +0000 (11:13 +0800)
num_pgs is the most accurate value fore reserve when call _get_pgs &
_get_pgids.

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/osd/OSD.cc

index 3bdf8938fb2bd35141e90e845d3e360dcf585431..c172fef223eee60c1c5ccf45e7d4dc5fa91acdea 100644 (file)
@@ -3983,6 +3983,7 @@ PG* OSD::_make_pg(
 void OSD::_get_pgs(vector<PGRef> *v, bool clear_too)
 {
   v->clear();
+  v->reserve(get_num_pgs());
   for (auto& s : shards) {
     std::lock_guard l(s->shard_lock);
     for (auto& j : s->pg_slots) {
@@ -4000,6 +4001,7 @@ void OSD::_get_pgs(vector<PGRef> *v, bool clear_too)
 void OSD::_get_pgids(vector<spg_t> *v)
 {
   v->clear();
+  v->reserve(get_num_pgs());
   for (auto& s : shards) {
     std::lock_guard l(s->shard_lock);
     for (auto& j : s->pg_slots) {