diff options
author | Song Liu <songliubraving@fb.com> | 2019-09-04 17:46:18 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2019-10-09 06:44:12 -0400 |
commit | d44248a41337731a111374822d7d4451b64e73e4 (patch) | |
tree | 00a83d5f6e5c1723c1d7a79b96ea27fdfabf6fea /kernel | |
parent | f733c6b508bcaa3441ba1eacf16efb9abd47489f (diff) |
perf/core: Rework memory accounting in perf_mmap()
perf_mmap() always increases user->locked_vm. As a result, "extra" could
grow bigger than "user_extra", which doesn't make sense. Here is an
example case:
(Note: Assume "user_lock_limit" is very small.)
| # of perf_mmap calls |vma->vm_mm->pinned_vm|user->locked_vm|
| 0 | 0 | 0 |
| 1 | user_extra | user_extra |
| 2 | 3 * user_extra | 2 * user_extra|
| 3 | 6 * user_extra | 3 * user_extra|
| 4 | 10 * user_extra | 4 * user_extra|
Fix this by maintaining proper user_extra and extra.
Reviewed-By: Hechao Li <hechaol@fb.com>
Reported-by: Hechao Li <hechaol@fb.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: <kernel-team@fb.com>
Cc: Jie Meng <jmeng@fb.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190904214618.3795672-1-songliubraving@fb.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/events/core.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c index f953dd16a5e2..2b8265ad7bf5 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -5668,7 +5668,8 @@ again: | |||
5668 | * undo the VM accounting. | 5668 | * undo the VM accounting. |
5669 | */ | 5669 | */ |
5670 | 5670 | ||
5671 | atomic_long_sub((size >> PAGE_SHIFT) + 1, &mmap_user->locked_vm); | 5671 | atomic_long_sub((size >> PAGE_SHIFT) + 1 - mmap_locked, |
5672 | &mmap_user->locked_vm); | ||
5672 | atomic64_sub(mmap_locked, &vma->vm_mm->pinned_vm); | 5673 | atomic64_sub(mmap_locked, &vma->vm_mm->pinned_vm); |
5673 | free_uid(mmap_user); | 5674 | free_uid(mmap_user); |
5674 | 5675 | ||
@@ -5812,8 +5813,20 @@ accounting: | |||
5812 | 5813 | ||
5813 | user_locked = atomic_long_read(&user->locked_vm) + user_extra; | 5814 | user_locked = atomic_long_read(&user->locked_vm) + user_extra; |
5814 | 5815 | ||
5815 | if (user_locked > user_lock_limit) | 5816 | if (user_locked <= user_lock_limit) { |
5817 | /* charge all to locked_vm */ | ||
5818 | } else if (atomic_long_read(&user->locked_vm) >= user_lock_limit) { | ||
5819 | /* charge all to pinned_vm */ | ||
5820 | extra = user_extra; | ||
5821 | user_extra = 0; | ||
5822 | } else { | ||
5823 | /* | ||
5824 | * charge locked_vm until it hits user_lock_limit; | ||
5825 | * charge the rest from pinned_vm | ||
5826 | */ | ||
5816 | extra = user_locked - user_lock_limit; | 5827 | extra = user_locked - user_lock_limit; |
5828 | user_extra -= extra; | ||
5829 | } | ||
5817 | 5830 | ||
5818 | lock_limit = rlimit(RLIMIT_MEMLOCK); | 5831 | lock_limit = rlimit(RLIMIT_MEMLOCK); |
5819 | lock_limit >>= PAGE_SHIFT; | 5832 | lock_limit >>= PAGE_SHIFT; |