From c107d1fdf90523b599c4f7782ac619db1c8717ba Mon Sep 17 00:00:00 2001 From: Ken Sato Date: Thu, 15 Mar 2018 14:29:16 +0900 Subject: [PATCH] fix: Bug for measuring rss in fork() refs: #1032 --- kernel/include/cls.h | 2 ++ kernel/include/rusage_private.h | 7 ++++++- kernel/process.c | 6 ++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/kernel/include/cls.h b/kernel/include/cls.h index 02de2bc7..d778407c 100644 --- a/kernel/include/cls.h +++ b/kernel/include/cls.h @@ -97,6 +97,8 @@ struct cpu_local_var { ihk_spinlock_t smp_func_req_lock; struct list_head smp_func_req_list; + + struct process_vm *on_fork_vm; } __attribute__((aligned(64))); diff --git a/kernel/include/rusage_private.h b/kernel/include/rusage_private.h index dcc8f342..72401691 100644 --- a/kernel/include/rusage_private.h +++ b/kernel/include/rusage_private.h @@ -35,7 +35,7 @@ rusage_rss_add(unsigned long size) unsigned long newval; unsigned long oldval; unsigned long retval; - struct process_vm *vm = cpu_local_var(current)->vm; + struct process_vm *vm; newval = __sync_add_and_fetch(&rusage->rss_current, size); oldval = rusage->memory_max_usage; @@ -49,6 +49,11 @@ rusage_rss_add(unsigned long size) } /* process rss */ + vm = cpu_local_var(on_fork_vm); + if (!vm) { + vm = cpu_local_var(current)->vm; + } + vm->currss += size; if (vm->currss > vm->proc->maxrss) { vm->proc->maxrss = vm->currss; diff --git a/kernel/process.c b/kernel/process.c index 5b817f3d..f574aa1c 100644 --- a/kernel/process.c +++ b/kernel/process.c @@ -398,6 +398,7 @@ clone_thread(struct thread *org, unsigned long pc, unsigned long sp, int termsig = clone_flags & 0xff; struct process *proc = NULL; struct address_space *asp = NULL; + struct cpu_local_var *v = get_this_cpu_local_var(); if ((thread = ihk_mc_alloc_pages(KERNEL_STACK_NR_PAGES, IHK_MC_AP_NOWAIT)) == NULL) { @@ -484,12 +485,15 @@ clone_thread(struct thread *org, unsigned long pc, unsigned long sp, dkprintf("fork(): copy_user_ranges()\n"); /* Copy user-space mappings. * TODO: do this with COW later? */ + v->on_fork_vm = proc->vm; if (copy_user_ranges(proc->vm, org->vm) != 0) { release_address_space(asp); + v->on_fork_vm = NULL; kfree(proc->vm); kfree(proc); goto err_free_proc; } + v->on_fork_vm = NULL; /* Copy mckfd list FIXME: Replace list manipulation with list_add() etc. */ @@ -522,8 +526,6 @@ clone_thread(struct thread *org, unsigned long pc, unsigned long sp, thread->vm->vdso_addr = org->vm->vdso_addr; thread->vm->vvar_addr = org->vm->vvar_addr; - thread->proc->maxrss = org->proc->maxrss; - thread->vm->currss = org->vm->currss; thread->sigstack.ss_sp = org->sigstack.ss_sp; thread->sigstack.ss_flags = org->sigstack.ss_flags;