]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: cr: add prealloc_stack()
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 25 Jun 2020 20:49:09 +0000 (13:49 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 16 Jul 2020 19:23:50 +0000 (12:23 -0700)
Can now preallocate stack before it is spawned, so that its
id can be used.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_coroutine.cc
src/rgw/rgw_coroutine.h

index 512ead62d331f86d60cec3065f08fd30823435a3..e5f9f9927cae594c1a9b212ddd4a3ef26d14d383 100644 (file)
@@ -222,6 +222,10 @@ RGWCoroutinesStack::~RGWCoroutinesStack()
   for (auto stack : spawned.entries) {
     stack->put();
   }
+
+  if (preallocated_stack) {
+    preallocated_stack->put();
+  }
 }
 
 int RGWCoroutinesStack::operate(RGWCoroutinesEnv *_env)
@@ -293,7 +297,12 @@ RGWCoroutinesStack *RGWCoroutinesStack::spawn(RGWCoroutine *source_op, RGWCorout
 
   rgw_spawned_stacks *s = (source_op ? &source_op->spawned : &spawned);
 
-  RGWCoroutinesStack *stack = env->manager->allocate_stack();
+  RGWCoroutinesStack *stack = preallocated_stack;
+  if (!stack) {
+    stack = env->manager->allocate_stack();
+  }
+  preallocated_stack = nullptr;
+
   s->add_pending(stack);
   stack->parent = this;
 
@@ -314,6 +323,14 @@ RGWCoroutinesStack *RGWCoroutinesStack::spawn(RGWCoroutine *op, bool wait)
   return spawn(NULL, op, wait);
 }
 
+RGWCoroutinesStack *RGWCoroutinesStack::prealloc_stack()
+{
+  if (!preallocated_stack) {
+    preallocated_stack = env->manager->allocate_stack();
+  }
+  return preallocated_stack;
+}
+
 int RGWCoroutinesStack::wait(const utime_t& interval)
 {
   RGWCompletionManager *completion_mgr = env->manager->get_completion_mgr();
@@ -892,6 +909,16 @@ RGWCoroutinesStack *RGWCoroutine::spawn(RGWCoroutine *op, bool wait)
   return stack->spawn(this, op, wait);
 }
 
+RGWCoroutinesStack *RGWCoroutine::prealloc_stack()
+{
+  return stack->prealloc_stack();
+}
+
+uint64_t RGWCoroutine::prealloc_stack_id()
+{
+  return prealloc_stack()->get_id();
+}
+
 bool RGWCoroutine::collect(int *ret, RGWCoroutinesStack *skip_stack, uint64_t *stack_id) /* returns true if needs to be called again */
 {
   return stack->collect(this, ret, skip_stack, stack_id);
index f589b4eac5d0870907598fff9578c2c422acae68..0d0b48bddc8395b2a80a90aeedd0fe00d9dab9c6 100644 (file)
@@ -302,6 +302,9 @@ public:
   bool collect(int *ret, RGWCoroutinesStack *skip_stack, uint64_t *stack_id = nullptr); /* returns true if needs to be called again */
   bool collect_next(int *ret, RGWCoroutinesStack **collected_stack = NULL); /* returns true if found a stack to collect */
 
+  RGWCoroutinesStack *prealloc_stack(); /* prepare a stack that will be used in the next spawn operation */
+  uint64_t prealloc_stack_id(); /* prepare a stack that will be used in the next spawn operation, return its id */
+
   int wait(const utime_t& interval);
   bool drain_children(int num_cr_left,
                       RGWCoroutinesStack *skip_stack = nullptr,
@@ -434,6 +437,8 @@ class RGWCoroutinesStack : public RefCountedObject {
 
   rgw_spawned_stacks spawned;
 
+  RGWCoroutinesStack *preallocated_stack{nullptr};
+
   set<RGWCoroutinesStack *> blocked_by_stack;
   set<RGWCoroutinesStack *> blocking_stacks;
 
@@ -531,6 +536,7 @@ public:
 
   void call(RGWCoroutine *next_op);
   RGWCoroutinesStack *spawn(RGWCoroutine *next_op, bool wait);
+  RGWCoroutinesStack *prealloc_stack();
   int unwind(int retcode);
 
   int wait(const utime_t& interval);