提交 ebb3c4c4 编写于 作者: P Peter Zijlstra 提交者: Ingo Molnar

perf_counter: fix the mlock accounting

Reading through the code I saw I forgot the finish the mlock accounting.
Do so now.
Signed-off-by: NPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
LKML-Reference: <20090406094517.899767331@chello.nl>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
上级 f6c7d5fe
...@@ -1461,6 +1461,7 @@ static void perf_mmap_close(struct vm_area_struct *vma) ...@@ -1461,6 +1461,7 @@ static void perf_mmap_close(struct vm_area_struct *vma)
if (atomic_dec_and_mutex_lock(&counter->mmap_count, if (atomic_dec_and_mutex_lock(&counter->mmap_count,
&counter->mmap_mutex)) { &counter->mmap_mutex)) {
vma->vm_mm->locked_vm -= counter->data->nr_pages + 1;
perf_mmap_data_free(counter); perf_mmap_data_free(counter);
mutex_unlock(&counter->mmap_mutex); mutex_unlock(&counter->mmap_mutex);
} }
...@@ -1499,24 +1500,32 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -1499,24 +1500,32 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
if (vma->vm_pgoff != 0) if (vma->vm_pgoff != 0)
return -EINVAL; return -EINVAL;
locked = vma_size >> PAGE_SHIFT; mutex_lock(&counter->mmap_mutex);
locked += vma->vm_mm->locked_vm; if (atomic_inc_not_zero(&counter->mmap_count)) {
if (nr_pages != counter->data->nr_pages)
ret = -EINVAL;
goto unlock;
}
locked = vma->vm_mm->locked_vm;
locked += nr_pages + 1;
lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
lock_limit >>= PAGE_SHIFT; lock_limit >>= PAGE_SHIFT;
if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) {
return -EPERM; ret = -EPERM;
goto unlock;
mutex_lock(&counter->mmap_mutex); }
if (atomic_inc_not_zero(&counter->mmap_count))
goto out;
WARN_ON(counter->data); WARN_ON(counter->data);
ret = perf_mmap_data_alloc(counter, nr_pages); ret = perf_mmap_data_alloc(counter, nr_pages);
if (!ret) if (ret)
goto unlock;
atomic_set(&counter->mmap_count, 1); atomic_set(&counter->mmap_count, 1);
out: vma->vm_mm->locked_vm += nr_pages + 1;
unlock:
mutex_unlock(&counter->mmap_mutex); mutex_unlock(&counter->mmap_mutex);
vma->vm_flags &= ~VM_MAYWRITE; vma->vm_flags &= ~VM_MAYWRITE;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册