From: Yehuda Sadeh Date: Thu, 25 Jun 2020 20:49:09 +0000 (-0700) Subject: rgw: cr: add prealloc_stack() X-Git-Tag: v16.1.0~421^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7970f355497f48ee5a18bf3a0bc034226c6d225c;p=ceph.git rgw: cr: add prealloc_stack() Can now preallocate stack before it is spawned, so that its id can be used. Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_coroutine.cc b/src/rgw/rgw_coroutine.cc index 512ead62d33..e5f9f9927ca 100644 --- a/src/rgw/rgw_coroutine.cc +++ b/src/rgw/rgw_coroutine.cc @@ -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); diff --git a/src/rgw/rgw_coroutine.h b/src/rgw/rgw_coroutine.h index f589b4eac5d..0d0b48bddc8 100644 --- a/src/rgw/rgw_coroutine.h +++ b/src/rgw/rgw_coroutine.h @@ -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 blocked_by_stack; set 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);