fix: Bug for measuring rss in fork()

refs: #1032
This commit is contained in:
Ken Sato
2018-03-15 14:29:16 +09:00
parent bc89a51e00
commit c107d1fdf9
3 changed files with 12 additions and 3 deletions

View File

@ -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)));

View File

@ -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;

View File

@ -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;