mcexec: RLIMIT_STACK handling
This commit is contained in:
@@ -1318,6 +1318,9 @@ static struct option mcexec_options[] = {
|
|||||||
{ NULL, 0, NULL, 0, },
|
{ NULL, 0, NULL, 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MCEXEC_DEF_CUR_STACK_SIZE (2 * 1024 * 1024) /* 2 MiB */
|
||||||
|
#define MCEXEC_DEF_MAX_STACK_SIZE (64 * 1024 * 1024) /* 64 MiB */
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// int fd;
|
// int fd;
|
||||||
@@ -1350,16 +1353,14 @@ int main(int argc, char **argv)
|
|||||||
if (!altroot) {
|
if (!altroot) {
|
||||||
altroot = "/usr/linux-k1om-4.7/linux-k1om";
|
altroot = "/usr/linux-k1om-4.7/linux-k1om";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Collect environment variables */
|
/* Collect environment variables */
|
||||||
envs_len = flatten_strings(-1, NULL, environ, &envs);
|
envs_len = flatten_strings(-1, NULL, environ, &envs);
|
||||||
envs = envs;
|
envs = envs;
|
||||||
|
|
||||||
error = getrlimit(RLIMIT_STACK, &rlim_stack);
|
rlim_stack.rlim_cur = MCEXEC_DEF_CUR_STACK_SIZE;
|
||||||
if (error) {
|
rlim_stack.rlim_max = MCEXEC_DEF_MAX_STACK_SIZE;
|
||||||
fprintf(stderr, "Error: Failed to get stack limit.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#define MCEXEC_MAX_STACK_SIZE (1024 * 1024 * 1024) /* 1 GiB */
|
#define MCEXEC_MAX_STACK_SIZE (1024 * 1024 * 1024) /* 1 GiB */
|
||||||
if (rlim_stack.rlim_cur > MCEXEC_MAX_STACK_SIZE) {
|
if (rlim_stack.rlim_cur > MCEXEC_MAX_STACK_SIZE) {
|
||||||
/* need to call reduce_stack() before modifying the argv[] */
|
/* need to call reduce_stack() before modifying the argv[] */
|
||||||
@@ -1367,7 +1368,7 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, "Error: Failed to reduce stack.\n");
|
fprintf(stderr, "Error: Failed to reduce stack.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse options ("+" denotes stop at the first non-option) */
|
/* Parse options ("+" denotes stop at the first non-option) */
|
||||||
while ((opt = getopt_long(argc, argv, "+c:n:t:m:", mcexec_options, NULL)) != -1) {
|
while ((opt = getopt_long(argc, argv, "+c:n:t:m:", mcexec_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
@@ -1584,14 +1585,15 @@ int main(int argc, char **argv)
|
|||||||
rlimit_stack_envname);
|
rlimit_stack_envname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (lmax > rlim_stack.rlim_max) {
|
|
||||||
lmax = rlim_stack.rlim_max;
|
|
||||||
}
|
|
||||||
if (lcur > lmax) {
|
if (lcur > lmax) {
|
||||||
lcur = lmax;
|
lcur = lmax;
|
||||||
}
|
}
|
||||||
rlim_stack.rlim_cur = lcur;
|
if (lmax > rlim_stack.rlim_max) {
|
||||||
rlim_stack.rlim_max = lmax;
|
rlim_stack.rlim_max = lmax;
|
||||||
|
}
|
||||||
|
if (lcur > rlim_stack.rlim_cur) {
|
||||||
|
rlim_stack.rlim_cur = lcur;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
desc->rlimit[MCK_RLIMIT_STACK].rlim_cur = rlim_stack.rlim_cur;
|
desc->rlimit[MCK_RLIMIT_STACK].rlim_cur = rlim_stack.rlim_cur;
|
||||||
desc->rlimit[MCK_RLIMIT_STACK].rlim_max = rlim_stack.rlim_max;
|
desc->rlimit[MCK_RLIMIT_STACK].rlim_max = rlim_stack.rlim_max;
|
||||||
|
|||||||
@@ -1918,9 +1918,14 @@ int init_process_stack(struct thread *thread, struct program_load_desc *pn,
|
|||||||
|
|
||||||
/* Create stack range */
|
/* Create stack range */
|
||||||
end = STACK_TOP(&thread->vm->region) & LARGE_PAGE_MASK;
|
end = STACK_TOP(&thread->vm->region) & LARGE_PAGE_MASK;
|
||||||
minsz = LARGE_PAGE_SIZE;
|
minsz = (proc->rlimit[MCK_RLIMIT_STACK].rlim_cur
|
||||||
size = (proc->rlimit[MCK_RLIMIT_STACK].rlim_cur
|
|
||||||
+ LARGE_PAGE_SIZE - 1) & LARGE_PAGE_MASK;
|
+ LARGE_PAGE_SIZE - 1) & LARGE_PAGE_MASK;
|
||||||
|
size = (proc->rlimit[MCK_RLIMIT_STACK].rlim_max
|
||||||
|
+ LARGE_PAGE_SIZE - 1) & LARGE_PAGE_MASK;
|
||||||
|
dkprintf("%s: rlim_max: %lu, rlim_cur: %lu\n",
|
||||||
|
__FUNCTION__,
|
||||||
|
proc->rlimit[MCK_RLIMIT_STACK].rlim_max,
|
||||||
|
proc->rlimit[MCK_RLIMIT_STACK].rlim_cur);
|
||||||
if (size > (USER_END / 2)) {
|
if (size > (USER_END / 2)) {
|
||||||
size = USER_END / 2;
|
size = USER_END / 2;
|
||||||
}
|
}
|
||||||
@@ -1933,7 +1938,8 @@ int init_process_stack(struct thread *thread, struct program_load_desc *pn,
|
|||||||
/* TODO: make threshold kernel or mcexec argument */
|
/* TODO: make threshold kernel or mcexec argument */
|
||||||
ap_flag = (size >= proc->mpol_threshold &&
|
ap_flag = (size >= proc->mpol_threshold &&
|
||||||
!(proc->mpol_flags & MPOL_NO_STACK)) ? IHK_MC_AP_USER : 0;
|
!(proc->mpol_flags & MPOL_NO_STACK)) ? IHK_MC_AP_USER : 0;
|
||||||
dkprintf("%s: size: %lu %s\n", __FUNCTION__, size,
|
dkprintf("%s: max size: %lu, mapped size: %lu %s\n",
|
||||||
|
__FUNCTION__, size, minsz,
|
||||||
ap_flag ? "(IHK_MC_AP_USER)" : "");
|
ap_flag ? "(IHK_MC_AP_USER)" : "");
|
||||||
|
|
||||||
stack = ihk_mc_alloc_aligned_pages(minsz >> PAGE_SHIFT,
|
stack = ihk_mc_alloc_aligned_pages(minsz >> PAGE_SHIFT,
|
||||||
|
|||||||
Reference in New Issue
Block a user