Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-04-27 04:41:56 +0300
committerAnna Henningsen <anna@addaleax.net>2020-04-29 06:13:42 +0300
commite7b99e027b2fe2fc0834bf2df9daf6d94b27f02b (patch)
treee280ed7486944384816c6a48f0a113c0195c629e /src/node_worker.cc
parentef85bd1908e9550e59dbfa16372b79c1a95ea2a8 (diff)
worker: add stack size resource limit option
Add `stackSizeMb` to the `resourceLimit` option group. Refs: https://github.com/nodejs/node/pull/31593#issuecomment-619633820 PR-URL: https://github.com/nodejs/node/pull/33085 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_worker.cc')
-rw-r--r--src/node_worker.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc
index 2043d84490b..1e1d9434cdd 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -39,6 +39,8 @@ using v8::Value;
namespace node {
namespace worker {
+constexpr double kMB = 1024 * 1024;
+
Worker::Worker(Environment* env,
Local<Object> wrap,
const std::string& url,
@@ -93,8 +95,6 @@ bool Worker::is_stopped() const {
void Worker::UpdateResourceConstraints(ResourceConstraints* constraints) {
constraints->set_stack_limit(reinterpret_cast<uint32_t*>(stack_base_));
- constexpr double kMB = 1024 * 1024;
-
if (resource_limits_[kMaxYoungGenerationSizeMb] > 0) {
constraints->set_max_young_generation_size_in_bytes(
resource_limits_[kMaxYoungGenerationSizeMb] * kMB);
@@ -589,9 +589,20 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
w->stopped_ = false;
+ if (w->resource_limits_[kStackSizeMb] > 0) {
+ if (w->resource_limits_[kStackSizeMb] * kMB < kStackBufferSize) {
+ w->resource_limits_[kStackSizeMb] = kStackBufferSize / kMB;
+ w->stack_size_ = kStackBufferSize;
+ } else {
+ w->stack_size_ = w->resource_limits_[kStackSizeMb] * kMB;
+ }
+ } else {
+ w->resource_limits_[kStackSizeMb] = w->stack_size_ / kMB;
+ }
+
uv_thread_options_t thread_options;
thread_options.flags = UV_THREAD_HAS_STACK_SIZE;
- thread_options.stack_size = kStackSize;
+ thread_options.stack_size = w->stack_size_;
int ret = uv_thread_create_ex(&w->tid_, &thread_options, [](void* arg) {
// XXX: This could become a std::unique_ptr, but that makes at least
// gcc 6.3 detect undefined behaviour when there shouldn't be any.
@@ -601,7 +612,7 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
// Leave a few kilobytes just to make sure we're within limits and have
// some space to do work in C++ land.
- w->stack_base_ = stack_top - (kStackSize - kStackBufferSize);
+ w->stack_base_ = stack_top - (w->stack_size_ - kStackBufferSize);
w->Run();
@@ -834,6 +845,7 @@ void InitWorker(Local<Object> target,
NODE_DEFINE_CONSTANT(target, kMaxYoungGenerationSizeMb);
NODE_DEFINE_CONSTANT(target, kMaxOldGenerationSizeMb);
NODE_DEFINE_CONSTANT(target, kCodeRangeSizeMb);
+ NODE_DEFINE_CONSTANT(target, kStackSizeMb);
NODE_DEFINE_CONSTANT(target, kTotalResourceLimitCount);
}