Skip to content

Commit 40a0f96

Browse files
committed
---
yaml --- r: 6785 b: refs/heads/master c: 0ed5117 h: refs/heads/master i: 6783: d3cdcbd v: v3
1 parent bac7cb9 commit 40a0f96

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c1a2c2f6b0340bfd1a82ff7c3a0a8a76951969ac
2+
refs/heads/master: 0ed5117a9d1cdf0024b8c14d810a71d48c365350

trunk/src/rt/rust_env.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,14 @@ get_num_threads()
6767
return get_num_cpus();
6868
}
6969

70-
// FIXME (issue #151): This should be 0x300; the change here is for
71-
// practicality's sake until stack growth is working.
72-
7370
static size_t
7471
get_min_stk_size() {
7572
char *stack_size = getenv(RUST_MIN_STACK);
7673
if(stack_size) {
7774
return strtol(stack_size, NULL, 0);
7875
}
7976
else {
80-
return 0x300000;
77+
return 0x300;
8178
}
8279
}
8380

trunk/src/rt/rust_task.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <iostream>
1212
#include <cassert>
1313
#include <cstring>
14+
#include <algorithm>
1415

1516
#include "globals.h"
1617

@@ -44,25 +45,55 @@ get_min_stk_size(size_t default_size) {
4445
}
4546
}
4647

48+
static size_t
49+
get_next_stk_size(rust_scheduler *sched, rust_task *task,
50+
size_t min, size_t current, size_t requested) {
51+
LOG(task, mem, "calculating new stack size for 0x%" PRIxPTR, task);
52+
LOG(task, mem,
53+
"min: %" PRIdPTR " current: %" PRIdPTR " requested: %" PRIdPTR,
54+
min, current, requested);
55+
56+
// Allocate at least enough to accomodate the next frame
57+
size_t sz = std::max(min, requested);
58+
59+
// And double the stack size each allocation
60+
const size_t max = 1024 * 1024;
61+
size_t next = std::min(max, current * 2);
62+
63+
sz = std::max(sz, next);
64+
65+
LOG(task, mem, "next stack size: %" PRIdPTR, sz);
66+
return sz;
67+
}
4768

4869
// Task stack segments. Heap allocated and chained together.
4970

5071
static stk_seg*
51-
new_stk(rust_scheduler *sched, rust_task *task, size_t minsz)
72+
new_stk(rust_scheduler *sched, rust_task *task, size_t requested_sz)
5273
{
53-
size_t min_stk_bytes = get_min_stk_size(sched->min_stack_size);
54-
if (minsz < min_stk_bytes)
55-
minsz = min_stk_bytes;
56-
size_t sz = sizeof(stk_seg) + minsz + RED_ZONE_SIZE;
74+
// The minimum stack size, in bytes, of a Rust stack, excluding red zone
75+
size_t min_sz = get_min_stk_size(sched->min_stack_size);
76+
// The size of the current stack segment, excluding red zone
77+
size_t current_sz = 0;
78+
if (task->stk != NULL) {
79+
current_sz = (size_t)(task->stk->end
80+
- (uintptr_t)&task->stk->data[0]
81+
- RED_ZONE_SIZE);
82+
}
83+
// The calculated size of the new stack, excluding red zone
84+
size_t rust_stk_sz = get_next_stk_size(sched, task, min_sz,
85+
current_sz, requested_sz);
86+
87+
size_t sz = sizeof(stk_seg) + rust_stk_sz + RED_ZONE_SIZE;
5788
stk_seg *stk = (stk_seg *)task->malloc(sz, "stack");
5889
LOGPTR(task->sched, "new stk", (uintptr_t)stk);
5990
memset(stk, 0, sizeof(stk_seg));
6091
stk->next = task->stk;
61-
stk->end = (uintptr_t) &stk->data[minsz + RED_ZONE_SIZE];
92+
stk->end = (uintptr_t) &stk->data[rust_stk_sz + RED_ZONE_SIZE];
6293
LOGPTR(task->sched, "stk end", stk->end);
6394
stk->valgrind_id =
6495
VALGRIND_STACK_REGISTER(&stk->data[0],
65-
&stk->data[minsz + RED_ZONE_SIZE]);
96+
&stk->data[rust_stk_sz + RED_ZONE_SIZE]);
6697
#ifndef NVALGRIND
6798
VALGRIND_MAKE_MEM_NOACCESS(stk->data, STACK_NOACCESS_SIZE);
6899
#endif

0 commit comments

Comments
 (0)