Commit 1ea3e3b0 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Peter Zijlstra
Browse files

perf: Split out VM accounting



Similarly to the mlock limit calculation the VM accounting is required for
both the ringbuffer and the AUX buffer allocations.

To prepare for splitting them out into separate functions, move the
accounting into a helper function.

Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarLorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/r/20250812104018.660347811@infradead.org
parent 81e026ca
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -6962,10 +6962,17 @@ static bool perf_mmap_calc_limits(struct vm_area_struct *vma, long *user_extra,
	return locked <= lock_limit || !perf_is_paranoid() || capable(CAP_IPC_LOCK);
}

static void perf_mmap_account(struct vm_area_struct *vma, long user_extra, long extra)
{
	struct user_struct *user = current_user();

	atomic_long_add(user_extra, &user->locked_vm);
	atomic64_add(extra, &vma->vm_mm->pinned_vm);
}

static int perf_mmap(struct file *file, struct vm_area_struct *vma)
{
	struct perf_event *event = file->private_data;
	struct user_struct *user = current_user();
	unsigned long vma_size, nr_pages;
	long user_extra = 0, extra = 0;
	struct mutex *aux_mutex = NULL;
@@ -7136,9 +7143,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)

unlock:
	if (!ret) {
		atomic_long_add(user_extra, &user->locked_vm);
		atomic64_add(extra, &vma->vm_mm->pinned_vm);

		perf_mmap_account(vma, user_extra, extra);
		atomic_inc(&event->mmap_count);
	} else if (rb) {
		/* AUX allocation failed */