Skip to contentSkip to conversation

osd: avoid flushing every TEMP removal to speedup startup

PATCH In review Alexandre Oliva 2 participants 3 messages May 18, 2014 – May 19, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 osd: avoid flushing every TEMP removal to speedup startup

When a btrfs OSD suicides because it couldn't keep up with others (recovery included), it is often the case that the filesystem is in a state in which creating and removing snapshots takes a long time. It is likely that there are going to be plenty of recovering PGs (with corresponding TEMP directories), and we will create and remove a btrfs snapshot for every such directory we remove at startup. This is very
wasteful: there's no reason to not pile up as many removals as possible before syncing and flushing the removal so as to force a btrfs snapshot.

This patch introduces an optional argument to the function used to remove PGs to control whether or not to perform the final flush. The flush still happens if the call does not pass that argument, but with the patch, the startup removals skip the per-PG flush, and run a single flush at the end.

---
 src/osd/OSD.cc |   12 +++++++++---
 src/osd/OSD.h  |    3 ++-
 2 files changed, 11 insertions(+), 4 deletions(-)
src/osd/OSD.cc +9 -3
index 4240ba8..504cb71 100644
@@ -1774,7 +1774,8 @@ int OSD::read_superblock()
 
 
 
-void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp)
+void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp,
+				      bool flush)
 {
   OSDriver driver(
     store,
@@ -1810,7 +1811,8 @@ void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp)
   t.remove_collection(tmp);
   int r = store->apply_transaction(t);
   assert(r == 0);
-  store->sync_and_flush();
+  if (flush)
+    store->sync_and_flush();
 }
 
 
@@ -2046,6 +2048,7 @@ void OSD::load_pgs()
 
   set<spg_t> head_pgs;
   map<spg_t, interval_set<snapid_t> > pgs;
+  bool flush = false;
   for (vector<coll_t>::iterator it = ls.begin();
        it != ls.end();
        ++it) {
@@ -2056,7 +2059,8 @@ void OSD::load_pgs()
     if (it->is_temp(pgid) ||
 	it->is_removal(&seq, &pgid)) {
       dout(10) << "load_pgs " << *it << " clearing temp" << dendl;
-      recursive_remove_collection(store, *it);
+      recursive_remove_collection(store, *it, false);
+      flush = true;
       continue;
     }
 
@@ -2074,6 +2078,8 @@ void OSD::load_pgs()
 
     dout(10) << "load_pgs ignoring unrecognized " << *it << dendl;
   }
+  if (flush)
+    store->sync_and_flush();
 
   bool has_upgraded = false;
   for (map<spg_t, interval_set<snapid_t> >::iterator i = pgs.begin();
src/osd/OSD.h +2 -1
index ce8b74c..f599e43 100644
@@ -870,7 +870,8 @@ public:
     hobject_t oid(sobject_t("infos", CEPH_NOSNAP));
     return oid;
   }
-  static void recursive_remove_collection(ObjectStore *store, coll_t tmp);
+  static void recursive_remove_collection(ObjectStore *store, coll_t tmp,
+					  bool flush = true);
 
   /**
    * get_osd_initial_compat_set()
Signature · 4 lines
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer
#1 lore raw

Why would the osd need to create and remove 1 btrfs snapshot per temp directory? -Sam

Quoted 97 lines · Alexandre Oliva

When a btrfs OSD suicides because it couldn't keep up with others (recovery included), it is often the case that the filesystem is in a state in which creating and removing snapshots takes a long time. It is likely that there are going to be plenty of recovering PGs (with corresponding TEMP directories), and we will create and remove a btrfs snapshot for every such directory we remove at startup. This is very
wasteful: there's no reason to not pile up as many removals as possible before syncing and flushing the removal so as to force a btrfs snapshot.

This patch introduces an optional argument to the function used to remove PGs to control whether or not to perform the final flush. The flush still happens if the call does not pass that argument, but with the patch, the startup removals skip the per-PG flush, and run a single flush at the end.

---
 src/osd/OSD.cc |   12 +++++++++---
 src/osd/OSD.h  |    3 ++-
 2 files changed, 11 insertions(+), 4 deletions(-)
src/osd/OSD.cc +9 -3
index 4240ba8..504cb71 100644
@@ -1774,7 +1774,8 @@ int OSD::read_superblock()
 
 
 
-void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp)
+void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp,
+                                     bool flush)
 {
   OSDriver driver(
     store,
@@ -1810,7 +1811,8 @@ void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp)
   t.remove_collection(tmp);
   int r = store->apply_transaction(t);
   assert(r == 0);
-  store->sync_and_flush();
+  if (flush)
+    store->sync_and_flush();
 }
 
 
@@ -2046,6 +2048,7 @@ void OSD::load_pgs()
 
   set<spg_t> head_pgs;
   map<spg_t, interval_set<snapid_t> > pgs;
+  bool flush = false;
   for (vector<coll_t>::iterator it = ls.begin();
        it != ls.end();
        ++it) {
@@ -2056,7 +2059,8 @@ void OSD::load_pgs()
     if (it->is_temp(pgid) ||
        it->is_removal(&seq, &pgid)) {
       dout(10) << "load_pgs " << *it << " clearing temp" << dendl;
-      recursive_remove_collection(store, *it);
+      recursive_remove_collection(store, *it, false);
+      flush = true;
       continue;
     }
 
@@ -2074,6 +2078,8 @@ void OSD::load_pgs()
 
     dout(10) << "load_pgs ignoring unrecognized " << *it << dendl;
   }
+  if (flush)
+    store->sync_and_flush();
 
   bool has_upgraded = false;
   for (map<spg_t, interval_set<snapid_t> >::iterator i = pgs.begin();
src/osd/OSD.h +2 -2
index ce8b74c..f599e43 100644
@@ -870,7 +870,8 @@ public:
     hobject_t oid(sobject_t("infos", CEPH_NOSNAP));
     return oid;
   }
-  static void recursive_remove_collection(ObjectStore *store, coll_t tmp);
+  static void recursive_remove_collection(ObjectStore *store, coll_t tmp,
+                                         bool flush = true);
 
   /**
    * get_osd_initial_compat_set()
 
--

Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer --
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Nvm, sync_and_flush forces a sync for non-writeahead journals. -Sam

Quoted 101 lines · Samuel Just

Why would the osd need to create and remove 1 btrfs snapshot per temp directory? -Sam

Quoted 97 lines · Alexandre Oliva

When a btrfs OSD suicides because it couldn't keep up with others (recovery included), it is often the case that the filesystem is in a state in which creating and removing snapshots takes a long time. It is likely that there are going to be plenty of recovering PGs (with corresponding TEMP directories), and we will create and remove a btrfs snapshot for every such directory we remove at startup. This is very
wasteful: there's no reason to not pile up as many removals as possible before syncing and flushing the removal so as to force a btrfs snapshot.

This patch introduces an optional argument to the function used to remove PGs to control whether or not to perform the final flush. The flush still happens if the call does not pass that argument, but with the patch, the startup removals skip the per-PG flush, and run a single flush at the end.

---
 src/osd/OSD.cc |   12 +++++++++---
 src/osd/OSD.h  |    3 ++-
 2 files changed, 11 insertions(+), 4 deletions(-)
src/osd/OSD.cc +9 -3
index 4240ba8..504cb71 100644
@@ -1774,7 +1774,8 @@ int OSD::read_superblock()
 
 
 
-void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp)
+void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp,
+                                     bool flush)
 {
   OSDriver driver(
     store,
@@ -1810,7 +1811,8 @@ void OSD::recursive_remove_collection(ObjectStore *store, coll_t tmp)
   t.remove_collection(tmp);
   int r = store->apply_transaction(t);
   assert(r == 0);
-  store->sync_and_flush();
+  if (flush)
+    store->sync_and_flush();
 }
 
 
@@ -2046,6 +2048,7 @@ void OSD::load_pgs()
 
   set<spg_t> head_pgs;
   map<spg_t, interval_set<snapid_t> > pgs;
+  bool flush = false;
   for (vector<coll_t>::iterator it = ls.begin();
        it != ls.end();
        ++it) {
@@ -2056,7 +2059,8 @@ void OSD::load_pgs()
     if (it->is_temp(pgid) ||
        it->is_removal(&seq, &pgid)) {
       dout(10) << "load_pgs " << *it << " clearing temp" << dendl;
-      recursive_remove_collection(store, *it);
+      recursive_remove_collection(store, *it, false);
+      flush = true;
       continue;
     }
 
@@ -2074,6 +2078,8 @@ void OSD::load_pgs()
 
     dout(10) << "load_pgs ignoring unrecognized " << *it << dendl;
   }
+  if (flush)
+    store->sync_and_flush();
 
   bool has_upgraded = false;
   for (map<spg_t, interval_set<snapid_t> >::iterator i = pgs.begin();
src/osd/OSD.h +2 -2
index ce8b74c..f599e43 100644
@@ -870,7 +870,8 @@ public:
     hobject_t oid(sobject_t("infos", CEPH_NOSNAP));
     return oid;
   }
-  static void recursive_remove_collection(ObjectStore *store, coll_t tmp);
+  static void recursive_remove_collection(ObjectStore *store, coll_t tmp,
+                                         bool flush = true);
 
   /**
    * get_osd_initial_compat_set()
 
--

Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer --
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html