From e901d42fb625fb1a94af6e01a468368733011a64 Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Tue, 7 Mar 2017 14:23:28 +0900 Subject: [PATCH] mcexec: --extend-heap-by: argument to specify heap extension size --- executer/include/uprotocol.h | 1 + executer/user/mcexec.c | 16 +++++++++++++-- kernel/host.c | 40 +++++++++++++++++++++++++++++++++--- kernel/include/process.h | 3 ++- kernel/include/syscall.h | 1 + kernel/process.c | 5 +++-- kernel/syscall.c | 1 + 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/executer/include/uprotocol.h b/executer/include/uprotocol.h index 22199f76..86936b23 100644 --- a/executer/include/uprotocol.h +++ b/executer/include/uprotocol.h @@ -129,6 +129,7 @@ struct program_load_desc { unsigned long interp_align; unsigned long mpol_flags; unsigned long mpol_threshold; + unsigned long heap_extension; int nr_processes; char shell_path[SHELL_PATH_MAX_LEN]; __cpu_set_unit cpu_set[PLD_CPU_SET_SIZE]; diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 48c5d259..f744a50c 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -160,6 +160,7 @@ static int mpol_no_stack = 0; static int mpol_no_bss = 0; static int no_bind_ikc_map = 0; static unsigned long mpol_threshold = 0; +static unsigned long heap_extension = (2*1024*1024); static int profile = 0; static int disable_sched_yield = 0; @@ -1116,7 +1117,7 @@ static int reduce_stack(struct rlimit *orig_rlim, char *argv[]) void print_usage(char **argv) { - fprintf(stderr, "usage: %s [-c target_core] [-n nr_partitions] [--mpol-threshold=N] [--mpol-no-heap] [--mpol-no-bss] [--mpol-no-stack] [] (program) [args...]\n", argv[0]); + fprintf(stderr, "usage: %s [-c target_core] [-n nr_partitions] [--mpol-threshold=N] [--enable-straight-map] [--extend-heap-by=N] [--mpol-no-heap] [--mpol-no-bss] [--mpol-no-stack] [] (program) [args...]\n", argv[0]); } void init_sigaction(void) @@ -1329,6 +1330,12 @@ static struct option mcexec_options[] = { .flag = &disable_sched_yield, .val = 1, }, + { + .name = "extend-heap-by", + .has_arg = required_argument, + .flag = NULL, + .val = 'h', + }, /* end */ { NULL, 0, NULL, 0, }, }; @@ -1381,7 +1388,7 @@ int main(int argc, char **argv) } /* 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:h:", mcexec_options, NULL)) != -1) { switch (opt) { case 'c': target_core = atoi(optarg); @@ -1399,6 +1406,10 @@ int main(int argc, char **argv) mpol_threshold = atol(optarg); break; + case 'h': + heap_extension = atol(optarg); + break; + case 0: /* long opt */ break; @@ -1788,6 +1799,7 @@ int main(int argc, char **argv) } desc->mpol_threshold = mpol_threshold; + desc->heap_extension = heap_extension; if (ioctl(fd, MCEXEC_UP_PREPARE_IMAGE, (unsigned long)desc) != 0) { perror("prepare"); diff --git a/kernel/host.c b/kernel/host.c index bfef4cd5..2fbc87dc 100644 --- a/kernel/host.c +++ b/kernel/host.c @@ -209,11 +209,44 @@ int prepare_process_ranges_args_envs(struct thread *thread, pn->at_entry += aout_base; } - vm->region.brk_start = - vm->region.brk_end = - vm->region.brk_end_allocated = + vm->region.brk_start = vm->region.brk_end = (vm->region.data_end + LARGE_PAGE_SIZE - 1) & LARGE_PAGE_MASK; +#if 0 + { + void *heap; + + dkprintf("%s: requested heap size: %lu\n", + __FUNCTION__, proc->heap_extension); + heap = ihk_mc_alloc_aligned_pages(proc->heap_extension >> PAGE_SHIFT, + LARGE_PAGE_P2ALIGN, IHK_MC_AP_NOWAIT | + (!(proc->mpol_flags & MPOL_NO_HEAP) ? IHK_MC_AP_USER : 0)); + + if (!heap) { + kprintf("%s: error: allocating heap\n", __FUNCTION__); + goto err; + } + + flags = VR_PROT_READ | VR_PROT_WRITE; + flags |= VRFLAG_PROT_TO_MAXPROT(flags); + if (add_process_memory_range(vm, vm->region.brk_start, + vm->region.brk_start + proc->heap_extension, + virt_to_phys(heap), + flags, NULL, 0, LARGE_PAGE_P2ALIGN, NULL) != 0) { + ihk_mc_free_pages(heap, proc->heap_extension >> PAGE_SHIFT); + kprintf("%s: error: adding memory range for heap\n", __FUNCTION__); + goto err; + } + + vm->region.brk_end_allocated = vm->region.brk_end + + proc->heap_extension; + dkprintf("%s: heap @ 0x%lx:%lu\n", + __FUNCTION__, vm->region.brk_start, proc->heap_extension); + } +#else + vm->region.brk_end_allocated = vm->region.brk_end; +#endif + /* Map, copy and update args and envs */ flags = VR_PROT_READ | VR_PROT_WRITE; flags |= VRFLAG_PROT_TO_MAXPROT(flags); @@ -433,6 +466,7 @@ static int process_msg_prepare_process(unsigned long rphys) proc->mpol_flags = pn->mpol_flags; proc->mpol_threshold = pn->mpol_threshold; proc->nr_processes = pn->nr_processes; + proc->heap_extension = pn->heap_extension; #ifdef PROFILE_ENABLE proc->profile = pn->profile; thread->profile = pn->profile; diff --git a/kernel/include/process.h b/kernel/include/process.h index fb1aa986..2642ae9e 100644 --- a/kernel/include/process.h +++ b/kernel/include/process.h @@ -534,9 +534,10 @@ struct process { long maxrss; long maxrss_children; - /* Memory policy flags */ + /* Memory policy flags and memory specific options */ unsigned long mpol_flags; size_t mpol_threshold; + unsigned long heap_extension; // perf_event int perf_status; diff --git a/kernel/include/syscall.h b/kernel/include/syscall.h index c12e6114..dc8929ce 100644 --- a/kernel/include/syscall.h +++ b/kernel/include/syscall.h @@ -194,6 +194,7 @@ struct program_load_desc { unsigned long interp_align; unsigned long mpol_flags; unsigned long mpol_threshold; + unsigned long heap_extension; int nr_processes; char shell_path[SHELL_PATH_MAX_LEN]; __cpu_set_unit cpu_set[PLD_CPU_SET_SIZE]; diff --git a/kernel/process.c b/kernel/process.c index 2475a0cf..ec8573a5 100644 --- a/kernel/process.c +++ b/kernel/process.c @@ -2067,7 +2067,8 @@ unsigned long extend_process_region(struct process_vm *vm, void *p; int rc; - new_end_allocated = (address + (8 * LARGE_PAGE_SIZE) - 1) & LARGE_PAGE_MASK; + new_end_allocated = (address + vm->proc->heap_extension + + (LARGE_PAGE_SIZE - 1)) & LARGE_PAGE_MASK; if (flag & VR_DEMAND_PAGING) { p = 0; @@ -2085,7 +2086,7 @@ unsigned long extend_process_region(struct process_vm *vm, if ((rc = add_process_memory_range(vm, end_allocated, new_end_allocated, (p == 0 ? 0 : virt_to_phys(p)), flag, NULL, 0, - LARGE_PAGE_SHIFT, NULL)) != 0) { + LARGE_PAGE_P2ALIGN, NULL)) != 0) { ihk_mc_free_pages(p, (new_end_allocated - end_allocated) >> PAGE_SHIFT); return end_allocated; } diff --git a/kernel/syscall.c b/kernel/syscall.c index 6182e1d9..fe6fe644 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -1802,6 +1802,7 @@ static void munmap_all(void) /* free vm_ranges which do_munmap() failed to remove. */ free_process_memory_ranges(thread->vm); + return; } /* munmap_all() */